Class: Sevgi::Geometry::Line
- Inherits:
-
LineBase
- Object
- Sevgi::Geometry::Line
- Defined in:
- lib/sevgi/geometry/elements/line.rb,
lib/sevgi/geometry/equation.rb
Overview
Open lined element with one segment.
Class Method Summary collapse
-
.[](length, angle, position: Origin) ⇒ Sevgi::Geometry::Line
Builds a line from length and angle.
-
.from_length_angle(length, angle, position: Origin) ⇒ Sevgi::Geometry::Line
Builds a line from length and angle.
-
.from_points(starting, ending) ⇒ Sevgi::Geometry::Line
Builds a line from two endpoints.
Instance Method Summary collapse
-
#angle ⇒ Float
Returns the clockwise line angle in degrees.
-
#draw!(node) ⇒ Object
Draws the line into a graphics node.
-
#ending ⇒ Sevgi::Geometry::Point
Returns the ending point.
-
#equation ⇒ Sevgi::Geometry::Equation::Linear
Returns the linear equation containing this line.
-
#left?(point) ⇒ Boolean
Reports whether a point is left of the line equation.
-
#length ⇒ Float
Returns the line segment length.
-
#over?(point) ⇒ Boolean
Reports whether a point lies on the finite line segment.
-
#right?(point) ⇒ Boolean
Reports whether a point is right of the line equation.
-
#shift(distance) ⇒ Sevgi::Geometry::Line
Returns a parallel line shifted by a signed perpendicular offset.
-
#starting ⇒ Sevgi::Geometry::Point
Returns the starting point.
Class Method Details
.[](length, angle, position: Origin) ⇒ Sevgi::Geometry::Line
19 |
# File 'lib/sevgi/geometry/elements/line.rb', line 19 def self.[](...) = from_length_angle(...) |
.from_length_angle(length, angle, position: Origin) ⇒ Sevgi::Geometry::Line
Builds a line from length and angle.
27 |
# File 'lib/sevgi/geometry/elements/line.rb', line 27 def self.from_length_angle(length, angle, position: Origin) = new_by_segments(Segment[length, angle], position:) |
.from_points(starting, ending) ⇒ Sevgi::Geometry::Line
35 |
# File 'lib/sevgi/geometry/elements/line.rb', line 35 def self.from_points(...) = new_by_points(...) |
Instance Method Details
#angle ⇒ Float
Returns the clockwise line angle in degrees.
39 |
# File 'lib/sevgi/geometry/elements/line.rb', line 39 def angle = head.angle |
#draw!(node) ⇒ Object
Draws the line into a graphics node.
68 |
# File 'lib/sevgi/geometry/elements/line.rb', line 68 def draw!(node, **) = node.LineTo(x1: position.x, y1: position.y, x2: ending.x, y2: ending.y, **) |
#ending ⇒ Sevgi::Geometry::Point
Returns the ending point.
43 |
# File 'lib/sevgi/geometry/elements/line.rb', line 43 def ending = points.last |
#equation ⇒ Sevgi::Geometry::Equation::Linear
Returns the linear equation containing this line.
108 |
# File 'lib/sevgi/geometry/equation.rb', line 108 def equation = position.equation(angle) |
#left?(point) ⇒ Boolean
Reports whether a point is left of the line equation.
49 |
# File 'lib/sevgi/geometry/elements/line.rb', line 49 def left?(point) = equation.left?(point) |
#length ⇒ Float
Returns the line segment length.
53 |
# File 'lib/sevgi/geometry/elements/line.rb', line 53 def length = head.length |
#over?(point) ⇒ Boolean
Reports whether a point lies on the finite line segment.
74 75 76 77 78 |
# File 'lib/sevgi/geometry/elements/line.rb', line 74 def over?(point) point = Tuple[Point, point] within_range?(point) && equation.on?(point) end |
#right?(point) ⇒ Boolean
Reports whether a point is right of the line equation.
59 |
# File 'lib/sevgi/geometry/elements/line.rb', line 59 def right?(point) = equation.right?(point) |
#shift(distance) ⇒ Sevgi::Geometry::Line
Returns a parallel line shifted by a signed perpendicular offset.
83 |
# File 'lib/sevgi/geometry/elements/line.rb', line 83 def shift(distance) = translate(distance * F.sin(angle), -distance * F.cos(angle)) |
#starting ⇒ Sevgi::Geometry::Point
Returns the starting point.
63 |
# File 'lib/sevgi/geometry/elements/line.rb', line 63 def starting = points.first |