normalize prototype shortcuts

This commit is contained in:
Stewart Allen 2017-10-28 13:30:08 -04:00
commit 8d57ed0883
10 changed files with 229 additions and 230 deletions

View file

@ -27,7 +27,7 @@ var gs_base_bounds = exports;
ABS = Math.abs, ABS = Math.abs,
MIN = Math.min, MIN = Math.min,
MAX = Math.max, MAX = Math.max,
BoP = Bounds.prototype; PRO = Bounds.prototype;
BASE.Bounds = Bounds; BASE.Bounds = Bounds;
BASE.newBounds = newBounds; BASE.newBounds = newBounds;
@ -39,7 +39,7 @@ var gs_base_bounds = exports;
/** /**
* @returns {Bounds} * @returns {Bounds}
*/ */
BoP.clone = function() { PRO.clone = function() {
var b = new Bounds(); var b = new Bounds();
b.minx = this.minx; b.minx = this.minx;
b.miny = this.miny; b.miny = this.miny;
@ -48,7 +48,7 @@ var gs_base_bounds = exports;
return b; return b;
}; };
BoP.equals = function(bounds, margin) { PRO.equals = function(bounds, margin) {
if (!margin) margin = BASE.config.precision_offset; if (!margin) margin = BASE.config.precision_offset;
return UTIL.isCloseTo(this.minx, bounds.minx, margin) && return UTIL.isCloseTo(this.minx, bounds.minx, margin) &&
UTIL.isCloseTo(this.miny, bounds.miny, margin) && UTIL.isCloseTo(this.miny, bounds.miny, margin) &&
@ -59,7 +59,7 @@ var gs_base_bounds = exports;
/** /**
* @param {Bounds} b * @param {Bounds} b
*/ */
BoP.merge = function(b) { PRO.merge = function(b) {
this.minx = MIN(this.minx, b.minx); this.minx = MIN(this.minx, b.minx);
this.maxx = MAX(this.maxx, b.maxx); this.maxx = MAX(this.maxx, b.maxx);
this.miny = MIN(this.miny, b.miny); this.miny = MIN(this.miny, b.miny);
@ -69,7 +69,7 @@ var gs_base_bounds = exports;
/** /**
* @param {Point} p * @param {Point} p
*/ */
BoP.update = function(p) { PRO.update = function(p) {
this.minx = MIN(this.minx, p.x); this.minx = MIN(this.minx, p.x);
this.maxx = MAX(this.maxx, p.x); this.maxx = MAX(this.maxx, p.x);
this.miny = MIN(this.miny, p.y); this.miny = MIN(this.miny, p.y);
@ -77,15 +77,15 @@ var gs_base_bounds = exports;
if (this.minx === p.x) this.leftMost = p; if (this.minx === p.x) this.leftMost = p;
}; };
BoP.contains = function(bounds) { PRO.contains = function(bounds) {
return bounds.isNested(this); return bounds.isNested(this);
}; };
BoP.containsXY = function(x,y) { PRO.containsXY = function(x,y) {
return x >= this.minx && x <= this.maxx && y >= this.miny && y <= this.maxy; return x >= this.minx && x <= this.maxx && y >= this.miny && y <= this.maxy;
}; };
BoP.containsOffsetXY = function(x,y,offset) { PRO.containsOffsetXY = function(x,y,offset) {
return x >= this.minx-offset && x <= this.maxx+offset && y >= this.miny-offset && y <= this.maxy+offset; return x >= this.minx-offset && x <= this.maxx+offset && y >= this.miny-offset && y <= this.maxy+offset;
}; };
@ -93,7 +93,7 @@ var gs_base_bounds = exports;
* @param {Bounds} parent * @param {Bounds} parent
* @returns {boolean} true if fully inside parent bounds * @returns {boolean} true if fully inside parent bounds
*/ */
BoP.isNested = function(parent) { PRO.isNested = function(parent) {
return ( return (
this.minx >= parent.minx - CONF.precision_bounds && // min-x this.minx >= parent.minx - CONF.precision_bounds && // min-x
this.maxx <= parent.maxx + CONF.precision_bounds && // max-x this.maxx <= parent.maxx + CONF.precision_bounds && // max-x
@ -107,26 +107,26 @@ var gs_base_bounds = exports;
* @param {number} precision * @param {number} precision
* @returns {boolean} * @returns {boolean}
*/ */
BoP.overlaps = function(b, precision) { PRO.overlaps = function(b, precision) {
return ( return (
ABS(this.centerx() - b.centerx()) * 2 - precision < this.width() + b.width() && ABS(this.centerx() - b.centerx()) * 2 - precision < this.width() + b.width() &&
ABS(this.centery() - b.centery()) * 2 - precision < this.height() + b.height() ABS(this.centery() - b.centery()) * 2 - precision < this.height() + b.height()
); );
}; };
BoP.width = function() { PRO.width = function() {
return this.maxx - this.minx; return this.maxx - this.minx;
}; };
BoP.height = function() { PRO.height = function() {
return this.maxy - this.miny; return this.maxy - this.miny;
}; };
BoP.centerx = function() { PRO.centerx = function() {
return this.minx + this.width() / 2; return this.minx + this.width() / 2;
}; };
BoP.centery = function() { PRO.centery = function() {
return this.miny + this.height() / 2; return this.miny + this.height() / 2;
}; };

View file

@ -27,7 +27,7 @@ var gs_base_line = exports;
} }
var BASE = self.base, var BASE = self.base,
LiP = Line.prototype; PRO = Line.prototype;
BASE.Line = Line; BASE.Line = Line;
BASE.newLine = newLine; BASE.newLine = newLine;
@ -40,28 +40,28 @@ var gs_base_line = exports;
/** /**
* @returns {number} * @returns {number}
*/ */
LiP.length = function() { PRO.length = function() {
return Math.sqrt(this.length2()); return Math.sqrt(this.length2());
}; };
/** /**
* @returns {number} square of length * @returns {number} square of length
*/ */
LiP.length2 = function() { PRO.length2 = function() {
return this.p1.distToSq2D(this.p2); return this.p1.distToSq2D(this.p2);
}; };
/** /**
* @returns {Slope} * @returns {Slope}
*/ */
LiP.slope = function() { PRO.slope = function() {
return BASE.newSlope(this.p1.slopeTo(this.p2)); return BASE.newSlope(this.p1.slopeTo(this.p2));
}; };
/** /**
* @returns {Line} * @returns {Line}
*/ */
LiP.reverse = function() { PRO.reverse = function() {
var t = this.p1; var t = this.p1;
this.p1 = this.p2; this.p1 = this.p2;
this.p2 = t; this.p2 = t;
@ -71,7 +71,7 @@ var gs_base_line = exports;
/** /**
* @returns {Point} * @returns {Point}
*/ */
LiP.midpoint = function() { PRO.midpoint = function() {
return this.p1.midPointTo(this.p2); return this.p1.midPointTo(this.p2);
}; };
@ -79,7 +79,7 @@ var gs_base_line = exports;
* @param {Line} line * @param {Line} line
* @returns {boolean} * @returns {boolean}
*/ */
LiP.isCollinear = function(line) { PRO.isCollinear = function(line) {
var p1 = this.p1, var p1 = this.p1,
p2 = this.p2, p2 = this.p2,
p3 = line.p1, p3 = line.p1,

View file

@ -49,7 +49,7 @@ var gs_base_point = exports;
CONF = BASE.config, CONF = BASE.config,
KEYS = BASE.key, KEYS = BASE.key,
ROUND = UTIL.round, ROUND = UTIL.round,
PoP = Point.prototype; PRO = Point.prototype;
BASE.Point = Point; BASE.Point = Point;
BASE.newPoint = newPoint; BASE.newPoint = newPoint;
@ -58,47 +58,47 @@ var gs_base_point = exports;
* Point Prototype Functions * Point Prototype Functions
******************************************************************* */ ******************************************************************* */
PoP.setZ = function(z) { PRO.setZ = function(z) {
this.z = z; this.z = z;
return this; return this;
} }
PoP.swapXZ = function() { PRO.swapXZ = function() {
var p = this, var p = this,
t = p.x; t = p.x;
p.x = p.z; p.x = p.z;
p.z = t; p.z = t;
}; };
PoP.swapYZ = function() { PRO.swapYZ = function() {
var p = this, var p = this,
t = p.y; t = p.y;
p.y = p.z; p.y = p.z;
p.z = t; p.z = t;
}; };
PoP.round = function(precision) { PRO.round = function(precision) {
return newPoint(ROUND(this.x,precision), ROUND(this.y,precision), ROUND(this.z,precision)); return newPoint(ROUND(this.x,precision), ROUND(this.y,precision), ROUND(this.z,precision));
}; };
PoP.addFacet = function(facet) { PRO.addFacet = function(facet) {
if (!this.group) this.group = []; if (!this.group) this.group = [];
this.group.push(facet); this.group.push(facet);
return this; return this;
}; };
PoP.rekey = function() { PRO.rekey = function() {
this.key = [this.x,this.y,this.z].join(','); this.key = [this.x,this.y,this.z].join(',');
}; };
PoP.toString = function() { PRO.toString = function() {
return this.key; return this.key;
}; };
/** /**
* @returns {Point} * @returns {Point}
*/ */
PoP.clone = function() { PRO.clone = function() {
return newPoint(this.x, this.y, this.z, this.key); return newPoint(this.x, this.y, this.z, this.key);
}; };
@ -106,7 +106,7 @@ var gs_base_point = exports;
* @param {Point} p * @param {Point} p
* @returns {Slope} * @returns {Slope}
*/ */
PoP.slopeTo = function(p) { PRO.slopeTo = function(p) {
return BASE.newSlope(this, p); return BASE.newSlope(this, p);
}; };
@ -116,7 +116,7 @@ var gs_base_point = exports;
* @param {String} [k] * @param {String} [k]
* @returns {Line} * @returns {Line}
*/ */
PoP.lineTo = function(p, k) { PRO.lineTo = function(p, k) {
return BASE.newLine(this, p, k); return BASE.newLine(this, p, k);
}; };
@ -125,7 +125,7 @@ var gs_base_point = exports;
* @param {number} [dist] * @param {number} [dist]
* @returns {boolean} * @returns {boolean}
*/ */
PoP.isNear = function(p, dist) { PRO.isNear = function(p, dist) {
return UTIL.isCloseTo(this.x, p.x, dist) && UTIL.isCloseTo(this.y, p.y, dist); return UTIL.isCloseTo(this.x, p.x, dist) && UTIL.isCloseTo(this.y, p.y, dist);
}; };
@ -137,7 +137,7 @@ var gs_base_point = exports;
* @param {Point} p2 * @param {Point} p2
* @returns {number} * @returns {number}
*/ */
PoP.distToLine = function(p1, p2) { PRO.distToLine = function(p1, p2) {
return Math.sqrt(this.distToLineSq(p1, p2)); return Math.sqrt(this.distToLineSq(p1, p2));
}; };
@ -149,7 +149,7 @@ var gs_base_point = exports;
* @param {Point} p2 * @param {Point} p2
* @returns {number} * @returns {number}
*/ */
PoP.distToLineSq = function(p1, p2) { PRO.distToLineSq = function(p1, p2) {
var p = this, var p = this,
d = UTIL.distSq(p1, p2); d = UTIL.distSq(p1, p2);
@ -168,7 +168,7 @@ var gs_base_point = exports;
* @param {number} dist2 * @param {number} dist2
* @returns {boolean} * @returns {boolean}
*/ */
PoP.withinDist2 = function(p1, p2, dist2) { PRO.withinDist2 = function(p1, p2, dist2) {
var ll2 = p1.distToSq2D(p2), var ll2 = p1.distToSq2D(p2),
dp1 = this.distToSq2D(p1), dp1 = this.distToSq2D(p1),
dp2 = this.distToSq2D(p2); dp2 = this.distToSq2D(p2);
@ -192,7 +192,7 @@ var gs_base_point = exports;
* @param {Point} p2 * @param {Point} p2
* @returns {Point} * @returns {Point}
*/ */
PoP.midPointTo = function(p2) { PRO.midPointTo = function(p2) {
return newPoint((this.x + p2.x)/2, (this.y + p2.y)/2, this.z); return newPoint((this.x + p2.x)/2, (this.y + p2.y)/2, this.z);
}; };
@ -200,7 +200,7 @@ var gs_base_point = exports;
* @param {Point} p2 * @param {Point} p2
* @returns {Point} * @returns {Point}
*/ */
PoP.midPointTo3D = function(p2) { PRO.midPointTo3D = function(p2) {
return newPoint( return newPoint(
(this.x + p2.x)/2, (this.x + p2.x)/2,
(this.y + p2.y)/2, (this.y + p2.y)/2,
@ -215,14 +215,14 @@ var gs_base_point = exports;
* @param mult * @param mult
* @returns {Point} * @returns {Point}
*/ */
PoP.projectOnSlope = function(slope, mult) { PRO.projectOnSlope = function(slope, mult) {
return newPoint( return newPoint(
this.x + slope.dx * mult, this.x + slope.dx * mult,
this.y + slope.dy * mult, this.y + slope.dy * mult,
this.z); this.z);
}; };
PoP.followTo = function(point, mult) { PRO.followTo = function(point, mult) {
return this.follow(this.slopeTo(point), mult); return this.follow(this.slopeTo(point), mult);
}; };
@ -234,7 +234,7 @@ var gs_base_point = exports;
* @param p2 * @param p2
* @param dist * @param dist
*/ */
PoP.offsetPointFrom = function(p2, dist) { PRO.offsetPointFrom = function(p2, dist) {
var p1 = this, var p1 = this,
dx = p2.x - p1.x, dx = p2.x - p1.x,
dy = p2.y - p1.y, dy = p2.y - p1.y,
@ -249,7 +249,7 @@ var gs_base_point = exports;
* @param {number} offset * @param {number} offset
* @returns {Line} * @returns {Line}
*/ */
PoP.offsetLineTo = function(p2, offset) { PRO.offsetLineTo = function(p2, offset) {
var p1 = this, var p1 = this,
dx = p2.x - p1.x, dx = p2.x - p1.x,
dy = p2.y - p1.y, dy = p2.y - p1.y,
@ -271,7 +271,7 @@ var gs_base_point = exports;
* @param {Polygon} poly * @param {Polygon} poly
* @returns {boolean} * @returns {boolean}
*/ */
PoP.inPolygon = function(poly) { PRO.inPolygon = function(poly) {
if (!poly.bounds.containsXY(this.x, this.y)) return false; if (!poly.bounds.containsXY(this.x, this.y)) return false;
var p = poly.points, pl = p.length, p1, p2, i, inside = false; var p = poly.points, pl = p.length, p1, p2, i, inside = false;
@ -296,7 +296,7 @@ var gs_base_point = exports;
* @param {Polygon | Polygon[]} poly * @param {Polygon | Polygon[]} poly
* @return {boolean} true if inside outer but not inner * @return {boolean} true if inside outer but not inner
*/ */
PoP.isInPolygon = function(poly) { PRO.isInPolygon = function(poly) {
var point = this, i; var point = this, i;
if (Array.isArray(poly)) { if (Array.isArray(poly)) {
for (i=0; i<poly.length; i++) { for (i=0; i<poly.length; i++) {
@ -321,7 +321,7 @@ var gs_base_point = exports;
* @param {Polygon | Polygon[]} poly * @param {Polygon | Polygon[]} poly
* @return {boolean} true if inside outer but not inner * @return {boolean} true if inside outer but not inner
*/ */
PoP.isInPolygonOnly = function(poly) { PRO.isInPolygonOnly = function(poly) {
var point = this, i; var point = this, i;
if (Array.isArray(poly)) { if (Array.isArray(poly)) {
for (i=0; i<poly.length; i++) { for (i=0; i<poly.length; i++) {
@ -347,7 +347,7 @@ var gs_base_point = exports;
* @param {boolean} [inner] process inner polygons * @param {boolean} [inner] process inner polygons
* @returns {boolean} * @returns {boolean}
*/ */
PoP.nearPolygon = function(poly, dist2, inner) { PRO.nearPolygon = function(poly, dist2, inner) {
// throw new Error("nearPolygon"); // throw new Error("nearPolygon");
for (var i=0, p=poly.points, pl=p.length ; i<pl; i++) { for (var i=0, p=poly.points, pl=p.length ; i<pl; i++) {
if (this.withinDist2(p[i], p[(i+1)%pl], dist2)) { if (this.withinDist2(p[i], p[(i+1)%pl], dist2)) {
@ -370,7 +370,7 @@ var gs_base_point = exports;
* @param {number} mindist2 * @param {number} mindist2
* @returns {boolean} * @returns {boolean}
*/ */
PoP.insideOffset = function(poly, offset, mindist2) { PRO.insideOffset = function(poly, offset, mindist2) {
return this.inPolygon(poly) === (offset > 0) && !this.nearPolygon(poly, mindist2); return this.inPolygon(poly) === (offset > 0) && !this.nearPolygon(poly, mindist2);
}; };
@ -382,7 +382,7 @@ var gs_base_point = exports;
* @param {number} distance * @param {number} distance
* @returns {Point} * @returns {Point}
*/ */
PoP.follow = function(slope, distance) { PRO.follow = function(slope, distance) {
var ls = distance / Math.sqrt(slope.dx * slope.dx + slope.dy * slope.dy); var ls = distance / Math.sqrt(slope.dx * slope.dx + slope.dy * slope.dy);
return newPoint(this.x + slope.dx * ls, this.y + slope.dy * ls, this.z); return newPoint(this.x + slope.dx * ls, this.y + slope.dy * ls, this.z);
}; };
@ -394,7 +394,7 @@ var gs_base_point = exports;
* @param {number} z * @param {number} z
* @returns {Point} * @returns {Point}
*/ */
PoP.intersectZ = function(p, z) { PRO.intersectZ = function(p, z) {
var dx = p.x - this.x, var dx = p.x - this.x,
dy = p.y - this.y, dy = p.y - this.y,
dz = p.z - this.z, dz = p.z - this.z,
@ -406,7 +406,7 @@ var gs_base_point = exports;
* @param {Point} p * @param {Point} p
* @returns {boolean} * @returns {boolean}
*/ */
PoP.isEqual2D = function(p) { PRO.isEqual2D = function(p) {
return this === p || (this.x === p.x && this.y === p.y); return this === p || (this.x === p.x && this.y === p.y);
}; };
@ -416,7 +416,7 @@ var gs_base_point = exports;
* @param {Point} p * @param {Point} p
* @returns {boolean} * @returns {boolean}
*/ */
PoP.isMergable2D = function(p) { PRO.isMergable2D = function(p) {
return this.isEqual2D(p) || (this.distToSq2D(p) < CONF.precision_merge_sq); return this.isEqual2D(p) || (this.distToSq2D(p) < CONF.precision_merge_sq);
}; };
@ -426,7 +426,7 @@ var gs_base_point = exports;
* @param {Point} p * @param {Point} p
* @returns {boolean} * @returns {boolean}
*/ */
PoP.isEqual = function(p) { PRO.isEqual = function(p) {
return this === p || (this.x === p.x && this.y === p.y && this.z === p.z); return this === p || (this.x === p.x && this.y === p.y && this.z === p.z);
}; };
@ -436,7 +436,7 @@ var gs_base_point = exports;
* @param {Point} p * @param {Point} p
* @returns {boolean} * @returns {boolean}
*/ */
PoP.isMergable3D = function(p) { PRO.isMergable3D = function(p) {
return this.isEqual(p) || (this.distToSq3D(p) < CONF.precision_merge_sq); return this.isEqual(p) || (this.distToSq3D(p) < CONF.precision_merge_sq);
}; };
@ -447,7 +447,7 @@ var gs_base_point = exports;
* @param {number} dist * @param {number} dist
* @returns {boolean} * @returns {boolean}
*/ */
PoP.isInBox = function(p, dist) { PRO.isInBox = function(p, dist) {
return Math.abs(this.x - p.x) < dist && Math.abs(this.y - p.y) < dist; return Math.abs(this.x - p.x) < dist && Math.abs(this.y - p.y) < dist;
}; };
@ -458,7 +458,7 @@ var gs_base_point = exports;
* @param {Polygon} poly * @param {Polygon} poly
* @param {number} [threshold] stop looking if under threshold * @param {number} [threshold] stop looking if under threshold
*/ */
PoP.distToPolySegments = function(poly, threshold) { PRO.distToPolySegments = function(poly, threshold) {
var point = this, var point = this,
mindist = Infinity; mindist = Infinity;
poly.forEachSegment(function(p1, p2) { poly.forEachSegment(function(p1, p2) {
@ -474,7 +474,7 @@ var gs_base_point = exports;
* @param {Polygon} poly * @param {Polygon} poly
* @param {number} [threshold] stop looking if under threshold * @param {number} [threshold] stop looking if under threshold
*/ */
PoP.distToPolyPoints = function(poly, threshold) { PRO.distToPolyPoints = function(poly, threshold) {
var point = this, mindist = Infinity; var point = this, mindist = Infinity;
poly.forEachPoint(function(pp) { poly.forEachPoint(function(pp) {
mindist = Math.min(mindist, point.distTo2D(pp)); mindist = Math.min(mindist, point.distTo2D(pp));
@ -488,7 +488,7 @@ var gs_base_point = exports;
* @param {number} max * @param {number} max
* @returns {Point} nearest point (less than max) from array to this point * @returns {Point} nearest point (less than max) from array to this point
*/ */
PoP.nearestTo = function(points, max) { PRO.nearestTo = function(points, max) {
if (!max) throw "missing max"; if (!max) throw "missing max";
var mind = Infinity, var mind = Infinity,
minp = null, minp = null,
@ -509,7 +509,7 @@ var gs_base_point = exports;
* @param {Point[]} points * @param {Point[]} points
* @return {number} average square dist to cloud of points * @return {number} average square dist to cloud of points
*/ */
PoP.averageDistTo = function(points) { PRO.averageDistTo = function(points) {
var sum = 0.0, count = 0, i; var sum = 0.0, count = 0, i;
for (i = 0; i < points.length; i++) { for (i = 0; i < points.length; i++) {
if (points[i] != this) { if (points[i] != this) {
@ -526,7 +526,7 @@ var gs_base_point = exports;
* @param {Point} p * @param {Point} p
* @returns {number} * @returns {number}
*/ */
PoP.distTo2D = function(p) { PRO.distTo2D = function(p) {
var dx = this.x - p.x, var dx = this.x - p.x,
dy = this.y - p.y; dy = this.y - p.y;
return Math.sqrt(dx * dx + dy * dy); return Math.sqrt(dx * dx + dy * dy);
@ -538,13 +538,13 @@ var gs_base_point = exports;
* @param {Point} p * @param {Point} p
* @returns {number} * @returns {number}
*/ */
PoP.distToSq2D = function(p) { PRO.distToSq2D = function(p) {
var dx = this.x - p.x, var dx = this.x - p.x,
dy = this.y - p.y; dy = this.y - p.y;
return dx * dx + dy * dy; return dx * dx + dy * dy;
}; };
PoP.distTo3D = function(p) { PRO.distTo3D = function(p) {
var dx = this.x - p.x, var dx = this.x - p.x,
dy = this.y - p.y, dy = this.y - p.y,
dz = this.z - p.z; dz = this.z - p.z;
@ -557,7 +557,7 @@ var gs_base_point = exports;
* @param {Point} p * @param {Point} p
* @returns {number} * @returns {number}
*/ */
PoP.distToSq3D = function(p) { PRO.distToSq3D = function(p) {
var dx = this.x - p.x, var dx = this.x - p.x,
dy = this.y - p.y, dy = this.y - p.y,
dz = this.z - p.z; dz = this.z - p.z;
@ -572,7 +572,7 @@ var gs_base_point = exports;
* @param {Point} c * @param {Point} c
* @returns {boolean} * @returns {boolean}
*/ */
PoP.inTriangle = function(a, b, c) { PRO.inTriangle = function(a, b, c) {
var as_x = this.x - a.x, var as_x = this.x - a.x,
as_y = this.y - a.y, as_y = this.y - a.y,
s_ab = (b.x - a.x) * as_y - (b.y - a.y) * as_x > 0; s_ab = (b.x - a.x) * as_y - (b.y - a.y) * as_x > 0;
@ -590,7 +590,7 @@ var gs_base_point = exports;
* @param {Point} p2 * @param {Point} p2
* @returns {boolean} * @returns {boolean}
*/ */
PoP.onLine = function(p1, p2) { PRO.onLine = function(p1, p2) {
return this.distToLine(p1, p2) < CONF.precision_point_on_line; return this.distToLine(p1, p2) < CONF.precision_point_on_line;
}; };
@ -599,7 +599,7 @@ var gs_base_point = exports;
* @param {THREE.Vector3} delta * @param {THREE.Vector3} delta
* @return {Point} new offset point * @return {Point} new offset point
*/ */
PoP.add = function(delta) { PRO.add = function(delta) {
return newPoint(this.x + delta.x, this.y + delta.y, this.z + delta.z); return newPoint(this.x + delta.x, this.y + delta.y, this.z + delta.z);
}; };
@ -608,7 +608,7 @@ var gs_base_point = exports;
* @param {THREE.Vector3} delta * @param {THREE.Vector3} delta
* @return {Point} new offset point * @return {Point} new offset point
*/ */
PoP.sub = function(delta) { PRO.sub = function(delta) {
return newPoint(this.x - delta.x, this.y - delta.y, this.z - delta.z); return newPoint(this.x - delta.x, this.y - delta.y, this.z - delta.z);
}; };
@ -616,7 +616,7 @@ var gs_base_point = exports;
* *
* @param {THREE.Vector3} delta * @param {THREE.Vector3} delta
*/ */
PoP.move = function(delta) { PRO.move = function(delta) {
this.x += delta.x; this.x += delta.x;
this.y += delta.y; this.y += delta.y;
this.z += delta.z; this.z += delta.z;

View file

@ -23,7 +23,7 @@ var gs_base_polygon = exports;
DEG2RAD = PI / 180, DEG2RAD = PI / 180,
Bounds = BASE.Bounds, Bounds = BASE.Bounds,
newPoint = BASE.newPoint, newPoint = BASE.newPoint,
PlP = Polygon.prototype, PRO = Polygon.prototype,
nest_test_slope = BASE.newSlope(newPoint(0,0,0,KEYS.NONE), newPoint(1,0,0,KEYS.NONE)), nest_test_slope = BASE.newSlope(newPoint(0,0,0,KEYS.NONE), newPoint(1,0,0,KEYS.NONE)),
min_area_mult = 2.0, min_area_mult = 2.0,
seqid = 1; seqid = 1;
@ -111,7 +111,7 @@ var gs_base_polygon = exports;
* Polygon Prototype Functions * Polygon Prototype Functions
******************************************************************* */ ******************************************************************* */
PlP.createConvexHull = function(points) { PRO.createConvexHull = function(points) {
function removeMiddle(a, b, c) { function removeMiddle(a, b, c) {
var cross = (a.x - b.x) * (c.y - b.y) - (a.y - b.y) * (c.x - b.x); var cross = (a.x - b.x) * (c.y - b.y) - (a.y - b.y) * (c.x - b.x);
var dot = (a.x - b.x) * (c.x - b.x) + (a.y - b.y) * (c.y - b.y); var dot = (a.x - b.x) * (c.x - b.x) + (a.y - b.y) * (c.y - b.y);
@ -138,7 +138,7 @@ var gs_base_polygon = exports;
return this; return this;
}; };
PlP.stepsFromRoot = function() { PRO.stepsFromRoot = function() {
var p = this.parent, steps = 0; var p = this.parent, steps = 0;
while (p) { while (p) {
if (p.inner && p.inner.length > 1) steps++; if (p.inner && p.inner.length > 1) steps++;
@ -147,15 +147,15 @@ var gs_base_polygon = exports;
return steps; return steps;
}; };
PlP.first = function() { PRO.first = function() {
return this.points[0]; return this.points[0];
}; };
PlP.last = function() { PRO.last = function() {
return this.points[this.length-1]; return this.points[this.length-1];
}; };
PlP.swap = function(x,y) { PRO.swap = function(x,y) {
var poly = this, var poly = this,
points = poly.points, points = poly.points,
length = points.length; length = points.length;
@ -176,7 +176,7 @@ var gs_base_polygon = exports;
* @param {boolean} [point] return just the center point * @param {boolean} [point] return just the center point
* @returns {Polygon|Point} a new polygon centered on x=0, y=0, z=0 * @returns {Polygon|Point} a new polygon centered on x=0, y=0, z=0
*/ */
PlP.center = function(point) { PRO.center = function(point) {
var ap = newPoint(0,0,0,null), np = newPolygon(), pa = this.points; var ap = newPoint(0,0,0,null), np = newPolygon(), pa = this.points;
pa.forEach(function(p) { pa.forEach(function(p) {
ap.x += p.x; ap.x += p.x;
@ -200,7 +200,7 @@ var gs_base_polygon = exports;
/** /**
* @returns {Point} center of a polygon assuming it's a circle * @returns {Point} center of a polygon assuming it's a circle
*/ */
PlP.circleCenter = function() { PRO.circleCenter = function() {
var points = this.points, var points = this.points,
length = points.length, length = points.length,
incr = Math.floor(length / 3), incr = Math.floor(length / 3),
@ -229,7 +229,7 @@ var gs_base_polygon = exports;
* @param {number} width * @param {number} width
* @param {number} height * @param {number} height
*/ */
PlP.centerRectangle = function(center, width, height) { PRO.centerRectangle = function(center, width, height) {
width /= 2; width /= 2;
height /= 2; height /= 2;
this.push(newPoint(center.x - width, center.y - height, center.z)); this.push(newPoint(center.x - width, center.y - height, center.z));
@ -247,7 +247,7 @@ var gs_base_polygon = exports;
* @param {number} points * @param {number} points
* @param {boolean} clockwise * @param {boolean} clockwise
*/ */
PlP.centerCircle = function(center, radius, points, clockwise) { PRO.centerCircle = function(center, radius, points, clockwise) {
var angle = 0, add = 360 / points; var angle = 0, add = 360 / points;
if (clockwise) add = -add; if (clockwise) add = -add;
while (points-- > 0) { while (points-- > 0) {
@ -266,7 +266,7 @@ var gs_base_polygon = exports;
* @param {THREE.Vector3} offset * @param {THREE.Vector3} offset
* @returns {Polygon} * @returns {Polygon}
*/ */
PlP.move = function(offset) { PRO.move = function(offset) {
var scope = this, var scope = this,
bounds = scope.bounds = new Bounds(); bounds = scope.bounds = new Bounds();
scope.points.forEach(function(p) { scope.points.forEach(function(p) {
@ -277,7 +277,7 @@ var gs_base_polygon = exports;
return scope; return scope;
}; };
PlP.scale = function(scale, round) { PRO.scale = function(scale, round) {
var scope = this, var scope = this,
bounds = scope.bounds = new Bounds(); bounds = scope.bounds = new Bounds();
scope.points.forEach(function(p) { scope.points.forEach(function(p) {
@ -297,7 +297,7 @@ var gs_base_polygon = exports;
/** /**
* add fill angle hinting from longest segment * add fill angle hinting from longest segment
*/ */
PlP.hintFillAngle = function() { PRO.hintFillAngle = function() {
var index = 0, var index = 0,
points = this.points, points = this.points,
length = points.length, length = points.length,
@ -332,7 +332,7 @@ var gs_base_polygon = exports;
* @param {Boolean} deep * @param {Boolean} deep
* @returns {Polygon} * @returns {Polygon}
*/ */
PlP.clone = function(deep) { PRO.clone = function(deep) {
var np = newPolygon(), var np = newPolygon(),
ln = this.length, ln = this.length,
i = 0; i = 0;
@ -356,7 +356,7 @@ var gs_base_polygon = exports;
* @param {number} z * @param {number} z
* @returns {Polygon} this * @returns {Polygon} this
*/ */
PlP.setZ = function(z) { PRO.setZ = function(z) {
var ar = this.points, var ar = this.points,
ln = ar.length, ln = ar.length,
i = 0; i = 0;
@ -368,7 +368,7 @@ var gs_base_polygon = exports;
/** /**
* @returns {number} z value of first point * @returns {number} z value of first point
*/ */
PlP.getZ = function() { PRO.getZ = function() {
return this.points[0].z; return this.points[0].z;
}; };
@ -379,7 +379,7 @@ var gs_base_polygon = exports;
* @param {boolean} [recursive] * @param {boolean} [recursive]
* @param {boolean} [open] * @param {boolean} [open]
*/ */
PlP.render = function(layer, color, recursive, open) { PRO.render = function(layer, color, recursive, open) {
layer.poly(this, color, recursive, open); layer.poly(this, color, recursive, open);
}; };
@ -391,7 +391,7 @@ var gs_base_polygon = exports;
* @param {number} [z] * @param {number} [z]
* @returns {Polygon} * @returns {Polygon}
*/ */
PlP.add = function(x,y,z) { PRO.add = function(x,y,z) {
this.push(newPoint(x,y,z)); this.push(newPoint(x,y,z));
return this; return this;
}; };
@ -402,7 +402,7 @@ var gs_base_polygon = exports;
* @param {Point[]} points * @param {Point[]} points
* @returns {Polygon} * @returns {Polygon}
*/ */
PlP.addPoints = function(points) { PRO.addPoints = function(points) {
var poly = this, var poly = this,
length = points.length, length = points.length,
i = 0; i = 0;
@ -418,7 +418,7 @@ var gs_base_polygon = exports;
* @param {Point} p * @param {Point} p
* @returns {Point} * @returns {Point}
*/ */
PlP.push = function(p) { PRO.push = function(p) {
// 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;
@ -434,46 +434,46 @@ var gs_base_polygon = exports;
* @param {Point} p * @param {Point} p
* @returns {Polygon} * @returns {Polygon}
*/ */
PlP.append = function(p) { PRO.append = function(p) {
this.push(p); this.push(p);
return this; return this;
}; };
/** close polygon */ /** close polygon */
PlP.setClosed = function() { PRO.setClosed = function() {
this.open = false; this.open = false;
return this; return this;
}; };
/** open polygon */ /** open polygon */
PlP.setOpen = function() { PRO.setOpen = function() {
this.open = true; this.open = true;
return this; return this;
}; };
PlP.isOpen = function() { PRO.isOpen = function() {
return this.open; return this.open;
}; };
PlP.isClosed = function() { PRO.isClosed = function() {
return !this.open; return !this.open;
}; };
PlP.setClockwise = function() { PRO.setClockwise = function() {
if (!this.isClockwise()) this.reverse(); if (!this.isClockwise()) this.reverse();
return this; return this;
}; };
PlP.setCounterClockwise = function() { PRO.setCounterClockwise = function() {
if (this.isClockwise()) this.reverse(); if (this.isClockwise()) this.reverse();
return this; return this;
}; };
PlP.isClockwise = function() { PRO.isClockwise = function() {
return this.area(true) > 0; return this.area(true) > 0;
}; };
PlP.showKey = function() { PRO.showKey = function() {
return [this.first().key,this.last().key,this.length].join('~~'); return [this.first().key,this.last().key,this.length].join('~~');
}; };
@ -484,7 +484,7 @@ var gs_base_polygon = exports;
* @param [boolean] toLongest * @param [boolean] toLongest
* @returns {Polygon} self * @returns {Polygon} self
*/ */
PlP.alignWinding = function(poly, toLongest) { PRO.alignWinding = function(poly, toLongest) {
if (toLongest && this.length > poly.length) { if (toLongest && this.length > poly.length) {
poly.alignWinding(this, false); poly.alignWinding(this, false);
} else if (this.isClockwise() !== poly.isClockwise()) { } else if (this.isClockwise() !== poly.isClockwise()) {
@ -499,7 +499,7 @@ var gs_base_polygon = exports;
* @param [boolean] toLongest * @param [boolean] toLongest
* @returns {Polygon} self * @returns {Polygon} self
*/ */
PlP.opposeWinding = function(poly, toLongest) { PRO.opposeWinding = function(poly, toLongest) {
if (toLongest && this.length > poly.length) { if (toLongest && this.length > poly.length) {
poly.opposeWinding(this, false); poly.opposeWinding(this, false);
} else if (this.isClockwise() === poly.isClockwise()) { } else if (this.isClockwise() === poly.isClockwise()) {
@ -511,7 +511,7 @@ var gs_base_polygon = exports;
* reverse direction of polygon points. * reverse direction of polygon points.
* @returns {Polygon} self * @returns {Polygon} self
*/ */
PlP.reverse = function() { PRO.reverse = function() {
this.area2 = -this.area2; this.area2 = -this.area2;
this.points = this.points.reverse(); this.points = this.points.reverse();
return this; return this;
@ -523,7 +523,7 @@ var gs_base_polygon = exports;
* @param {Polygon} parent * @param {Polygon} parent
* @returns {boolean} * @returns {boolean}
*/ */
PlP.isNested = function(parent) { PRO.isNested = function(parent) {
if (parent.bounds.contains(this.bounds)) { if (parent.bounds.contains(this.bounds)) {
//var int = POLY().rayIntersect(this.bounds.leftMost, nest_test_slope, [parent], false); //var int = POLY().rayIntersect(this.bounds.leftMost, nest_test_slope, [parent], false);
//return int.length % 2 === 1 || this.isInside(parent, CONF.precision_nested_sq); //return int.length % 2 === 1 || this.isInside(parent, CONF.precision_nested_sq);
@ -532,7 +532,7 @@ var gs_base_polygon = exports;
return false; return false;
}; };
PlP.forEachPointEaseDown = function(fn, fromPoint) { PRO.forEachPointEaseDown = function(fn, fromPoint) {
var index = this.findClosestPointTo(fromPoint).index, var index = this.findClosestPointTo(fromPoint).index,
fromZ = fromPoint.z, fromZ = fromPoint.z,
offset = 0, offset = 0,
@ -573,7 +573,7 @@ var gs_base_polygon = exports;
return last; return last;
}; };
PlP.forEachPoint = function(fn, close, start) { PRO.forEachPoint = function(fn, close, start) {
var index = start || 0, var index = start || 0,
points = this.points, points = this.points,
length = points.length, length = points.length,
@ -588,7 +588,7 @@ var gs_base_polygon = exports;
} }
}; };
PlP.forEachSegment = function(fn, open, start) { PRO.forEachSegment = function(fn, open, start) {
var index = start || 0, var index = start || 0,
points = this.points, points = this.points,
length = points.length, length = points.length,
@ -606,7 +606,7 @@ var gs_base_polygon = exports;
/** /**
* returns intersections sorted by closest to lp1 * returns intersections sorted by closest to lp1
*/ */
PlP.intersections = function(lp1, lp2) { PRO.intersections = function(lp1, lp2) {
var list = []; var list = [];
this.forEachSegment(function(pp1, pp2, ip1, ip2) { this.forEachSegment(function(pp1, pp2, ip1, ip2) {
var int = UTIL.intersect(lp1, lp2, pp1, pp2, BASE.key.SEGINT, false); var int = UTIL.intersect(lp1, lp2, pp1, pp2, BASE.key.SEGINT, false);
@ -625,7 +625,7 @@ var gs_base_polygon = exports;
/** /**
* emit new open poly between two intersection points * emit new open poly between two intersection points
*/ */
PlP.emitSegment = function(i1, i2) { PRO.emitSegment = function(i1, i2) {
var poly = newPolygon(), var poly = newPolygon(),
start = i1.p2.pos, start = i1.p2.pos,
end = i2.p1.pos, end = i2.p1.pos,
@ -648,7 +648,7 @@ var gs_base_polygon = exports;
* @param {number} [tolerance] * @param {number} [tolerance]
* @returns {boolean} any points inside OR on edge * @returns {boolean} any points inside OR on edge
*/ */
PlP.hasPointsInside = function(poly, tolerance) { PRO.hasPointsInside = function(poly, tolerance) {
if (!poly.overlaps(this)) return false; if (!poly.overlaps(this)) return false;
var mid, exit = false; var mid, exit = false;
@ -676,7 +676,7 @@ var gs_base_polygon = exports;
* @param {number} [tolerance] * @param {number} [tolerance]
* @returns {boolean} all points inside OR on edge * @returns {boolean} all points inside OR on edge
*/ */
PlP.isInside = function(poly, tolerance) { PRO.isInside = function(poly, tolerance) {
// throw new Error("isInside"); // throw new Error("isInside");
if (!( if (!(
// poly.overlaps(this) && // poly.overlaps(this) &&
@ -710,7 +710,7 @@ var gs_base_polygon = exports;
* @param {number} [tolerance] * @param {number} [tolerance]
* @returns {boolean} all points inside poly AND not inside children * @returns {boolean} all points inside poly AND not inside children
*/ */
PlP.contains = function(poly, tolerance) { PRO.contains = function(poly, tolerance) {
return (poly && poly.isInside(this, tolerance) && poly.isOutsideAll(this.inner, tolerance)); return (poly && poly.isInside(this, tolerance) && poly.isOutsideAll(this.inner, tolerance));
}; };
@ -719,7 +719,7 @@ var gs_base_polygon = exports;
* @param polys * @param polys
* @returns {boolean} * @returns {boolean}
*/ */
PlP.containedBySet = function(polys) { PRO.containedBySet = function(polys) {
if (!polys) return false; if (!polys) return false;
for (var i=0; i<polys.length; i++) { for (var i=0; i<polys.length; i++) {
if (polys[i].contains(this)) return true; if (polys[i].contains(this)) return true;
@ -731,7 +731,7 @@ var gs_base_polygon = exports;
* @param {Polygon} child * @param {Polygon} child
* @returns {Polygon} self * @returns {Polygon} self
*/ */
PlP.addInner = function(child) { PRO.addInner = function(child) {
child.parent = this; child.parent = this;
if (this.inner) { if (this.inner) {
this.inner.push(child); this.inner.push(child);
@ -744,14 +744,14 @@ var gs_base_polygon = exports;
/** /**
* @returns {number} number of inner polygons * @returns {number} number of inner polygons
*/ */
PlP.innerCount = function() { PRO.innerCount = function() {
return this.inner ? this.inner.length : 0; return this.inner ? this.inner.length : 0;
}; };
/** /**
* @returns {boolean} if has 1 or more inner polygons * @returns {boolean} if has 1 or more inner polygons
*/ */
PlP.hasInner = function() { PRO.hasInner = function() {
return this.inner && this.inner.length > 0; return this.inner && this.inner.length > 0;
}; };
@ -759,12 +759,12 @@ var gs_base_polygon = exports;
* remove all inner polygons * remove all inner polygons
* @returns {Polygon} self * @returns {Polygon} self
*/ */
PlP.clearInner = function() { PRO.clearInner = function() {
this.inner = null; this.inner = null;
return this; return this;
}; };
PlP.newUndeleted = function() { PRO.newUndeleted = function() {
var poly = newPolygon(); var poly = newPolygon();
this.forEachPoint(function(p) { this.forEachPoint(function(p) {
if (!p.del) poly.push(p); if (!p.del) poly.push(p);
@ -776,18 +776,18 @@ var gs_base_polygon = exports;
* http://www.ehow.com/how_5138742_calculate-circularity.html * http://www.ehow.com/how_5138742_calculate-circularity.html
* @returns {number} 0.0 - 1.0 from flat to perfectly circular * @returns {number} 0.0 - 1.0 from flat to perfectly circular
*/ */
PlP.circularity = function() { PRO.circularity = function() {
return (4 * PI * this.area()) / UTIL.sqr(this.perimeter()); return (4 * PI * this.area()) / UTIL.sqr(this.perimeter());
}; };
PlP.circularityDeep = function() { PRO.circularityDeep = function() {
return (4 * PI * this.areaDeep()) / UTIL.sqr(this.perimeter()); return (4 * PI * this.areaDeep()) / UTIL.sqr(this.perimeter());
}; };
/** /**
* @returns {number} perimeter length (sum of all segment lengths) * @returns {number} perimeter length (sum of all segment lengths)
*/ */
PlP.perimeter = function() { PRO.perimeter = function() {
var len = 0.0; var len = 0.0;
this.forEachSegment(function(prev,next) { this.forEachSegment(function(prev,next) {
@ -797,7 +797,7 @@ var gs_base_polygon = exports;
return len; return len;
}; };
PlP.perimeterDeep = function() { PRO.perimeterDeep = function() {
var len = this.perimeter(); var len = this.perimeter();
if (this.inner) this.inner.forEach(function(p) { len += p.perimeter() }); if (this.inner) this.inner.forEach(function(p) { len += p.perimeter() });
return len; return len;
@ -811,7 +811,7 @@ var gs_base_polygon = exports;
* @param {boolean} [raw] * @param {boolean} [raw]
* @returns {number} area * @returns {number} area
*/ */
PlP.area = function(raw) { PRO.area = function(raw) {
if (this.length < 3) return 0; if (this.length < 3) return 0;
if (this.area2 === 0.0) { if (this.area2 === 0.0) {
for (var p=this.points,pl=p.length,pi=0,p1,p2; pi<pl; pi++) { for (var p=this.points,pl=p.length,pi=0,p1,p2; pi<pl; pi++) {
@ -829,7 +829,7 @@ var gs_base_polygon = exports;
* *
* @returns {number} area * @returns {number} area
*/ */
PlP.areaDeep = function() { PRO.areaDeep = function() {
if (!this.inner) return this.area(); if (!this.inner) return this.area();
var i, c = this.inner, a = this.area(); var i, c = this.inner, a = this.area();
for (i=0; i<c.length; i++) { for (i=0; i<c.length; i++) {
@ -842,7 +842,7 @@ var gs_base_polygon = exports;
* @param {Polygon} poly * @param {Polygon} poly
* @returns {boolean} * @returns {boolean}
*/ */
PlP.overlaps = function(poly) { PRO.overlaps = function(poly) {
return this.bounds.overlaps(poly.bounds, CONF.precision_merge); return this.bounds.overlaps(poly.bounds, CONF.precision_merge);
}; };
@ -852,7 +852,7 @@ var gs_base_polygon = exports;
* @param {number[]} arr * @param {number[]} arr
* @param {number} [z] * @param {number} [z]
*/ */
PlP.fromXYArray = function(arr,z) { PRO.fromXYArray = function(arr,z) {
var i = 0; var i = 0;
while (i < arr.length) { while (i < arr.length) {
this.add(arr[i++], arr[i++], z || 0); this.add(arr[i++], arr[i++], z || 0);
@ -870,7 +870,7 @@ var gs_base_polygon = exports;
* simplify and merge collinear. only works for single * simplify and merge collinear. only works for single
* non-nested polygons. used primarily in slicer/connectLines. * non-nested polygons. used primarily in slicer/connectLines.
*/ */
PlP.clean = function() { PRO.clean = function() {
var clib = self.ClipperLib, var clib = self.ClipperLib,
clip = clib.Clipper, clip = clib.Clipper,
clean = clip.CleanPolygon(this.toClipper()[0], CONF.clipperClean), clean = clip.CleanPolygon(this.toClipper()[0], CONF.clipperClean),
@ -878,7 +878,7 @@ var gs_base_polygon = exports;
return poly; return poly;
}; };
PlP.toClipper = function(inout,debug) { PRO.toClipper = function(inout,debug) {
var poly = this, var poly = this,
cur = [], cur = [],
out = inout || []; out = inout || [];
@ -908,7 +908,7 @@ var gs_base_polygon = exports;
/** /**
* todo for debugging * todo for debugging
*/ */
PlP.dump = function(msg,prec) { PRO.dump = function(msg,prec) {
var scope = this, var scope = this,
txt = [JSON.stringify({ txt = [JSON.stringify({
len:scope.length, len:scope.length,
@ -941,7 +941,7 @@ var gs_base_polygon = exports;
* @param {Polygon[]} [output] * @param {Polygon[]} [output]
* @returns {?Polygon[]} returns output array provided as input or new array if not provided * @returns {?Polygon[]} returns output array provided as input or new array if not provided
*/ */
PlP.offset = function(offset, output) { PRO.offset = function(offset, output) {
return POLY().expand([this], -offset, this.getZ(), output); return POLY().expand([this], -offset, this.getZ(), output);
}; };
@ -954,7 +954,7 @@ var gs_base_polygon = exports;
* @param {number} [precision] * @param {number} [precision]
* @returns {boolean} true if polygons are, essentially, the same * @returns {boolean} true if polygons are, essentially, the same
*/ */
PlP.isEquivalent = function(poly, recurse, precision) { PRO.isEquivalent = function(poly, recurse, precision) {
// throw new Error("isEquivalent"); // throw new Error("isEquivalent");
var debug = DBUG.get('circularity'); var debug = DBUG.get('circularity');
if (debug) { if (debug) {
@ -1023,7 +1023,7 @@ var gs_base_polygon = exports;
* @param {Point} target * @param {Point} target
* @return {Object} {point:point, distance:distance} * @return {Object} {point:point, distance:distance}
*/ */
PlP.findClosestPointTo = function(target) { PRO.findClosestPointTo = function(target) {
var dist, var dist,
index, index,
closest, closest,
@ -1045,7 +1045,7 @@ var gs_base_polygon = exports;
* @param {Polygon[]} out * @param {Polygon[]} out
* @returns {Polygon[]} * @returns {Polygon[]}
*/ */
PlP.flattenTo = function(out) { PRO.flattenTo = function(out) {
out.push(this); out.push(this);
if (this.inner) out.appendAll(this.inner); if (this.inner) out.appendAll(this.inner);
return out; return out;
@ -1055,7 +1055,7 @@ var gs_base_polygon = exports;
* @param {Polygon} poly clipping mask * @param {Polygon} poly clipping mask
* @returns {?Polygon[]} * @returns {?Polygon[]}
*/ */
PlP.diff = function(poly) { PRO.diff = function(poly) {
var fillang = this.fillang && this.area() > poly.area() ? this.fillang : poly.fillang, var fillang = this.fillang && this.area() > poly.area() ? this.fillang : poly.fillang,
clib = self.ClipperLib, clib = self.ClipperLib,
ctyp = clib.ClipType, ctyp = clib.ClipType,
@ -1084,7 +1084,7 @@ var gs_base_polygon = exports;
* @param {Polygon} poly clipping mask * @param {Polygon} poly clipping mask
* @returns {?Polygon[]} * @returns {?Polygon[]}
*/ */
PlP.mask = function(poly) { PRO.mask = function(poly) {
var fillang = this.fillang && this.area() > poly.area() ? this.fillang : poly.fillang, var fillang = this.fillang && this.area() > poly.area() ? this.fillang : poly.fillang,
clib = self.ClipperLib, clib = self.ClipperLib,
ctyp = clib.ClipType, ctyp = clib.ClipType,
@ -1115,7 +1115,7 @@ var gs_base_polygon = exports;
* @param {Polygon} poly * @param {Polygon} poly
* @returns {?Polygon} intersected polygon or null if no intersection * @returns {?Polygon} intersected polygon or null if no intersection
*/ */
PlP.union = function(poly) { PRO.union = function(poly) {
if (!this.overlaps(poly)) return null; if (!this.overlaps(poly)) return null;
var fillang = this.fillang && this.area() > poly.area() ? this.fillang : poly.fillang, var fillang = this.fillang && this.area() > poly.area() ? this.fillang : poly.fillang,
@ -1147,7 +1147,7 @@ var gs_base_polygon = exports;
* rotate such that first and last points are the points * rotate such that first and last points are the points
* furthest apart and lowest when there is a tie breaker * furthest apart and lowest when there is a tie breaker
*/ */
PlP.spread = function() { PRO.spread = function() {
var poly = this, var poly = this,
points = poly.points, points = poly.points,
plen = points.length, plen = points.length,

View file

@ -26,7 +26,7 @@ var gs_base_slope = exports;
var BASE = self.base, var BASE = self.base,
CONF = BASE.config, CONF = BASE.config,
ABS = Math.abs, ABS = Math.abs,
SlP = Slope.prototype, PRO = Slope.prototype,
DEG2RAD = Math.PI / 180, DEG2RAD = Math.PI / 180,
RAD2DEG = 180 / Math.PI; RAD2DEG = 180 / Math.PI;
@ -44,7 +44,7 @@ var gs_base_slope = exports;
* Slope Prototype Functions * Slope Prototype Functions
******************************************************************* */ ******************************************************************* */
SlP.toString = function() { PRO.toString = function() {
return [this.dx, this.dy, this.angle].join(','); return [this.dx, this.dy, this.angle].join(',');
}; };
@ -52,7 +52,7 @@ var gs_base_slope = exports;
* @param {Slope} s * @param {Slope} s
* @returns {boolean} * @returns {boolean}
*/ */
SlP.isSame = function(s) { PRO.isSame = function(s) {
// if very close to vertical or horizontal, they're the same // if very close to vertical or horizontal, they're the same
if (ABS(this.dx) <= CONF.precision_merge && ABS(s.dx) <= CONF.precision_merge) return true; if (ABS(this.dx) <= CONF.precision_merge && ABS(s.dx) <= CONF.precision_merge) return true;
if (ABS(this.dy) <= CONF.precision_merge && ABS(s.dy) <= CONF.precision_merge) return true; if (ABS(this.dy) <= CONF.precision_merge && ABS(s.dy) <= CONF.precision_merge) return true;
@ -66,7 +66,7 @@ var gs_base_slope = exports;
* *
* @returns {Slope} * @returns {Slope}
*/ */
SlP.normal = function() { PRO.normal = function() {
var t = this.dx; var t = this.dx;
this.dx = -this.dy; this.dx = -this.dy;
this.dy = t; this.dy = t;
@ -74,14 +74,14 @@ var gs_base_slope = exports;
return this; return this;
}; };
SlP.toUnit = function() { PRO.toUnit = function() {
var max = Math.max(ABS(this.dx), ABS(this.dy)); var max = Math.max(ABS(this.dx), ABS(this.dy));
this.dx = this.dx / max; this.dx = this.dx / max;
this.dy = this.dy / max; this.dy = this.dy / max;
return this; return this;
}; };
SlP.factor = function(f) { PRO.factor = function(f) {
this.dx *= f; this.dx *= f;
this.dy *= f; this.dy *= f;
return this; return this;
@ -92,7 +92,7 @@ var gs_base_slope = exports;
* *
* @returns {Slope} * @returns {Slope}
*/ */
SlP.invert = function() { PRO.invert = function() {
this.dx = -this.dx; this.dx = -this.dx;
this.dy = -this.dy; this.dy = -this.dy;
this.angle = 360 - this.angle;//Math.atan2(this.dy, this.dx) * RAD2DEG; this.angle = 360 - this.angle;//Math.atan2(this.dy, this.dx) * RAD2DEG;

View file

@ -10,7 +10,6 @@ var gs_base = exports;
if (self.base.util) return; if (self.base.util) return;
var BASE = self.base, var BASE = self.base,
ABS = Math.abs,
round_decimal_precision = 8; round_decimal_precision = 8;
/** ****************************************************************** /** ******************************************************************
@ -93,7 +92,7 @@ var gs_base = exports;
* @returns {boolean} * @returns {boolean}
*/ */
function isCloseTo(v1,v2,dist) { function isCloseTo(v1,v2,dist) {
return ABS(v1-v2) <= (dist || BASE.config.precision_merge); return Math.abs(v1-v2) <= (dist || BASE.config.precision_merge);
} }
/** /**
@ -141,7 +140,7 @@ var gs_base = exports;
* @returns {number} * @returns {number}
*/ */
function offsetPrecision(offset, precision) { function offsetPrecision(offset, precision) {
return ABS(offset) - precision; return Math.abs(offset) - precision;
} }
/** /**
@ -194,8 +193,8 @@ var gs_base = exports;
d2y = (p4y - p3y), // bd.y d2y = (p4y - p3y), // bd.y
d = (d2y * d1x) - (d2x * d1y); // det d = (d2y * d1x) - (d2x * d1y); // det
//if (ABS(d) < 0.0000000001) { //if (Math.abs(d) < 0.0000000001) {
if (ABS(d) < 0.0001) { if (Math.abs(d) < 0.0001) {
// lines are parallel or collinear // lines are parallel or collinear
return test && !parallelok ? null : keys.PARALLEL; return test && !parallelok ? null : keys.PARALLEL;
} }
@ -259,7 +258,7 @@ var gs_base = exports;
n1 = (s2x * a) - (s2y * b), n1 = (s2x * a) - (s2y * b),
n2 = (s1x * a) - (s1y * b); n2 = (s1x * a) - (s1y * b);
if (ABS(d) < 0.000000000001) { if (Math.abs(d) < 0.000000000001) {
// lines are parallel or collinear // lines are parallel or collinear
return null; return null;
} }

View file

@ -365,7 +365,7 @@ var gs_kiri_fdm = exports;
// for flashforge finder that uses cumulative extruder position // for flashforge finder that uses cumulative extruder position
o.append(" E").append(UTIL.round(outputLength, decimals)); o.append(" E").append(UTIL.round(outputLength, decimals));
} else { } else {
o.append(" E").append(UTIL.round(newpos.e,decimals)); o.append(" E").append(UTIL.round(newpos.e, decimals));
} }
} }
if (rate && rate != pos.f) { if (rate && rate != pos.f) {

View file

@ -19,7 +19,7 @@ var gs_kiri_print = exports;
POLY = BASE.polygons, POLY = BASE.polygons,
SQRT = Math.sqrt, SQRT = Math.sqrt,
PI = Math.PI, PI = Math.PI,
PROTO = Print.prototype, PRO = Print.prototype,
Polygon = BASE.Polygon, Polygon = BASE.Polygon,
newPoint = BASE.newPoint; newPoint = BASE.newPoint;
@ -46,15 +46,15 @@ var gs_kiri_print = exports;
this.bounds = null; this.bounds = null;
} }
PROTO.newOut = newOut; PRO.newOut = newOut;
PROTO.tip2tipEmit = tip2tipEmit; PRO.tip2tipEmit = tip2tipEmit;
PROTO.extrudePerMM = extrudePerMM; PRO.extrudePerMM = extrudePerMM;
PROTO.constReplace = constReplace; PRO.constReplace = constReplace;
PROTO.poly2polyEmit = poly2polyEmit; PRO.poly2polyEmit = poly2polyEmit;
PROTO.addPrintPoints = addPrintPoints; PRO.addPrintPoints = addPrintPoints;
PROTO.poly2polyDepthFirstEmit = poly2polyDepthFirstEmit; PRO.poly2polyDepthFirstEmit = poly2polyDepthFirstEmit;
PROTO.parseGCode = function(gcode, offset) { PRO.parseGCode = function(gcode, offset) {
var lines = gcode var lines = gcode
.toUpperCase() .toUpperCase()
.replace("X", " X") .replace("X", " X")
@ -136,7 +136,7 @@ var gs_kiri_print = exports;
scope.bytes = gcode.length; scope.bytes = gcode.length;
}; };
PROTO.setup = function(remote, onupdate, ondone) { PRO.setup = function(remote, onupdate, ondone) {
var scope = this, var scope = this,
settings = scope.settings, settings = scope.settings,
mode = settings.mode; mode = settings.mode;
@ -158,7 +158,7 @@ var gs_kiri_print = exports;
} }
}; };
PROTO.exportGCode = function(remote, ondone, online) { PRO.exportGCode = function(remote, ondone, online) {
var scope = this, var scope = this,
settings = scope.settings, settings = scope.settings,
mode = settings.mode; mode = settings.mode;
@ -184,19 +184,19 @@ var gs_kiri_print = exports;
} }
}; };
PROTO.exportLaserGCode = function() { PRO.exportLaserGCode = function() {
return KIRI.driver.LASER.exportGCode(this); return KIRI.driver.LASER.exportGCode(this);
}; };
PROTO.exportSVG = function() { PRO.exportSVG = function() {
return KIRI.driver.LASER.exportSVG(this); return KIRI.driver.LASER.exportSVG(this);
}; };
PROTO.exportDXF = function() { PRO.exportDXF = function() {
return KIRI.driver.LASER.exportDXF(this); return KIRI.driver.LASER.exportDXF(this);
}; };
PROTO.encodeOutput = function() { PRO.encodeOutput = function() {
var newout = [], newlayer; var newout = [], newlayer;
this.output.forEach(function(layerout) { this.output.forEach(function(layerout) {
@ -209,7 +209,7 @@ var gs_kiri_print = exports;
return newout; return newout;
}; };
PROTO.render = function() { PRO.render = function() {
var scope = this, var scope = this,
mode = scope.settings.mode; mode = scope.settings.mode;
@ -224,7 +224,7 @@ var gs_kiri_print = exports;
} }
}; };
PROTO.renderMoves = function(showMoves, moveColor) { PRO.renderMoves = function(showMoves, moveColor) {
var scope = this, last, view; var scope = this, last, view;
// render layered output // render layered output
scope.lines = 0; scope.lines = 0;
@ -257,17 +257,17 @@ var gs_kiri_print = exports;
}); });
} }
PROTO.getLayerCount = function() { PRO.getLayerCount = function() {
return this.output.length; return this.output.length;
} }
PROTO.hide = function() { PRO.hide = function() {
this.layerView.forEach(function(layer) { this.layerView.forEach(function(layer) {
layer.setVisible(false); layer.setVisible(false);
}) })
}; };
PROTO.showLayer = function(index, show) { PRO.showLayer = function(index, show) {
if (this.layerView[index]) this.layerView[index].setVisible(show); if (this.layerView[index]) this.layerView[index].setVisible(show);
}; };
@ -300,7 +300,7 @@ var gs_kiri_print = exports;
* @param {number} [extrude] wipe distance * @param {number} [extrude] wipe distance
* @return {Point} last output point * @return {Point} last output point
*/ */
PROTO.polyPrintPath = function(poly, startPoint, output, extrude, wipe) { PRO.polyPrintPath = function(poly, startPoint, output, extrude, wipe) {
// poly.setClosed(); // poly.setClosed();
poly.setClockwise(); poly.setClockwise();
@ -350,7 +350,7 @@ var gs_kiri_print = exports;
* @param {boolean} isFDM controls whether we emit wipe or not * @param {boolean} isFDM controls whether we emit wipe or not
* @return {Point} last output point * @return {Point} last output point
*/ */
PROTO.slicePrintPath = function(slice, startPoint, offset, output, isFDM) { PRO.slicePrintPath = function(slice, startPoint, offset, output, isFDM) {
var i, var i,
preout = [], preout = [],
scope = this, scope = this,

View file

@ -14,7 +14,7 @@ var gs_kiri_slice = exports;
UTIL = BASE.util, UTIL = BASE.util,
DBUG = BASE.debug, DBUG = BASE.debug,
POLY = BASE.polygons, POLY = BASE.polygons,
SiP = Slice.prototype, PRO = Slice.prototype,
fillArea = POLY.fillArea, fillArea = POLY.fillArea,
newPoint = BASE.newPoint, newPoint = BASE.newPoint,
ROUND = UTIL.round, ROUND = UTIL.round,
@ -116,7 +116,7 @@ var gs_kiri_slice = exports;
/** /**
* returns a cloned slice the option of a deep clone on the top polys * returns a cloned slice the option of a deep clone on the top polys
*/ */
SiP.clone = function(deep) { PRO.clone = function(deep) {
var from = this, var from = this,
slice = newSlice(from.z, from.view); slice = newSlice(from.z, from.view);
from.tops.forEach(function(top) { from.tops.forEach(function(top) {
@ -130,7 +130,7 @@ var gs_kiri_slice = exports;
* *
* @param {THREE.Group} view * @param {THREE.Group} view
*/ */
SiP.addLayers = function(view) { PRO.addLayers = function(view) {
if (this.layers) return; if (this.layers) return;
// create views client side only // create views client side only
@ -154,7 +154,7 @@ var gs_kiri_slice = exports;
* *
* @param {Polygon} poly to merge into a top * @param {Polygon} poly to merge into a top
*/ */
SiP.mergeTop = function(poly) { PRO.mergeTop = function(poly) {
var scope = this, var scope = this,
tops = scope.tops, tops = scope.tops,
union, i; union, i;
@ -172,7 +172,7 @@ var gs_kiri_slice = exports;
* *
* @param {Polygon} poly to add * @param {Polygon} poly to add
*/ */
SiP.addTop = function(poly) { PRO.addTop = function(poly) {
var top = new Top(poly); var top = new Top(poly);
this.tops.push(top); this.tops.push(top);
return top; return top;
@ -184,7 +184,7 @@ var gs_kiri_slice = exports;
* @param {Polygon[]} out array to populate * @param {Polygon[]} out array to populate
* @returns {Polygon[]} array of top polygons * @returns {Polygon[]} array of top polygons
*/ */
SiP.gatherTopPolys = function(out) { PRO.gatherTopPolys = function(out) {
this.tops.forEach(function(top) { this.tops.forEach(function(top) {
out.push(top.poly); out.push(top.poly);
}); });
@ -198,7 +198,7 @@ var gs_kiri_slice = exports;
* @param {Polygon[]} out array to populate * @param {Polygon[]} out array to populate
* @returns {Polygon[]} array of top polygons * @returns {Polygon[]} array of top polygons
*/ */
SiP.gatherTopPolyInners = function(out) { PRO.gatherTopPolyInners = function(out) {
this.tops.forEach(function(top) { this.tops.forEach(function(top) {
if (top.poly.inner) out.appendAll(top.poly.inner); if (top.poly.inner) out.appendAll(top.poly.inner);
}); });
@ -211,7 +211,7 @@ var gs_kiri_slice = exports;
* @param {Polygon[]} out array to populate * @param {Polygon[]} out array to populate
* @returns {Polygon[]} array of top polygons * @returns {Polygon[]} array of top polygons
*/ */
SiP.gatherTraces = function(out) { PRO.gatherTraces = function(out) {
this.tops.forEach(function(top) { this.tops.forEach(function(top) {
out.appendAll(top.traces); out.appendAll(top.traces);
}); });
@ -224,7 +224,7 @@ var gs_kiri_slice = exports;
* @param {Polygon[]} out array to populate * @param {Polygon[]} out array to populate
* @returns {Polygon[]} array of top polygons * @returns {Polygon[]} array of top polygons
*/ */
SiP.gatherInner = function(out) { PRO.gatherInner = function(out) {
this.tops.forEach(function(top) { this.tops.forEach(function(top) {
out.appendAll(top.inner); out.appendAll(top.inner);
}); });
@ -237,7 +237,7 @@ var gs_kiri_slice = exports;
* @param {Polygon[]} out array to populate * @param {Polygon[]} out array to populate
* @returns {Polygon[]} array of top polygons * @returns {Polygon[]} array of top polygons
*/ */
SiP.gatherOuter = function(out) { PRO.gatherOuter = function(out) {
this.tops.forEach(function(top) { this.tops.forEach(function(top) {
out.appendAll(top.outer); out.appendAll(top.outer);
}); });
@ -250,7 +250,7 @@ var gs_kiri_slice = exports;
* @param {Polygon[]} out array to populate * @param {Polygon[]} out array to populate
* @returns {Polygon[]} array of top polygons * @returns {Polygon[]} array of top polygons
*/ */
SiP.gatherSolids = function(out) { PRO.gatherSolids = function(out) {
this.tops.forEach(function(top) { this.tops.forEach(function(top) {
out.appendAll(top.solids); out.appendAll(top.solids);
}); });
@ -263,7 +263,7 @@ var gs_kiri_slice = exports;
* *
* @param {Point[]} [lines] array to append to * @param {Point[]} [lines] array to append to
*/ */
SiP.gatherFillLines = function(lines) { PRO.gatherFillLines = function(lines) {
this.tops.forEach(function(top) { this.tops.forEach(function(top) {
if (top.fill_lines) lines.appendAll(top.fill_lines); if (top.fill_lines) lines.appendAll(top.fill_lines);
}); });
@ -273,7 +273,7 @@ var gs_kiri_slice = exports;
/** /**
* Clear solid area cache in preparation for a new slicing action * Clear solid area cache in preparation for a new slicing action
*/ */
SiP.invalidateSolids = function() { PRO.invalidateSolids = function() {
var solids = this.solids; var solids = this.solids;
solids.poly = []; solids.poly = [];
solids.trimmed = null; solids.trimmed = null;
@ -282,7 +282,7 @@ var gs_kiri_slice = exports;
/** /**
* Clear support cache in preparation for a new slicing calculation * Clear support cache in preparation for a new slicing calculation
*/ */
SiP.invalidateSupports = function() { PRO.invalidateSupports = function() {
this.supports = null; this.supports = null;
}; };
@ -291,7 +291,7 @@ var gs_kiri_slice = exports;
* *
* @param {number} renderMode * @param {number} renderMode
*/ */
SiP.renderOutline = function(renderMode) { PRO.renderOutline = function(renderMode) {
if (!this.view) return; if (!this.view) return;
var process = KIRI.driver.CAM.process, var process = KIRI.driver.CAM.process,
@ -362,7 +362,7 @@ var gs_kiri_slice = exports;
* @param {number} offsetN all subsequent offsets * @param {number} offsetN all subsequent offsets
* @param {number} fillOffset * @param {number} fillOffset
*/ */
SiP.doShells = function(count, offset1, offsetN, fillOffset, vase) { PRO.doShells = function(count, offset1, offsetN, fillOffset, vase) {
var slice = this; var slice = this;
slice.tops.forEach(function(top) { slice.tops.forEach(function(top) {
@ -398,7 +398,7 @@ var gs_kiri_slice = exports;
* *
* @param {number} renderMode * @param {number} renderMode
*/ */
SiP.renderShells = function(renderMode) { PRO.renderShells = function(renderMode) {
var scope = this, var scope = this,
layers = scope.layers, layers = scope.layers,
layer = layers.trace, layer = layers.trace,
@ -440,7 +440,7 @@ var gs_kiri_slice = exports;
/** /**
* Clear fill cache in preparation for a slice or re-slice of a widget * Clear fill cache in preparation for a slice or re-slice of a widget
*/ */
SiP.invalidateFill = function() { PRO.invalidateFill = function() {
this.tops.forEach(function(top) { this.tops.forEach(function(top) {
top.fill_lines = null; top.fill_lines = null;
top.fill_sparse = null; top.fill_sparse = null;
@ -452,7 +452,7 @@ var gs_kiri_slice = exports;
* *
* @param {number} minDist * @param {number} minDist
*/ */
SiP.doThinWallDetection = function(mindist) { PRO.doThinWallDetection = function(mindist) {
this.tops.forEach(function(top) { this.tops.forEach(function(top) {
if (top.inner && top.inner.length > 0) { if (top.inner && top.inner.length > 0) {
// using next line2line algo from print lib // using next line2line algo from print lib
@ -468,7 +468,7 @@ var gs_kiri_slice = exports;
* @param {number} angle * @param {number} angle
* @param {number} density * @param {number} density
*/ */
SiP.doSolidLayerFill = function(linewidth, angle, density) { PRO.doSolidLayerFill = function(linewidth, angle, density) {
this.isSolidFill = false; this.isSolidFill = false;
if (this.tops.length === 0) return; if (this.tops.length === 0) return;
@ -493,7 +493,7 @@ var gs_kiri_slice = exports;
/** /**
* Runs in client. Generate solid lines in the correct view layer. * Runs in client. Generate solid lines in the correct view layer.
*/ */
SiP.renderSolidFill = function() { PRO.renderSolidFill = function() {
var layer = this.layers.fill, var layer = this.layers.fill,
render; render;
@ -515,7 +515,7 @@ var gs_kiri_slice = exports;
* @param {number} percent infill 0.0 - 1.0 * @param {number} percent infill 0.0 - 1.0
* @param {Object} bounds -- TODO calc w/out mesh so it can run in a worker * @param {Object} bounds -- TODO calc w/out mesh so it can run in a worker
*/ */
SiP.doSparseLayerFill = function(linewidth, density, percent, bounds) { PRO.doSparseLayerFill = function(linewidth, density, percent, bounds) {
this.isSparseFill = false; this.isSparseFill = false;
if (this.tops.length === 0 || percent === 0.0 || this.isSolidFill) return; if (this.tops.length === 0 || percent === 0.0 || this.isSolidFill) return;
@ -580,7 +580,7 @@ var gs_kiri_slice = exports;
/** /**
* Runs in client. Generate sparse lines in the correct view layer. * Runs in client. Generate sparse lines in the correct view layer.
*/ */
SiP.renderSparseFill = function() { PRO.renderSparseFill = function() {
var layer = this.layers.sparse; var layer = this.layers.sparse;
layer.clear(); layer.clear();
@ -601,7 +601,7 @@ var gs_kiri_slice = exports;
* Find difference between fill inset poly on two adjacent layers. * Find difference between fill inset poly on two adjacent layers.
* Used to calculate bridges, flats and then solid projections. * Used to calculate bridges, flats and then solid projections.
*/ */
SiP.doDiff = function(minArea) { PRO.doDiff = function(minArea) {
if (!this.down) return; if (!this.down) return;
var debug = (this.index === DBUG.get('z-index')) && DBUG.get('diff'), var debug = (this.index === DBUG.get('z-index')) && DBUG.get('diff'),
@ -627,7 +627,7 @@ var gs_kiri_slice = exports;
/** /**
* Runs in client. Generate polygon lines in the correct view layer. * Runs in client. Generate polygon lines in the correct view layer.
*/ */
SiP.renderDiff = function() { PRO.renderDiff = function() {
var scope = this, var scope = this,
layers = scope.layers, layers = scope.layers,
bridgeLayer = layers.bridge, bridgeLayer = layers.bridge,
@ -657,14 +657,14 @@ var gs_kiri_slice = exports;
* *
* @param {Polygon[]} polys * @param {Polygon[]} polys
*/ */
SiP.addSolidFills = function(polys) { PRO.addSolidFills = function(polys) {
this.solids.poly.appendAll(polys); this.solids.poly.appendAll(polys);
}; };
/** /**
* project bottom flats down * project bottom flats down
*/ */
SiP.projectFlats = function(count) { PRO.projectFlats = function(count) {
if (this.isSolidFill || !this.down || !this.flats) return; if (this.isSolidFill || !this.down || !this.flats) return;
projectSolid(this, this.flats, count, false, true); projectSolid(this, this.flats, count, false, true);
}; };
@ -672,7 +672,7 @@ var gs_kiri_slice = exports;
/** /**
* project top bridges up * project top bridges up
*/ */
SiP.projectBridges = function(count) { PRO.projectBridges = function(count) {
if (this.isSolidFill || !this.up || !this.bridges) return; if (this.isSolidFill || !this.up || !this.bridges) return;
projectSolid(this, this.bridges, count, true, true); projectSolid(this, this.bridges, count, true, true);
}; };
@ -681,7 +681,7 @@ var gs_kiri_slice = exports;
* fill projected areas and store line data * fill projected areas and store line data
* @return {boolean} true if filled, false if not * @return {boolean} true if filled, false if not
*/ */
SiP.doSolidsFill = function(linewidth, angle, density, minArea) { PRO.doSolidsFill = function(linewidth, angle, density, minArea) {
var minarea = minArea || 1, var minarea = minArea || 1,
scope = this, scope = this,
@ -769,7 +769,7 @@ var gs_kiri_slice = exports;
return true; return true;
}; };
SiP.renderSolidOutlines = function() { PRO.renderSolidOutlines = function() {
var layer = this.layers.solid, var layer = this.layers.solid,
trimmed = this.solids.trimmed; trimmed = this.solids.trimmed;
@ -791,7 +791,7 @@ var gs_kiri_slice = exports;
* @param {number} expand outer support clip * @param {number} expand outer support clip
* @param {number} offset inner support clip * @param {number} offset inner support clip
*/ */
SiP.doSupport = function(minOffset, maxBridge, expand, minArea, pillarSize, offset) { PRO.doSupport = function(minOffset, maxBridge, expand, minArea, pillarSize, offset) {
var min = minArea || 0.1, var min = minArea || 0.1,
size = (pillarSize || 2), size = (pillarSize || 2),
mergeDist = size * 3, // pillar merge dist mergeDist = size * 3, // pillar merge dist
@ -919,7 +919,7 @@ var gs_kiri_slice = exports;
* @param {number} density * @param {number} density
* @param {number} offset * @param {number} offset
*/ */
SiP.doSupportFill = function(linewidth, density, minArea) { PRO.doSupportFill = function(linewidth, density, minArea) {
// return; // return;
var slice = this, var slice = this,
supports = slice.supports, supports = slice.supports,
@ -965,7 +965,7 @@ var gs_kiri_slice = exports;
/** /**
* *
*/ */
SiP.renderSupport = function() { PRO.renderSupport = function() {
var slice = this, var slice = this,
layer = slice.layers.support, layer = slice.layers.support,
supports = slice.supports; supports = slice.supports;
@ -987,7 +987,7 @@ var gs_kiri_slice = exports;
* @param {Point} target * @param {Point} target
* @return {Object} * @return {Object}
*/ */
SiP.findClosestPointTo = function(target) { PRO.findClosestPointTo = function(target) {
var min, find; var min, find;
this.tops.forEach(function(top) { this.tops.forEach(function(top) {

View file

@ -35,7 +35,7 @@ var gs_kiri_widget = exports;
newPolygon = BASE.newPolygon, newPolygon = BASE.newPolygon,
newOrderedLine = BASE.newOrderedLine, newOrderedLine = BASE.newOrderedLine,
time = UTIL.time, time = UTIL.time,
WP = Widget.prototype, PRO = Widget.prototype,
solid_opacity = 1.0, solid_opacity = 1.0,
nextId = 0; nextId = 0;
@ -227,7 +227,7 @@ var gs_kiri_widget = exports;
* Widget Prototype Functions * Widget Prototype Functions
******************************************************************* */ ******************************************************************* */
WP.saveToCatalog = function(filename) { PRO.saveToCatalog = function(filename) {
var widget = this; var widget = this;
var time = UTIL.time(); var time = UTIL.time();
KIRI.catalog.putFile(filename, this.getGeoVertices(), function(vertices) { KIRI.catalog.putFile(filename, this.getGeoVertices(), function(vertices) {
@ -239,7 +239,7 @@ var gs_kiri_widget = exports;
return this; return this;
}; };
WP.saveState = function(ondone) { PRO.saveState = function(ondone) {
var widget = this; var widget = this;
KIRI.odb.put('ws-save-'+this.id, {geo:widget.getGeoVertices(), orient:widget.orient}, function(result) { KIRI.odb.put('ws-save-'+this.id, {geo:widget.getGeoVertices(), orient:widget.orient}, function(result) {
widget.saved = time(); widget.saved = time();
@ -247,7 +247,7 @@ var gs_kiri_widget = exports;
}); });
}; };
WP.encodeSlices = function() { PRO.encodeSlices = function() {
var encoded = []; var encoded = [];
if (this.slices) this.slices.forEach(function(slice) { if (this.slices) this.slices.forEach(function(slice) {
encoded.push(slice.encode()); encoded.push(slice.encode());
@ -255,7 +255,7 @@ var gs_kiri_widget = exports;
return encoded; return encoded;
}; };
WP.decodeSlices = function(encoded) { PRO.decodeSlices = function(encoded) {
this.slices = KIRI.codec.decode(encoded, { mesh:this.mesh }); this.slices = KIRI.codec.decode(encoded, { mesh:this.mesh });
}; };
@ -264,7 +264,7 @@ var gs_kiri_widget = exports;
* @param {Float32Array} vertices * @param {Float32Array} vertices
* @returns {Widget} * @returns {Widget}
*/ */
WP.loadVertices = function(vertices) { PRO.loadVertices = function(vertices) {
if (this.mesh) { if (this.mesh) {
this.mesh.geometry.addAttribute('position', new THREE.BufferAttribute(vertices, 3)); this.mesh.geometry.addAttribute('position', new THREE.BufferAttribute(vertices, 3));
this.mesh.geometry.computeFaceNormals(); this.mesh.geometry.computeFaceNormals();
@ -282,7 +282,7 @@ var gs_kiri_widget = exports;
* @param {THREE.Geometry} geometry * @param {THREE.Geometry} geometry
* @returns {Widget} * @returns {Widget}
*/ */
WP.loadGeometry = function(geometry) { PRO.loadGeometry = function(geometry) {
var mesh = new THREE.Mesh( var mesh = new THREE.Mesh(
geometry, geometry,
new THREE.MeshPhongMaterial({ new THREE.MeshPhongMaterial({
@ -312,7 +312,7 @@ var gs_kiri_widget = exports;
* @param {Point[]} points * @param {Point[]} points
* @returns {Widget} * @returns {Widget}
*/ */
WP.setPoints = function(points) { PRO.setPoints = function(points) {
this.points = points || null; this.points = points || null;
return this; return this;
}; };
@ -320,7 +320,7 @@ var gs_kiri_widget = exports;
/** /**
* remove slice data and their views * remove slice data and their views
*/ */
WP.clearSlices = function() { PRO.clearSlices = function() {
var slices = this.slices, var slices = this.slices,
mesh = this.mesh; mesh = this.mesh;
if (slices) { if (slices) {
@ -334,7 +334,7 @@ var gs_kiri_widget = exports;
/** /**
* @param {number} color * @param {number} color
*/ */
WP.setColor = function(color) { PRO.setColor = function(color) {
var material = this.mesh.material; var material = this.mesh.material;
material.color.set(color); material.color.set(color);
}; };
@ -342,7 +342,7 @@ var gs_kiri_widget = exports;
/** /**
* @param {number} value * @param {number} value
*/ */
WP.setOpacity = function(value) { PRO.setOpacity = function(value) {
var mesh = this.mesh; var mesh = this.mesh;
if (value <= 0.0) { if (value <= 0.0) {
mesh.material.transparent = solid_opacity < 1.0; mesh.material.transparent = solid_opacity < 1.0;
@ -358,7 +358,7 @@ var gs_kiri_widget = exports;
/** /**
* center geometry bottom (on platform) at 0,0,0 * center geometry bottom (on platform) at 0,0,0
*/ */
WP.center = function() { PRO.center = function() {
var i = 0, var i = 0,
mesh = this.mesh, mesh = this.mesh,
geo = mesh.geometry, geo = mesh.geometry,
@ -391,7 +391,7 @@ var gs_kiri_widget = exports;
* *
* @param {number} z position * @param {number} z position
*/ */
WP.setTopZ = function(z) { PRO.setTopZ = function(z) {
var mesh = this.mesh, var mesh = this.mesh,
pos = this.orient.pos; pos = this.orient.pos;
if (z) { if (z) {
@ -411,7 +411,7 @@ var gs_kiri_widget = exports;
* @param {number} z * @param {number} z
* @param {boolean} abs * @param {boolean} abs
*/ */
WP.move = function(x, y, z, abs) { PRO.move = function(x, y, z, abs) {
var mesh = this.mesh, var mesh = this.mesh,
pos = this.orient.pos; pos = this.orient.pos;
// do not allow moves in pure slice view // do not allow moves in pure slice view
@ -438,7 +438,7 @@ var gs_kiri_widget = exports;
* @param {number} y * @param {number} y
* @param {number} z * @param {number} z
*/ */
WP.scale = function(x, y, z) { PRO.scale = function(x, y, z) {
var mesh = this.mesh, var mesh = this.mesh,
scale = this.orient.scale; scale = this.orient.scale;
this.setWireframe(false); this.setWireframe(false);
@ -456,7 +456,7 @@ var gs_kiri_widget = exports;
* @param {number} y * @param {number} y
* @param {number} z * @param {number} z
*/ */
WP.rotate = function(x, y, z) { PRO.rotate = function(x, y, z) {
this.setWireframe(false); this.setWireframe(false);
this.clearSlices(); this.clearSlices();
this.mesh.geometry.applyMatrix(new THREE.Matrix4().makeRotationFromEuler(new THREE.Euler(x || 0, y || 0, z || 0))); this.mesh.geometry.applyMatrix(new THREE.Matrix4().makeRotationFromEuler(new THREE.Euler(x || 0, y || 0, z || 0)));
@ -467,7 +467,7 @@ var gs_kiri_widget = exports;
rot.z += (z || 0); rot.z += (z || 0);
}; };
WP.mirror = function() { PRO.mirror = function() {
this.setWireframe(false); this.setWireframe(false);
this.clearSlices(); this.clearSlices();
var i, var i,
@ -486,11 +486,11 @@ var gs_kiri_widget = exports;
o.mirror = !o.mirror; o.mirror = !o.mirror;
}; };
WP.getGeoVertices = function() { PRO.getGeoVertices = function() {
return this.mesh.geometry.getAttribute('position').array; return this.mesh.geometry.getAttribute('position').array;
}; };
WP.getPoints = function() { PRO.getPoints = function() {
if (!this.points) { if (!this.points) {
// convert and cache points from geometry vertices // convert and cache points from geometry vertices
this.points = Widget.verticesToPoints(this.getGeoVertices()); this.points = Widget.verticesToPoints(this.getGeoVertices());
@ -498,7 +498,7 @@ var gs_kiri_widget = exports;
return this.points; return this.points;
}; };
WP.getBoundingBox = function(refresh) { PRO.getBoundingBox = function(refresh) {
// if (this.mesh) return this.mesh.getBoundingBox(); // if (this.mesh) return this.mesh.getBoundingBox();
if (!this.bounds || refresh) { if (!this.bounds || refresh) {
this.bounds = new THREE.Box3(); this.bounds = new THREE.Box3();
@ -507,7 +507,7 @@ var gs_kiri_widget = exports;
return this.bounds; return this.bounds;
}; };
WP.isModified = function() { PRO.isModified = function() {
return this.modified; return this.modified;
}; };
@ -525,7 +525,7 @@ var gs_kiri_widget = exports;
* @params {Function} [onupdate] * @params {Function} [onupdate]
* @params {boolean} [remote] * @params {boolean} [remote]
*/ */
WP.slice = function(settings, ondone, onupdate, remote) { PRO.slice = function(settings, ondone, onupdate, remote) {
var widget = this, var widget = this,
startTime = UTIL.time(); startTime = UTIL.time();
@ -586,7 +586,7 @@ var gs_kiri_widget = exports;
} }
}; };
WP.getCamBounds = function(settings) { PRO.getCamBounds = function(settings) {
var bounds = this.getBoundingBox().clone(); var bounds = this.getBoundingBox().clone();
bounds.max.z += settings.process.camZTopOffset; bounds.max.z += settings.process.camZTopOffset;
return bounds; return bounds;
@ -597,7 +597,7 @@ var gs_kiri_widget = exports;
* @param {number} renderMode * @param {number} renderMode
* @param {boolean} cam mode * @param {boolean} cam mode
*/ */
WP.render = function(renderMode, cam) { PRO.render = function(renderMode, cam) {
var slices = this.slices; var slices = this.slices;
if (!slices) return; if (!slices) return;
// render outline // render outline
@ -616,7 +616,7 @@ var gs_kiri_widget = exports;
if (!cam) slices.forEach(function(s) { s.renderSupport() }); if (!cam) slices.forEach(function(s) { s.renderSupport() });
}; };
WP.hideSlices = function() { PRO.hideSlices = function() {
var showing = false; var showing = false;
if (this.slices) this.slices.forEach(function(slice) { if (this.slices) this.slices.forEach(function(slice) {
showing = showing || slice.view.visible; showing = showing || slice.view.visible;
@ -625,11 +625,11 @@ var gs_kiri_widget = exports;
return showing; return showing;
}; };
WP.toggleWireframe = function (color, opacity) { PRO.toggleWireframe = function (color, opacity) {
this.setWireframe(!this.wire, color, opacity); this.setWireframe(!this.wire, color, opacity);
}; };
WP.setWireframe = function(set, color, opacity) { PRO.setWireframe = function(set, color, opacity) {
var mesh = this.mesh, var mesh = this.mesh,
widget = this; widget = this;
if (this.wire) { if (this.wire) {