Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit caea07e

Browse files
authored
Merge pull request #23 from juakotorres/feature/border-conditions
border points and segments included on file
2 parents 645d905 + 85dd6f1 commit caea07e

File tree

1 file changed

+170
-53
lines changed

1 file changed

+170
-53
lines changed

front/src/components/PackingTab.vue

Lines changed: 170 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<download-icon/>
3232
</v-btn>
3333
</template>
34-
<span>Export</span>
34+
<span>Download Mesh</span>
3535
</v-tooltip>
3636
<v-tooltip top>
3737
<template v-slot:activator="{ on }">
@@ -570,39 +570,41 @@
570570
};
571571
let height = this.packing.height;
572572
let width = this.packing.width;
573-
this.packing.polygons.forEach(pol => {
574-
for (let i = 0; i < pol.points.length; i++) {
575-
let pntA = pol.points[i];
576-
let pntB = pol.points[(i + 1) % pol.points.length];
577-
578-
if ([pntA.x, pntA.y] in this.packing.graph && [pntB.x, pntB.y] in this.packing.graph[[pntA.x, pntA.y]]) {
579-
this.packing.graph[[pntA.x, pntA.y]][[pntB.x, pntB.y]] = {
580-
selected: false
581-
}
582-
} else if ([pntB.x, pntB.y] in this.packing.graph && [pntA.x, pntA.y] in this.packing.graph[[pntB.x, pntB.y]]) {
583-
this.packing.graph[[pntB.x, pntB.y]][[pntA.x, pntA.y]] = {
584-
selected: false
573+
if(this.packing.graph) {
574+
this.packing.polygons.forEach(pol => {
575+
for (let i = 0; i < pol.points.length; i++) {
576+
let pntA = pol.points[i];
577+
let pntB = pol.points[(i + 1) % pol.points.length];
578+
579+
if ([pntA.x, pntA.y] in this.packing.graph && [pntB.x, pntB.y] in this.packing.graph[[pntA.x, pntA.y]]) {
580+
this.packing.graph[[pntA.x, pntA.y]][[pntB.x, pntB.y]] = {
581+
selected: false
582+
}
583+
} else if ([pntB.x, pntB.y] in this.packing.graph && [pntA.x, pntA.y] in this.packing.graph[[pntB.x, pntB.y]]) {
584+
this.packing.graph[[pntB.x, pntB.y]][[pntA.x, pntA.y]] = {
585+
selected: false
586+
}
585587
}
586588
}
587-
}
588-
});
589-
this.packing.polygons.forEach(pol => {
590-
pol.selected = this.polygonIntersection(pol, box, width, height, p);
591-
for (let i = 0; i < pol.points.length; i++) {
592-
let pntA = pol.points[i];
593-
let pntB = pol.points[(i + 1) % pol.points.length];
594-
595-
if ([pntA.x, pntA.y] in this.packing.graph && [pntB.x, pntB.y] in this.packing.graph[[pntA.x, pntA.y]]) {
596-
this.packing.graph[[pntA.x, pntA.y]][[pntB.x, pntB.y]] = {
597-
selected: pol.selected || this.packing.graph[[pntA.x, pntA.y]][[pntB.x, pntB.y]].selected
598-
}
599-
} else if ([pntB.x, pntB.y] in this.packing.graph && [pntA.x, pntA.y] in this.packing.graph[[pntB.x, pntB.y]]) {
600-
this.packing.graph[[pntB.x, pntB.y]][[pntA.x, pntA.y]] = {
601-
selected: pol.selected || this.packing.graph[[pntB.x, pntB.y]][[pntA.x, pntA.y]].selected
589+
});
590+
this.packing.polygons.forEach(pol => {
591+
pol.selected = this.polygonIntersection(pol, box, width, height, p);
592+
for (let i = 0; i < pol.points.length; i++) {
593+
let pntA = pol.points[i];
594+
let pntB = pol.points[(i + 1) % pol.points.length];
595+
596+
if ([pntA.x, pntA.y] in this.packing.graph && [pntB.x, pntB.y] in this.packing.graph[[pntA.x, pntA.y]]) {
597+
this.packing.graph[[pntA.x, pntA.y]][[pntB.x, pntB.y]] = {
598+
selected: pol.selected || this.packing.graph[[pntA.x, pntA.y]][[pntB.x, pntB.y]].selected
599+
}
600+
} else if ([pntB.x, pntB.y] in this.packing.graph && [pntA.x, pntA.y] in this.packing.graph[[pntB.x, pntB.y]]) {
601+
this.packing.graph[[pntB.x, pntB.y]][[pntA.x, pntA.y]] = {
602+
selected: pol.selected || this.packing.graph[[pntB.x, pntB.y]][[pntA.x, pntA.y]].selected
603+
}
602604
}
603605
}
604-
}
605-
});
606+
});
607+
}
606608
dragged = false;
607609
p.draw();
608610
}
@@ -624,31 +626,33 @@
624626
let graph = this.packing.graph;
625627
let height = this.packing.height;
626628
let width = this.packing.width;
627-
Object.keys(graph).forEach(function (pointA) {
628-
Object.keys(graph[pointA]).forEach(function (pointB) {
629-
const pntA = JSON.parse("[" + pointA + "]");
630-
const pntB = JSON.parse("[" + pointB + "]");
631-
632-
if (graph[pointA][pointB].selected) {
633-
p.stroke(189, 189, 189);
634-
} else {
635-
p.stroke(33, 33, 33);
636-
}
629+
if(graph) {
630+
Object.keys(graph).forEach(function (pointA) {
631+
Object.keys(graph[pointA]).forEach(function (pointB) {
632+
const pntA = JSON.parse("[" + pointA + "]");
633+
const pntB = JSON.parse("[" + pointB + "]");
634+
635+
if (graph[pointA][pointB].selected) {
636+
p.stroke(189, 189, 189);
637+
} else {
638+
p.stroke(33, 33, 33);
639+
}
637640
638-
if (graph[pointA][pointB].selected) {
639-
p.strokeWeight(4);
640-
} else {
641-
p.strokeWeight(3);
642-
}
641+
if (graph[pointA][pointB].selected) {
642+
p.strokeWeight(4);
643+
} else {
644+
p.strokeWeight(3);
645+
}
643646
644-
p.line(
645-
(pntA[0] / width) * p.width,
646-
((height - pntA[1]) / height) * p.height,
647-
(pntB[0] / width) * p.width,
648-
((height - pntB[1]) / height) * p.height
649-
);
647+
p.line(
648+
(pntA[0] / width) * p.width,
649+
((height - pntA[1]) / height) * p.height,
650+
(pntB[0] / width) * p.width,
651+
((height - pntB[1]) / height) * p.height
652+
);
653+
});
650654
});
651-
});
655+
}
652656
if (locked) {
653657
p.strokeWeight(3);
654658
p.stroke(239, 83, 80);
@@ -776,14 +780,22 @@
776780
let points = this.packing.draw.points;
777781
let edges = this.packing.draw.edges;
778782
let polygons = this.packing.draw.polygons;
783+
let borderPoints = this.packing.draw.borderPoints;
784+
let borderSegments = this.packing.draw.borderSegments;
779785
780786
let sortedPoints = this.sortDictionary(points);
781787
let sortedEdges = this.sortDictionary(edges);
782788
let sortedPolygons = this.sortPolygons(polygons);
783789
let properties = JSON.parse(localStorage.getItem('properties'));
784790
let propertiesArray = Object.keys(properties);
785791
786-
file += Object.keys(points).length + ' ' + Object.keys(edges).length + ' ' + propertiesArray.length + ' ' + Object.keys(polygons).length + '\n';
792+
file += Object.keys(points).length
793+
+ ' ' + Object.keys(edges).length
794+
+ ' ' + propertiesArray.length
795+
+ ' ' + Object.keys(polygons).length
796+
+ ' ' + Object.keys(borderPoints).length
797+
+ ' ' + Object.keys(borderSegments).length
798+
+ '\n';
787799
788800
sortedPoints.forEach(point => {
789801
let splitted = point[0].split(",");
@@ -818,6 +830,26 @@
818830
file += '\n';
819831
});
820832
833+
Object.keys(borderPoints).forEach(bp => {
834+
file += (borderPoints[bp].pointIndex + ' ');
835+
file += (borderPoints[bp].polygons.length + ' ');
836+
borderPoints[bp].polygons.forEach(pol => {
837+
file += (pol + ' ');
838+
});
839+
file = file.slice(0, -1);
840+
file += '\n';
841+
});
842+
843+
Object.keys(borderSegments).forEach(bs => {
844+
file += (borderSegments[bs].segmentIndex + ' ');
845+
file += (borderSegments[bs].polygons.length + ' ');
846+
borderSegments[bs].polygons.forEach(pol => {
847+
file += (pol + ' ');
848+
});
849+
file = file.slice(0, -1);
850+
file += '\n';
851+
});
852+
821853
822854
let filename = 'packing.txt';
823855
let universalBOM = "\uFEFF";
@@ -1026,15 +1058,83 @@
10261058
parseMesh(mesh) {
10271059
//console.log(resp);
10281060
1061+
const width = mesh.width;
1062+
const height = mesh.height;
1063+
10291064
let points = {};
10301065
let edges = {};
10311066
let polygons = {};
1067+
let borderPoints = {};
1068+
let borderSegments = {};
10321069
let edgesG = {};
10331070
let cEdgesG = {};
10341071
let p = 1;
10351072
let e = 1;
1073+
let bp = 1;
1074+
let bs = 1;
10361075
let polCount = 1;
10371076
1077+
function checkEpsilon(value, equalValue, precision = 1e-8) {
1078+
return Math.abs(value - equalValue) < precision;
1079+
}
1080+
1081+
function isBorderPoint(point, minX, maxX, minY, maxY) {
1082+
if(checkEpsilon(point.x, minX)
1083+
|| checkEpsilon(point.x, maxX)
1084+
|| checkEpsilon(point.y, minY)
1085+
|| checkEpsilon(point.y, maxY)) {
1086+
return true;
1087+
}
1088+
return false;
1089+
}
1090+
1091+
function checkBorderPoint(point, borderPoints, width, height, bpCount, polCount) {
1092+
let nPoint = false;
1093+
// Check if the point is on the border of the container.
1094+
if (isBorderPoint(point, 0, width, 0, height)) {
1095+
1096+
// Check if the point is already labeled.
1097+
if (!([point.x, point.y] in borderPoints)) {
1098+
borderPoints[[point.x, point.y]] = {
1099+
index: bpCount,
1100+
pointIndex: points[[point.x, point.y]],
1101+
polygons: []
1102+
};
1103+
nPoint = true;
1104+
}
1105+
1106+
// Add the polygon if needed.
1107+
if (!borderPoints[[point.x, point.y]].polygons.includes(polCount)) {
1108+
borderPoints[[point.x, point.y]].polygons.push(polCount);
1109+
}
1110+
}
1111+
return nPoint;
1112+
}
1113+
1114+
function checkBorderSegment(pointA, pointB, borderSegments, width, height, bsCount, polCount) {
1115+
let nSegment = false;
1116+
// Check if one of the points is on the border of the container.
1117+
if (isBorderPoint(pointA, 0, width, 0, height)
1118+
|| isBorderPoint(pointB, 0, width, 0, height)) {
1119+
1120+
// Check if the segment is already labeled.
1121+
if (!([points[[pointA.x, pointA.y]], points[[pointB.x, pointB.y]]] in borderSegments)) {
1122+
borderSegments[[points[[pointA.x, pointA.y]], points[[pointB.x, pointB.y]]]] = {
1123+
index: bsCount,
1124+
segmentIndex: edges[[points[[pointA.x, pointA.y]], points[[pointB.x, pointB.y]]]],
1125+
polygons: []
1126+
};
1127+
nSegment = true;
1128+
}
1129+
1130+
// Add the polygon if needed.
1131+
if (!borderSegments[[points[[pointA.x, pointA.y]], points[[pointB.x, pointB.y]]]].polygons.includes(polCount)) {
1132+
borderSegments[[points[[pointA.x, pointA.y]], points[[pointB.x, pointB.y]]]].polygons.push(polCount);
1133+
}
1134+
}
1135+
return nSegment;
1136+
}
1137+
10381138
mesh.polygons.forEach(pol => {
10391139
10401140
let polygonPoints = [];
@@ -1043,6 +1143,7 @@
10431143
10441144
let pointA = pol.points[i];
10451145
let pointB = pol.points[(i + 1) % pol.points.length];
1146+
10461147
if (!([pointA.x, pointA.y] in points)) {
10471148
points[[pointA.x, pointA.y]] = p;
10481149
p += 1;
@@ -1053,8 +1154,22 @@
10531154
p += 1;
10541155
}
10551156
1157+
// Check if the points are on the border of the container.
1158+
if (checkBorderPoint(pointA, borderPoints, width, height, bp, polCount)) {
1159+
bp += 1
1160+
}
1161+
if (checkBorderPoint(pointB, borderPoints, width, height, bp, polCount)) {
1162+
bp += 1
1163+
}
1164+
10561165
if (!([points[[pointA.x, pointA.y]], points[[pointB.x, pointB.y]]] in edges)) {
10571166
edges[[points[[pointA.x, pointA.y]], points[[pointB.x, pointB.y]]]] = e;
1167+
1168+
// Check if the segment is on the border of the container.
1169+
if (checkBorderSegment(pointA, pointB, borderSegments, width, height, bs, polCount)) {
1170+
bs += 1
1171+
}
1172+
10581173
e += 1;
10591174
10601175
if (!([pointA.x, pointA.y] in cEdgesG)) {
@@ -1093,6 +1208,8 @@
10931208
this.packing.draw.points = points;
10941209
this.packing.draw.edges = edges;
10951210
this.packing.draw.polygons = polygons;
1211+
this.packing.draw.borderPoints = borderPoints;
1212+
this.packing.draw.borderSegments = borderSegments;
10961213
this.packing.graph = edgesG;
10971214
this.packing.rGraph = cEdgesG;
10981215
},

0 commit comments

Comments
 (0)