Class: Sevgi::Geometry::Line

Inherits:
LineBase
  • Object
show all
Defined in:
lib/sevgi/geometry/elements/line.rb,
lib/sevgi/geometry/equation.rb

Overview

Open lined element with one segment.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](length, angle, position: Origin) ⇒ Sevgi::Geometry::Line

Builds a line from length and angle.

Parameters:

  • length (Numeric)

    line length

  • angle (Numeric)

    clockwise angle in degrees

  • position (Sevgi::Geometry::Point, Array<Numeric>) (defaults to: Origin)

    starting point

Returns:

Raises:



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.

Parameters:

  • length (Numeric)

    line length

  • angle (Numeric)

    clockwise angle in degrees

  • position (Sevgi::Geometry::Point, Array<Numeric>) (defaults to: Origin)

    starting point

Returns:

Raises:



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

Builds a line from two endpoints.

Parameters:

Returns:

Raises:



35
# File 'lib/sevgi/geometry/elements/line.rb', line 35

def self.from_points(...) = new_by_points(...)

Instance Method Details

#angleFloat

Returns the clockwise line angle in degrees.

Returns:

  • (Float)


39
# File 'lib/sevgi/geometry/elements/line.rb', line 39

def angle = head.angle

#draw!(node) ⇒ Object

Draws the line into a graphics node.

Parameters:

  • node (Object)

    graphics node receiving the drawing command

Returns:

  • (Object)

    graphics node command result



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, **)

#endingSevgi::Geometry::Point

Returns the ending point.



43
# File 'lib/sevgi/geometry/elements/line.rb', line 43

def ending = points.last

#equationSevgi::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.

Parameters:

Returns:

  • (Boolean)

Raises:



49
# File 'lib/sevgi/geometry/elements/line.rb', line 49

def left?(point) = equation.left?(point)

#lengthFloat

Returns the line segment length.

Returns:

  • (Float)


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.

Parameters:

Returns:

  • (Boolean)

Raises:



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.

Parameters:

Returns:

  • (Boolean)

Raises:



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.

Parameters:

  • distance (Numeric)

    signed perpendicular offset

Returns:



83
# File 'lib/sevgi/geometry/elements/line.rb', line 83

def shift(distance) = translate(distance * F.sin(angle), -distance * F.cos(angle))

#startingSevgi::Geometry::Point

Returns the starting point.



63
# File 'lib/sevgi/geometry/elements/line.rb', line 63

def starting = points.first