Class: Lutaml::Xsd::Spa::Svg::Geometry::Point
- Inherits:
-
Object
- Object
- Lutaml::Xsd::Spa::Svg::Geometry::Point
- Defined in:
- lib/lutaml/xsd/spa/svg/geometry/point.rb
Overview
Immutable value object representing a 2D point
Instance Attribute Summary collapse
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #distance_to(other) ⇒ Object
-
#initialize(x, y) ⇒ Point
constructor
A new instance of Point.
- #midpoint_to(other) ⇒ Object
- #offset(dx, dy) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(x, y) ⇒ Point
Returns a new instance of Point.
12 13 14 15 |
# File 'lib/lutaml/xsd/spa/svg/geometry/point.rb', line 12 def initialize(x, y) @x = x.to_f @y = y.to_f end |
Instance Attribute Details
#x ⇒ Object (readonly)
Returns the value of attribute x.
10 11 12 |
# File 'lib/lutaml/xsd/spa/svg/geometry/point.rb', line 10 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
10 11 12 |
# File 'lib/lutaml/xsd/spa/svg/geometry/point.rb', line 10 def y @y end |
Instance Method Details
#==(other) ⇒ Object
17 18 19 |
# File 'lib/lutaml/xsd/spa/svg/geometry/point.rb', line 17 def ==(other) other.is_a?(Point) && x == other.x && y == other.y end |
#distance_to(other) ⇒ Object
25 26 27 |
# File 'lib/lutaml/xsd/spa/svg/geometry/point.rb', line 25 def distance_to(other) Math.sqrt(((x - other.x)**2) + ((y - other.y)**2)) end |
#midpoint_to(other) ⇒ Object
29 30 31 |
# File 'lib/lutaml/xsd/spa/svg/geometry/point.rb', line 29 def midpoint_to(other) Point.new((x + other.x) / 2.0, (y + other.y) / 2.0) end |
#offset(dx, dy) ⇒ Object
33 34 35 |
# File 'lib/lutaml/xsd/spa/svg/geometry/point.rb', line 33 def offset(dx, dy) Point.new(x + dx, y + dy) end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/lutaml/xsd/spa/svg/geometry/point.rb', line 21 def to_s "(#{x}, #{y})" end |