Class: Triangular::Line
- Inherits:
-
Object
- Object
- Triangular::Line
- Defined in:
- lib/triangular/line.rb
Instance Attribute Summary collapse
-
#end ⇒ Object
Returns the value of attribute end.
-
#start ⇒ Object
Returns the value of attribute start.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(line_start, line_end) ⇒ Line
constructor
A new instance of Line.
- #intersection_at_z(z_plane) ⇒ Object
- #intersects_z?(z_plane) ⇒ Boolean
- #to_svg_path(units) ⇒ Object
Constructor Details
#initialize(line_start, line_end) ⇒ Line
Returns a new instance of Line.
6 7 8 9 |
# File 'lib/triangular/line.rb', line 6 def initialize(line_start, line_end) @start = line_start @end = line_end end |
Instance Attribute Details
#end ⇒ Object
Returns the value of attribute end.
4 5 6 |
# File 'lib/triangular/line.rb', line 4 def end @end end |
#start ⇒ Object
Returns the value of attribute start.
4 5 6 |
# File 'lib/triangular/line.rb', line 4 def start @start end |
Instance Method Details
#==(other) ⇒ Object
11 12 13 14 |
# File 'lib/triangular/line.rb', line 11 def ==(other) return false unless other.is_a?(Line) self.start == other.start && self.end == other.end end |
#intersection_at_z(z_plane) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/triangular/line.rb', line 24 def intersection_at_z(z_plane) return nil if !self.intersects_z?(z_plane) raise "Cannot calculate intersection for line that lies on the target Z plane" if @start.z == z_plane && @end.z == z_plane x_intersect = (@end.x - @start.x) / (@end.z - @start.z) * (z_plane - @start.z) + @start.x y_intersect = (@end.y - @start.y) / (@end.z - @start.z) * (z_plane - @start.z) + @start.y Point.new(x_intersect, y_intersect, z_plane) end |
#intersects_z?(z_plane) ⇒ Boolean
16 17 18 19 20 21 22 |
# File 'lib/triangular/line.rb', line 16 def intersects_z?(z_plane) if (@start.z >= z_plane && @end.z <= z_plane) || (@start.z <= z_plane && @end.z >= z_plane) true else false end end |
#to_svg_path(units) ⇒ Object
34 35 36 |
# File 'lib/triangular/line.rb', line 34 def to_svg_path(units) "<path d=\"M #{@start.x} #{@start.y} L #{@end.x} #{@end.y}\" fill=\"none\" stroke=\"black\" stroke-width=\"#{Units.stroke_width(units)}\" />" end |