Class: Ea::Svg::BoundsCalculator
- Inherits:
-
Object
- Object
- Ea::Svg::BoundsCalculator
- Defined in:
- lib/ea/svg/bounds_calculator.rb
Overview
Computes the actual drawing-area bounding box of an Ea::Model::Diagram. EA stores bounds in pixel space with two quirks: element rects can be inverted (rectbottom < recttop, producing negative height), and elements/connectors can sit outside the canvas bounds. The drawing area is the union of all element rects and connector waypoint positions.
Defined Under Namespace
Classes: Bounds
Instance Attribute Summary collapse
-
#diagram ⇒ Object
readonly
Returns the value of attribute diagram.
Instance Method Summary collapse
- #compute ⇒ Object
-
#initialize(diagram) ⇒ BoundsCalculator
constructor
A new instance of BoundsCalculator.
Constructor Details
#initialize(diagram) ⇒ BoundsCalculator
Returns a new instance of BoundsCalculator.
14 15 16 |
# File 'lib/ea/svg/bounds_calculator.rb', line 14 def initialize(diagram) @diagram = diagram end |
Instance Attribute Details
#diagram ⇒ Object (readonly)
Returns the value of attribute diagram.
12 13 14 |
# File 'lib/ea/svg/bounds_calculator.rb', line 12 def diagram @diagram end |
Instance Method Details
#compute ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/ea/svg/bounds_calculator.rb', line 18 def compute points = all_points return fallback_bounds if points.empty? xs = points.map(&:first) ys = points.map(&:last) Bounds.new(x: xs.min, y: ys.min, width: xs.max - xs.min, height: ys.max - ys.min) end |