Class: KvgCharacterRecognition::KvgParser::Point

Inherits:
Object
  • Object
show all
Defined in:
lib/kvg_character_recognition/kvg_parser.rb

Overview

A Point

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, color = :black) ⇒ Point

Returns a new instance of Point.



10
11
12
# File 'lib/kvg_character_recognition/kvg_parser.rb', line 10

def initialize(x,y, color = :black)
  @x,@y, @color = x, y, color
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



8
9
10
# File 'lib/kvg_character_recognition/kvg_parser.rb', line 8

def color
  @color
end

#xObject

Returns the value of attribute x.



8
9
10
# File 'lib/kvg_character_recognition/kvg_parser.rb', line 8

def x
  @x
end

#yObject

Returns the value of attribute y.



8
9
10
# File 'lib/kvg_character_recognition/kvg_parser.rb', line 8

def y
  @y
end

Instance Method Details

#*(number) ⇒ Object



27
28
29
# File 'lib/kvg_character_recognition/kvg_parser.rb', line 27

def *(number)
  return Point.new(@x * number, @y * number)
end

#+(p2) ⇒ Object

Basic point arithmetics



15
16
17
# File 'lib/kvg_character_recognition/kvg_parser.rb', line 15

def +(p2)
  return Point.new(@x + p2.x, @y + p2.y)
end

#-(p2) ⇒ Object



19
20
21
# File 'lib/kvg_character_recognition/kvg_parser.rb', line 19

def -(p2)
  return Point.new(@x - p2.x, @y - p2.y)
end

#dist(p2) ⇒ Object



23
24
25
# File 'lib/kvg_character_recognition/kvg_parser.rb', line 23

def dist(p2)
  return Math.sqrt((p2.x - @x)**2 + (p2.y - @y)**2)
end

#to_aObject

to array



32
33
34
# File 'lib/kvg_character_recognition/kvg_parser.rb', line 32

def to_a
  [@x.round(2), @y.round(2)]
end