Class: BoxPacker::SVGExporter::Face
- Inherits:
-
Object
- Object
- BoxPacker::SVGExporter::Face
- Defined in:
- lib/box_packer/svg_exporter.rb
Instance Attribute Summary collapse
-
#axes ⇒ Object
readonly
Returns the value of attribute axes.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(packing) ⇒ Face
constructor
A new instance of Face.
- #iterate_class_variables ⇒ Object
- #outline ⇒ Object
- #rectangles_and_labels ⇒ Object
Constructor Details
#initialize(packing) ⇒ Face
Returns a new instance of Face.
77 78 79 80 81 82 83 84 85 |
# File 'lib/box_packer/svg_exporter.rb', line 77 def initialize(packing) @i, @j, @k = @@coords_mapping.dup @front = @@front @axes = @@axes.dup @width = @@container_dimensions[i] * @@scale @height = @@container_dimensions[j] * @@scale iterate_class_variables @items = sorted_items(packing) end |
Instance Attribute Details
#axes ⇒ Object (readonly)
Returns the value of attribute axes.
55 56 57 |
# File 'lib/box_packer/svg_exporter.rb', line 55 def axes @axes end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
55 56 57 |
# File 'lib/box_packer/svg_exporter.rb', line 55 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
55 56 57 |
# File 'lib/box_packer/svg_exporter.rb', line 55 def width @width end |
Class Method Details
.reset(margin, scale, container_dimensions) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/box_packer/svg_exporter.rb', line 57 def self.reset(margin, scale, container_dimensions) @@coords_mapping = [0, 1, 2] @@front = true @@margin = margin @@axes = [margin, margin] @@scale = scale @@container_dimensions = container_dimensions end |
Instance Method Details
#iterate_class_variables ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/box_packer/svg_exporter.rb', line 66 def iterate_class_variables if front @@axes[0] = width + @@margin * 2 else @@coords_mapping.rotate! @@axes[0] = @@margin @@axes[1] += height + @@margin end @@front = !@@front end |
#outline ⇒ Object
87 88 89 |
# File 'lib/box_packer/svg_exporter.rb', line 87 def outline @axes + [width, height] end |
#rectangles_and_labels ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/box_packer/svg_exporter.rb', line 91 def rectangles_and_labels items.map do |item| x = axes[0] + item.position[i] * @@scale y = axes[1] + item.position[j] * @@scale width = item.dimensions[i] * @@scale height = item.dimensions[j] * @@scale label_x = x + width / 2 - item.label.length label_y = y + height / 2 { rectangle: [x, y, width, height, fill: item.colour], label: [label_x, label_y, item.label] } end end |