Class: Sevgi::Geometry::Element

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

Overview

Abstract base class for positioned geometry values.

Construct concrete shapes through their class factories. Element operations return new values, and #box supplies the axis-aligned bounds used by alignment and tiling helpers.

Direct Known Subclasses

Lined

Defined Under Namespace

Classes: Lined

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

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

Examples:

Define a custom two-segment open shape

Path = Sevgi::Geometry::Element.lined(2, open: true)
Path.([0, 0], [1, 0], [1, 1])

Builds a lined element subclass. Instances expose total path length; closed classes additionally expose perimeter.

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

Raises:



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

def self.lined(...) = Lined.send(:build, ...)

Instance Method Details

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

Returns a copy moved to a point and optional offset.

Examples:

Position a copy without mutating the source

source = Sevgi::Geometry::Rect[8, 4, position: [1, 2]]
moved = source.at([10, 20], dx: 2)
source.position.deconstruct # => [1.0, 2.0]
moved.position.deconstruct  # => [12.0, 20.0]

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:



48
49
50
51
52
53
54
55
56
57
# File 'lib/sevgi/geometry/element.rb', line 48

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

  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



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

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



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

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)


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

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



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

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



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

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