Class: Lutaml::Xsd::Spa::Svg::Geometry::Point

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/xsd/spa/svg/geometry/point.rb

Overview

Immutable value object representing a 2D point

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#xObject (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

#yObject (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_sObject



21
22
23
# File 'lib/lutaml/xsd/spa/svg/geometry/point.rb', line 21

def to_s
  "(#{x}, #{y})"
end