class Coords::Shapes::Line2d

Public Class Methods

new(x1, y1, x2, y2) click to toggle source
# File lib/coords/shapes/line2d.rb, line 5
def initialize(x1, y1, x2, y2)
  @point1 = Coords::Cartesian2d.new(x1, y1)
  @point2 = Coords::Cartesian2d.new(x2, y2)
end

Public Instance Methods

==(line) click to toggle source
# File lib/coords/shapes/line2d.rb, line 34
def ==(line)
  ((point1 == line.point1 && point2 == line.point2) || (point1 == line.point2 && point2 == line.point1))
end
ends() click to toggle source
# File lib/coords/shapes/line2d.rb, line 18
def ends
  [point1, point2]
end
length() click to toggle source
# File lib/coords/shapes/line2d.rb, line 26
def length
  Math.sqrt(length_squared)
end
length_squared() click to toggle source
# File lib/coords/shapes/line2d.rb, line 22
def length_squared
  point1.distance_squared(point2)
end
point1() click to toggle source
# File lib/coords/shapes/line2d.rb, line 10
def point1
  @point1
end
point2() click to toggle source
# File lib/coords/shapes/line2d.rb, line 14
def point2
  @point2
end
to_s() click to toggle source
# File lib/coords/shapes/line2d.rb, line 30
def to_s
  "(#{point1.x.to_s},#{point1.y.to_s}),(#{point2.x.to_s},#{point2.y.to_s})"
end
translate(x2, y2) click to toggle source
# File lib/coords/shapes/line2d.rb, line 38
def translate(x2, y2)
  translated_line = Line2d.new(point1.x, point1.y, point2.x, point2.y)
  translated_line.translate!(x2, y2)
  translated_line
end
translate!(x2, y2) click to toggle source
# File lib/coords/shapes/line2d.rb, line 44
def translate!(x2, y2)
  point1.translate!(x2, y2)
  point2.translate!(x2, y2)
end