Class: Draught::Point
- Inherits:
-
Object
- Object
- Draught::Point
- Includes:
- Pointlike
- Defined in:
- lib/draught/point.rb
Constant Summary collapse
- ZERO =
new(0, 0)
Instance Attribute Summary collapse
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #approximates?(other, delta) ⇒ Boolean
-
#initialize(x, y) ⇒ Point
constructor
A new instance of Point.
- #point_type ⇒ Object
- #to_matrix ⇒ Object
- #transform(transformation) ⇒ Object
- #translate(vector) ⇒ Object
- #translation_to(point) ⇒ Object
Methods included from Pointlike
Constructor Details
#initialize(x, y) ⇒ Point
Returns a new instance of Point.
16 17 18 |
# File 'lib/draught/point.rb', line 16 def initialize(x, y) @x, @y = x, y end |
Instance Attribute Details
#x ⇒ Object (readonly)
Returns the value of attribute x.
14 15 16 |
# File 'lib/draught/point.rb', line 14 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
14 15 16 |
# File 'lib/draught/point.rb', line 14 def y @y end |
Class Method Details
Instance Method Details
#==(other) ⇒ Object
24 25 26 27 |
# File 'lib/draught/point.rb', line 24 def ==(other) other.point_type == point_type && other.x == x && other.y == y end |
#approximates?(other, delta) ⇒ Boolean
29 30 31 32 33 |
# File 'lib/draught/point.rb', line 29 def approximates?(other, delta) other.point_type == point_type && ((other.x - x).abs <= delta) && ((other.y - y).abs <= delta) end |
#point_type ⇒ Object
20 21 22 |
# File 'lib/draught/point.rb', line 20 def point_type :point end |
#to_matrix ⇒ Object
43 44 45 |
# File 'lib/draught/point.rb', line 43 def to_matrix @matrix ||= Matrix[[x],[y],[1]].freeze end |
#transform(transformation) ⇒ Object
47 48 49 |
# File 'lib/draught/point.rb', line 47 def transform(transformation) transformation.call(self) end |
#translate(vector) ⇒ Object
35 36 37 |
# File 'lib/draught/point.rb', line 35 def translate(vector) transform(vector.to_transform) end |
#translation_to(point) ⇒ Object
39 40 41 |
# File 'lib/draught/point.rb', line 39 def translation_to(point) Vector.translation_between(self, point) end |