Class: Sumi::Geometry::Element
- Inherits:
-
Object
- Object
- Sumi::Geometry::Element
- Defined in:
- geometry/lib/sumi/geometry/element.rb,
geometry/lib/sumi/geometry/element/arced.rb,
geometry/lib/sumi/geometry/element/lined.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.
Defined Under Namespace
Class Method Summary collapse
-
.lined(size = Undefined, open: false) ⇒ Class
Builds a lined element subclass.
Instance Method Summary collapse
-
#at(point = nil, dx: 0, dy: 0) ⇒ Sumi::Geometry::Element
Returns a copy moved to a point and optional offset.
-
#box ⇒ Sumi::Geometry::Rect
abstract
Returns the bounding rectangle.
-
#closed? ⇒ Boolean
Reports whether the element boundary forms a closed path.
-
#equations ⇒ Array<Sumi::Geometry::Equation>
abstract
Returns carrier equations for candidate boundary intersections.
-
#ignorable?(precision: nil) ⇒ Boolean
Reports whether the element has zero bounding width and height.
-
#intersection(equation, precision: nil) ⇒ Array<Sumi::Geometry::Point>
Intersects the element boundary with an equation.
-
#position ⇒ Sumi::Geometry::Point
abstract
Returns the element position.
-
#translate(_x, _y) ⇒ Sumi::Geometry::Element
abstract
Returns a translated copy.
Class Method Details
.lined(size = Undefined, open: false) ⇒ Class
23 |
# File 'geometry/lib/sumi/geometry/element.rb', line 23 def self.lined(...) = Lined.send(:build, ...) |
Instance Method Details
#at(point = nil, dx: 0, dy: 0) ⇒ Sumi::Geometry::Element
Returns a copy moved to a point and optional offset.
38 39 40 41 42 43 44 45 46 47 |
# File 'geometry/lib/sumi/geometry/element.rb', line 38 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 |
#box ⇒ Sumi::Geometry::Rect
Subclasses implement element-specific bounds.
Returns the bounding rectangle.
53 |
# File 'geometry/lib/sumi/geometry/element.rb', line 53 def box = PanicError.("#{self.class}#box must be implemented") |
#closed? ⇒ Boolean
Reports whether the element boundary forms a closed path.
57 |
# File 'geometry/lib/sumi/geometry/element.rb', line 57 def closed? = self.class.send(:close?) |
#equations ⇒ Array<Sumi::Geometry::Equation>
Subclasses implement element-specific equations.
Returns carrier equations for candidate boundary intersections. A finite element can represent only part of each carrier.
64 |
# File 'geometry/lib/sumi/geometry/element.rb', line 64 def equations = PanicError.("#{self.class}#equations must be implemented") |
#ignorable?(precision: nil) ⇒ Boolean
Reports whether the element has zero bounding width and height.
69 |
# File 'geometry/lib/sumi/geometry/element.rb', line 69 def ignorable?(precision: nil) = box.then { F.zero?(it.width, precision:) && F.zero?(it.height, precision:) } |
#intersection(equation, precision: nil) ⇒ Array<Sumi::Geometry::Point>
Intersects the element boundary with an equation.
Precision controls boundary membership, returned-coordinate rounding, and duplicate collapse. A nil precision uses the current thread's function precision for all three stages.
84 85 86 87 88 89 90 91 92 |
# File 'geometry/lib/sumi/geometry/element.rb', line 84 def intersection(equation, precision: nil) Error.("Must be an equation: #{equation}") unless equation.is_a?(Equation) points = equations.flat_map do |candidate| equation.intersect(candidate).select { |point| boundary_point?(point, precision) } end points.map { |point| point.approx(precision) }.uniq end |
#position ⇒ Sumi::Geometry::Point
Subclasses implement element-specific positioning.
Returns the element position.
98 |
# File 'geometry/lib/sumi/geometry/element.rb', line 98 def position = PanicError.("#{self.class}#position must be implemented") |
#translate(_x, _y) ⇒ Sumi::Geometry::Element
Subclasses implement element-specific translation.
Returns a translated copy.
106 |
# File 'geometry/lib/sumi/geometry/element.rb', line 106 def translate(_x, _y) = PanicError.("#{self.class}#translate must be implemented") |