Skip to content

Commit 0e72ca5

Browse files
committed
Save positions of boxs
1 parent bb38066 commit 0e72ca5

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

ShapeAlgorithm.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class ShapeAlgorithm {
1818
this.matrix = [];
1919
this.labels = [];
2020
this.sizes = [];
21+
this.positions = [];
2122

2223
this.init();
2324
}
@@ -100,6 +101,14 @@ class ShapeAlgorithm {
100101

101102
const color = this.randomColor();
102103

104+
if (! this.positions[`${this.biggest_box.w}_${this.biggest_box.h}`]) this.positions[`${this.biggest_box.w}_${this.biggest_box.h}`] = [];
105+
this.positions[`${this.biggest_box.w}_${this.biggest_box.h}`].push({
106+
"from_w": i + 1,
107+
"from_h": j + 1,
108+
"to_w": i + this.biggest_box.h,
109+
"to_h": j + this.biggest_box.w
110+
});
111+
103112
for (let k = 0; k < this.biggest_box.h; k++) {
104113
for (let l = 0; l < this.biggest_box.w; l++) {
105114
this.matrix[i + k][j + l] = {
@@ -128,9 +137,16 @@ class ShapeAlgorithm {
128137
this.labels[`${size[0]}_${size[1]}`].quantity++;
129138
const key = this.labels[`${size[0]}_${size[1]}`];
130139

131-
132140
const color = this.randomColor();
133141

142+
if (! this.positions[`${size[0]}_${size[1]}`]) this.positions[`${size[0]}_${size[1]}`] = [];
143+
this.positions[`${size[0]}_${size[1]}`].push({
144+
"from_w": res["x"] + 1,
145+
"from_h": res["y"] + 1,
146+
"to_w": res["x"] + size[0],
147+
"to_h": res["y"] + size[1]
148+
});
149+
134150
for (let i = 0; i < size[1]; i++) {
135151
for (let j = 0; j < size[0]; j++) {
136152
this.matrix[res["y"] + i][res["x"] + j] = {
@@ -221,7 +237,8 @@ class ShapeAlgorithm {
221237
"label": label.name,
222238
"quantity": label.quantity,
223239
"width": parseInt(keys[0]),
224-
"height": parseInt(keys[1])
240+
"height": parseInt(keys[1]),
241+
"positions": this.positions[`${keys[0]}_${keys[1]}`]
225242
});
226243
}
227244

demo.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ <h1>Shapes Algorithm</h1>
6868
quantities_title.style.display = "block";
6969

7070
const quantities = shape.getQuantities();
71+
console.log(quantities);
7172
for (let i = 0; i < quantities.length; i++) {
7273
const quantity = quantities[i];
7374
const elm_quantity = document.createElement("li");

0 commit comments

Comments
 (0)