Class: Sevgi::Geometry::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/sevgi/geometry/element.rb

Overview

Base class for geometric elements.

Direct Known Subclasses

Arced, Lined

Defined Under Namespace

Classes: Arced, Lined

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.arced(*args) ⇒ Class

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Builds an arced element subclass.

Parameters:

  • args (Array<Object>)

    arced factory arguments

Returns:

  • (Class)

Raises:

  • (NoMethodError)

    until arced elements are implemented



20
# File 'lib/sevgi/geometry/element.rb', line 20

def self.arced(...) = Arced.build(...)

.lined(size = Undefined, open: false) ⇒ Class

Builds a lined element subclass.

Parameters:

  • size (Integer, Sevgi::Undefined) (defaults to: Undefined)

    segment count for fixed-size elements, or Undefined for variable size

  • open (Boolean) (defaults to: false)

    true for an open path, false for a closed path

Returns:

  • (Class)

    subclass of Lined



12
# File 'lib/sevgi/geometry/element.rb', line 12

def self.lined(...) = Lined.build(...)

Instance Method Details

#at(point = nil, dx: 0, dy: 0) ⇒ Sevgi::Geometry::Element

Returns a copy moved to a point and optional offset.

Parameters:

  • point (Sevgi::Geometry::Point, Array<Numeric>, nil) (defaults to: nil)

    target position, or nil to keep current position

  • dx (Numeric) (defaults to: 0)

    additional x offset

  • dy (Numeric) (defaults to: 0)

    additional y offset

Returns:

Raises:



30
31
32
33
34
35
36
37
# File 'lib/sevgi/geometry/element.rb', line 30

def at(point = nil, dx: 0, dy: 0)
  point = point ? Tuple[Point, point] : position

  translate(
    (point.x - position.x) + dx,
    (point.y - position.y) + dy
  )
end

#boxSevgi::Geometry::Rect

This method is abstract.

Subclasses implement element-specific bounds.

Returns the bounding rectangle.

Returns:

Raises:

  • (Sevgi::PanicError)

    when a subclass does not implement box



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

def box = PanicError.("#{self.class}#box must be implemented")

#equationsArray<Sevgi::Geometry::Equation>

This method is abstract.

Subclasses implement element-specific equations.

Returns equations that define the element boundary.

Returns:

Raises:

  • (Sevgi::PanicError)

    when a subclass does not implement equations



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

def equations = PanicError.("#{self.class}#equations must be implemented")

#ignorable?(precision: nil) ⇒ Boolean

Reports whether the element has zero bounding width and height.

Parameters:

  • precision (Integer, nil) (defaults to: nil)

    decimal precision, or nil for the current function default

Returns:

  • (Boolean)


54
# File 'lib/sevgi/geometry/element.rb', line 54

def ignorable?(precision: nil) = F.zero?(box.width, precision:) && F.zero?(box.height, precision:)

#positionSevgi::Geometry::Point

This method is abstract.

Subclasses implement element-specific positioning.

Returns the element position.

Returns:

Raises:

  • (Sevgi::PanicError)

    when a subclass does not implement position



60
# File 'lib/sevgi/geometry/element.rb', line 60

def position = PanicError.("#{self.class}#position must be implemented")

#translate(_x, _y) ⇒ Sevgi::Geometry::Element

This method is abstract.

Subclasses implement element-specific translation.

Returns a translated copy.

Parameters:

  • _x (Numeric)

    x offset

  • _y (Numeric)

    y offset

Returns:

Raises:

  • (Sevgi::PanicError)

    when a subclass does not implement translate



68
# File 'lib/sevgi/geometry/element.rb', line 68

def translate(_x, _y) = PanicError.("#{self.class}#translate must be implemented")