more mem optimizations: poly length/area. worker now cleans up widget groups

This commit is contained in:
Stewart Allen 2021-06-18 22:57:30 -04:00
commit fdfce594d4
4 changed files with 24 additions and 9 deletions

View file

@ -31,14 +31,16 @@
constructor(points) { constructor(points) {
this.id = seqid++; // polygon unique id this.id = seqid++; // polygon unique id
this.open = false; this.open = false;
this.length = 0; // number of points
this.points = []; // ordered array of points this.points = []; // ordered array of points
this.area2 = 0.0; // computed as 2x area (sign = direction)
this.parent = null; // enclosing parent polygon this.parent = null; // enclosing parent polygon
this.depth = 0; // depth nested from top parent (density for support fill) this.depth = 0; // depth nested from top parent (density for support fill)
if (points) this.addPoints(points); if (points) this.addPoints(points);
} }
get length() {
return this.points.length;
}
get bounds() { get bounds() {
if (this._bounds) { if (this._bounds) {
return this._bounds; return this._bounds;
@ -891,7 +893,6 @@
// clone any point belonging to another polygon // clone any point belonging to another polygon
if (p.poly) p = p.clone(); if (p.poly) p = p.clone();
p.poly = this; p.poly = this;
this.length++;
this.points.push(p); this.points.push(p);
return p; return p;
}; };
@ -991,7 +992,9 @@
* @returns {Polygon} self * @returns {Polygon} self
*/ */
PRO.reverse = function() { PRO.reverse = function() {
if (this.area2) {
this.area2 = -this.area2; this.area2 = -this.area2;
}
this.points = this.points.reverse(); this.points = this.points.reverse();
return this; return this;
}; };
@ -1351,8 +1354,11 @@
* @returns {number} area * @returns {number} area
*/ */
PRO.area = function(raw) { PRO.area = function(raw) {
if (this.length < 3) return 0; if (this.length < 3) {
if (this.area2 === 0.0) { return 0;
}
if (this.area2 === undefined) {
this.area2 = 0.0;
for (let p=this.points,pl=p.length,pi=0,p1,p2; pi<pl; pi++) { for (let p=this.points,pl=p.length,pi=0,p1,p2; pi<pl; pi++) {
p1 = p[pi]; p1 = p[pi];
p2 = p[(pi+1)%pl]; p2 = p[(pi+1)%pl];
@ -1369,7 +1375,9 @@
* @returns {number} area * @returns {number} area
*/ */
PRO.areaDeep = function() { PRO.areaDeep = function() {
if (!this.inner) return this.area(); if (!this.inner) {
return this.area();
}
let i, c = this.inner, a = this.area(); let i, c = this.inner, a = this.area();
for (i=0; i<c.length; i++) { for (i=0; i<c.length; i++) {
a -= c[i].area(); a -= c[i].area();

View file

@ -2872,7 +2872,7 @@
complete = {}; complete = {};
UI.back.style.display = ''; UI.back.style.display = '';
UI.render.style.display = ''; UI.render.style.display = '';
// KIRI.work.clear(); KIRI.client.clear();
STACKS.clear(); STACKS.clear();
hideSlider(); hideSlider();
updateSpeeds(); updateSpeeds();

View file

@ -123,6 +123,10 @@
} }
}); });
return bounds; return bounds;
},
clear: function() {
groups.length = 0;
} }
}; };

View file

@ -47,6 +47,7 @@ KIRI.worker = {
current.print = null; current.print = null;
dispatch.group = wgroup = {}; dispatch.group = wgroup = {};
dispatch.cache = wcache = {}; dispatch.cache = wcache = {};
KIRI.Widget.Groups.clear();
send.done({ clear: true }); send.done({ clear: true });
}, },
@ -162,6 +163,8 @@ KIRI.worker = {
slice: function(data, send) { slice: function(data, send) {
send.data({update:0.001, updateStatus:"slicing"}); send.data({update:0.001, updateStatus:"slicing"});
current.print = null;
let settings = data.settings, let settings = data.settings,
widget = wcache[data.id], widget = wcache[data.id],
last = time(), last = time(),