Module: Dieses::Geometry
- Defined in:
- lib/dieses/geometry/line.rb,
lib/dieses/geometry/rect.rb,
lib/dieses/geometry/error.rb,
lib/dieses/geometry/point.rb,
lib/dieses/geometry/element.rb,
lib/dieses/geometry/equation.rb,
lib/dieses/geometry/equation/slant.rb,
lib/dieses/geometry/equation/steep.rb
Defined Under Namespace
Modules: Equation
Classes: Element, Line, Point, Rect
Constant Summary
collapse
- Error =
Class.new Error
Class Method Summary
collapse
Class Method Details
.bounding_box_of(*elements) ⇒ Object
56
57
58
59
60
61
62
63
|
# File 'lib/dieses/geometry/element.rb', line 56
def bounding_box_of(*elements)
bboxes = elements.map(&:bbox)
minimum = bboxes.map(&:minimum).min
maximum = bboxes.map(&:maximum).max
Element::BoundingBox.new minimum, maximum
end
|
.centered(elements, rect) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/dieses/geometry/element.rb', line 41
def centered(elements, rect)
bbox = bounding_box_of(*elements)
x = (rect.width - bbox.maximum.x + bbox.minimum.x) / 2
y = (rect.height - bbox.maximum.y + bbox.minimum.y) / 2
elements.map { |element| element.translate(x: x, y: y).attr(**element.attributes.dup) }
end
|
.to_svg(elements, rect = Undefined, prefix: EMPTY_STRING) ⇒ Object
50
51
52
53
54
|
# File 'lib/dieses/geometry/element.rb', line 50
def to_svg(elements, rect = Undefined, prefix: EMPTY_STRING)
(Undefined.equal?(rect) ? elements : centered(elements, rect)).map do |element|
"#{prefix}#{element.to_svg}"
end.join.chomp
end
|