normalize prototype shortcuts
This commit is contained in:
parent
bc4949d2f8
commit
8d57ed0883
10 changed files with 229 additions and 230 deletions
|
|
@ -27,7 +27,7 @@ var gs_base_bounds = exports;
|
|||
ABS = Math.abs,
|
||||
MIN = Math.min,
|
||||
MAX = Math.max,
|
||||
BoP = Bounds.prototype;
|
||||
PRO = Bounds.prototype;
|
||||
|
||||
BASE.Bounds = Bounds;
|
||||
BASE.newBounds = newBounds;
|
||||
|
|
@ -39,7 +39,7 @@ var gs_base_bounds = exports;
|
|||
/**
|
||||
* @returns {Bounds}
|
||||
*/
|
||||
BoP.clone = function() {
|
||||
PRO.clone = function() {
|
||||
var b = new Bounds();
|
||||
b.minx = this.minx;
|
||||
b.miny = this.miny;
|
||||
|
|
@ -48,7 +48,7 @@ var gs_base_bounds = exports;
|
|||
return b;
|
||||
};
|
||||
|
||||
BoP.equals = function(bounds, margin) {
|
||||
PRO.equals = function(bounds, margin) {
|
||||
if (!margin) margin = BASE.config.precision_offset;
|
||||
return UTIL.isCloseTo(this.minx, bounds.minx, margin) &&
|
||||
UTIL.isCloseTo(this.miny, bounds.miny, margin) &&
|
||||
|
|
@ -59,7 +59,7 @@ var gs_base_bounds = exports;
|
|||
/**
|
||||
* @param {Bounds} b
|
||||
*/
|
||||
BoP.merge = function(b) {
|
||||
PRO.merge = function(b) {
|
||||
this.minx = MIN(this.minx, b.minx);
|
||||
this.maxx = MAX(this.maxx, b.maxx);
|
||||
this.miny = MIN(this.miny, b.miny);
|
||||
|
|
@ -69,7 +69,7 @@ var gs_base_bounds = exports;
|
|||
/**
|
||||
* @param {Point} p
|
||||
*/
|
||||
BoP.update = function(p) {
|
||||
PRO.update = function(p) {
|
||||
this.minx = MIN(this.minx, p.x);
|
||||
this.maxx = MAX(this.maxx, p.x);
|
||||
this.miny = MIN(this.miny, p.y);
|
||||
|
|
@ -77,15 +77,15 @@ var gs_base_bounds = exports;
|
|||
if (this.minx === p.x) this.leftMost = p;
|
||||
};
|
||||
|
||||
BoP.contains = function(bounds) {
|
||||
PRO.contains = function(bounds) {
|
||||
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;
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ var gs_base_bounds = exports;
|
|||
* @param {Bounds} parent
|
||||
* @returns {boolean} true if fully inside parent bounds
|
||||
*/
|
||||
BoP.isNested = function(parent) {
|
||||
PRO.isNested = function(parent) {
|
||||
return (
|
||||
this.minx >= parent.minx - CONF.precision_bounds && // min-x
|
||||
this.maxx <= parent.maxx + CONF.precision_bounds && // max-x
|
||||
|
|
@ -107,26 +107,26 @@ var gs_base_bounds = exports;
|
|||
* @param {number} precision
|
||||
* @returns {boolean}
|
||||
*/
|
||||
BoP.overlaps = function(b, precision) {
|
||||
PRO.overlaps = function(b, precision) {
|
||||
return (
|
||||
ABS(this.centerx() - b.centerx()) * 2 - precision < this.width() + b.width() &&
|
||||
ABS(this.centery() - b.centery()) * 2 - precision < this.height() + b.height()
|
||||
);
|
||||
};
|
||||
|
||||
BoP.width = function() {
|
||||
PRO.width = function() {
|
||||
return this.maxx - this.minx;
|
||||
};
|
||||
|
||||
BoP.height = function() {
|
||||
PRO.height = function() {
|
||||
return this.maxy - this.miny;
|
||||
};
|
||||
|
||||
BoP.centerx = function() {
|
||||
PRO.centerx = function() {
|
||||
return this.minx + this.width() / 2;
|
||||
};
|
||||
|
||||
BoP.centery = function() {
|
||||
PRO.centery = function() {
|
||||
return this.miny + this.height() / 2;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ var gs_base_line = exports;
|
|||
}
|
||||
|
||||
var BASE = self.base,
|
||||
LiP = Line.prototype;
|
||||
PRO = Line.prototype;
|
||||
|
||||
BASE.Line = Line;
|
||||
BASE.newLine = newLine;
|
||||
|
|
@ -40,28 +40,28 @@ var gs_base_line = exports;
|
|||
/**
|
||||
* @returns {number}
|
||||
*/
|
||||
LiP.length = function() {
|
||||
PRO.length = function() {
|
||||
return Math.sqrt(this.length2());
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {number} square of length
|
||||
*/
|
||||
LiP.length2 = function() {
|
||||
PRO.length2 = function() {
|
||||
return this.p1.distToSq2D(this.p2);
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {Slope}
|
||||
*/
|
||||
LiP.slope = function() {
|
||||
PRO.slope = function() {
|
||||
return BASE.newSlope(this.p1.slopeTo(this.p2));
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {Line}
|
||||
*/
|
||||
LiP.reverse = function() {
|
||||
PRO.reverse = function() {
|
||||
var t = this.p1;
|
||||
this.p1 = this.p2;
|
||||
this.p2 = t;
|
||||
|
|
@ -71,7 +71,7 @@ var gs_base_line = exports;
|
|||
/**
|
||||
* @returns {Point}
|
||||
*/
|
||||
LiP.midpoint = function() {
|
||||
PRO.midpoint = function() {
|
||||
return this.p1.midPointTo(this.p2);
|
||||
};
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ var gs_base_line = exports;
|
|||
* @param {Line} line
|
||||
* @returns {boolean}
|
||||
*/
|
||||
LiP.isCollinear = function(line) {
|
||||
PRO.isCollinear = function(line) {
|
||||
var p1 = this.p1,
|
||||
p2 = this.p2,
|
||||
p3 = line.p1,
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ var gs_base_point = exports;
|
|||
CONF = BASE.config,
|
||||
KEYS = BASE.key,
|
||||
ROUND = UTIL.round,
|
||||
PoP = Point.prototype;
|
||||
PRO = Point.prototype;
|
||||
|
||||
BASE.Point = Point;
|
||||
BASE.newPoint = newPoint;
|
||||
|
|
@ -58,47 +58,47 @@ var gs_base_point = exports;
|
|||
* Point Prototype Functions
|
||||
******************************************************************* */
|
||||
|
||||
PoP.setZ = function(z) {
|
||||
PRO.setZ = function(z) {
|
||||
this.z = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
PoP.swapXZ = function() {
|
||||
PRO.swapXZ = function() {
|
||||
var p = this,
|
||||
t = p.x;
|
||||
p.x = p.z;
|
||||
p.z = t;
|
||||
};
|
||||
|
||||
PoP.swapYZ = function() {
|
||||
PRO.swapYZ = function() {
|
||||
var p = this,
|
||||
t = p.y;
|
||||
p.y = p.z;
|
||||
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));
|
||||
};
|
||||
|
||||
PoP.addFacet = function(facet) {
|
||||
PRO.addFacet = function(facet) {
|
||||
if (!this.group) this.group = [];
|
||||
this.group.push(facet);
|
||||
return this;
|
||||
};
|
||||
|
||||
PoP.rekey = function() {
|
||||
PRO.rekey = function() {
|
||||
this.key = [this.x,this.y,this.z].join(',');
|
||||
};
|
||||
|
||||
PoP.toString = function() {
|
||||
PRO.toString = function() {
|
||||
return this.key;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {Point}
|
||||
*/
|
||||
PoP.clone = function() {
|
||||
PRO.clone = function() {
|
||||
return newPoint(this.x, this.y, this.z, this.key);
|
||||
};
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ var gs_base_point = exports;
|
|||
* @param {Point} p
|
||||
* @returns {Slope}
|
||||
*/
|
||||
PoP.slopeTo = function(p) {
|
||||
PRO.slopeTo = function(p) {
|
||||
return BASE.newSlope(this, p);
|
||||
};
|
||||
|
||||
|
|
@ -116,7 +116,7 @@ var gs_base_point = exports;
|
|||
* @param {String} [k]
|
||||
* @returns {Line}
|
||||
*/
|
||||
PoP.lineTo = function(p, k) {
|
||||
PRO.lineTo = function(p, k) {
|
||||
return BASE.newLine(this, p, k);
|
||||
};
|
||||
|
||||
|
|
@ -125,7 +125,7 @@ var gs_base_point = exports;
|
|||
* @param {number} [dist]
|
||||
* @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);
|
||||
};
|
||||
|
||||
|
|
@ -137,7 +137,7 @@ var gs_base_point = exports;
|
|||
* @param {Point} p2
|
||||
* @returns {number}
|
||||
*/
|
||||
PoP.distToLine = function(p1, p2) {
|
||||
PRO.distToLine = function(p1, p2) {
|
||||
return Math.sqrt(this.distToLineSq(p1, p2));
|
||||
};
|
||||
|
||||
|
|
@ -149,7 +149,7 @@ var gs_base_point = exports;
|
|||
* @param {Point} p2
|
||||
* @returns {number}
|
||||
*/
|
||||
PoP.distToLineSq = function(p1, p2) {
|
||||
PRO.distToLineSq = function(p1, p2) {
|
||||
var p = this,
|
||||
d = UTIL.distSq(p1, p2);
|
||||
|
||||
|
|
@ -168,7 +168,7 @@ var gs_base_point = exports;
|
|||
* @param {number} dist2
|
||||
* @returns {boolean}
|
||||
*/
|
||||
PoP.withinDist2 = function(p1, p2, dist2) {
|
||||
PRO.withinDist2 = function(p1, p2, dist2) {
|
||||
var ll2 = p1.distToSq2D(p2),
|
||||
dp1 = this.distToSq2D(p1),
|
||||
dp2 = this.distToSq2D(p2);
|
||||
|
|
@ -192,7 +192,7 @@ var gs_base_point = exports;
|
|||
* @param {Point} p2
|
||||
* @returns {Point}
|
||||
*/
|
||||
PoP.midPointTo = function(p2) {
|
||||
PRO.midPointTo = function(p2) {
|
||||
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
|
||||
* @returns {Point}
|
||||
*/
|
||||
PoP.midPointTo3D = function(p2) {
|
||||
PRO.midPointTo3D = function(p2) {
|
||||
return newPoint(
|
||||
(this.x + p2.x)/2,
|
||||
(this.y + p2.y)/2,
|
||||
|
|
@ -215,14 +215,14 @@ var gs_base_point = exports;
|
|||
* @param mult
|
||||
* @returns {Point}
|
||||
*/
|
||||
PoP.projectOnSlope = function(slope, mult) {
|
||||
PRO.projectOnSlope = function(slope, mult) {
|
||||
return newPoint(
|
||||
this.x + slope.dx * mult,
|
||||
this.y + slope.dy * mult,
|
||||
this.z);
|
||||
};
|
||||
|
||||
PoP.followTo = function(point, mult) {
|
||||
PRO.followTo = function(point, mult) {
|
||||
return this.follow(this.slopeTo(point), mult);
|
||||
};
|
||||
|
||||
|
|
@ -234,7 +234,7 @@ var gs_base_point = exports;
|
|||
* @param p2
|
||||
* @param dist
|
||||
*/
|
||||
PoP.offsetPointFrom = function(p2, dist) {
|
||||
PRO.offsetPointFrom = function(p2, dist) {
|
||||
var p1 = this,
|
||||
dx = p2.x - p1.x,
|
||||
dy = p2.y - p1.y,
|
||||
|
|
@ -249,7 +249,7 @@ var gs_base_point = exports;
|
|||
* @param {number} offset
|
||||
* @returns {Line}
|
||||
*/
|
||||
PoP.offsetLineTo = function(p2, offset) {
|
||||
PRO.offsetLineTo = function(p2, offset) {
|
||||
var p1 = this,
|
||||
dx = p2.x - p1.x,
|
||||
dy = p2.y - p1.y,
|
||||
|
|
@ -271,7 +271,7 @@ var gs_base_point = exports;
|
|||
* @param {Polygon} poly
|
||||
* @returns {boolean}
|
||||
*/
|
||||
PoP.inPolygon = function(poly) {
|
||||
PRO.inPolygon = function(poly) {
|
||||
if (!poly.bounds.containsXY(this.x, this.y)) return 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
|
||||
* @return {boolean} true if inside outer but not inner
|
||||
*/
|
||||
PoP.isInPolygon = function(poly) {
|
||||
PRO.isInPolygon = function(poly) {
|
||||
var point = this, i;
|
||||
if (Array.isArray(poly)) {
|
||||
for (i=0; i<poly.length; i++) {
|
||||
|
|
@ -321,7 +321,7 @@ var gs_base_point = exports;
|
|||
* @param {Polygon | Polygon[]} poly
|
||||
* @return {boolean} true if inside outer but not inner
|
||||
*/
|
||||
PoP.isInPolygonOnly = function(poly) {
|
||||
PRO.isInPolygonOnly = function(poly) {
|
||||
var point = this, i;
|
||||
if (Array.isArray(poly)) {
|
||||
for (i=0; i<poly.length; i++) {
|
||||
|
|
@ -347,7 +347,7 @@ var gs_base_point = exports;
|
|||
* @param {boolean} [inner] process inner polygons
|
||||
* @returns {boolean}
|
||||
*/
|
||||
PoP.nearPolygon = function(poly, dist2, inner) {
|
||||
PRO.nearPolygon = function(poly, dist2, inner) {
|
||||
// throw new Error("nearPolygon");
|
||||
for (var i=0, p=poly.points, pl=p.length ; i<pl; i++) {
|
||||
if (this.withinDist2(p[i], p[(i+1)%pl], dist2)) {
|
||||
|
|
@ -370,7 +370,7 @@ var gs_base_point = exports;
|
|||
* @param {number} mindist2
|
||||
* @returns {boolean}
|
||||
*/
|
||||
PoP.insideOffset = function(poly, offset, mindist2) {
|
||||
PRO.insideOffset = function(poly, offset, mindist2) {
|
||||
return this.inPolygon(poly) === (offset > 0) && !this.nearPolygon(poly, mindist2);
|
||||
};
|
||||
|
||||
|
|
@ -382,7 +382,7 @@ var gs_base_point = exports;
|
|||
* @param {number} distance
|
||||
* @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);
|
||||
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
|
||||
* @returns {Point}
|
||||
*/
|
||||
PoP.intersectZ = function(p, z) {
|
||||
PRO.intersectZ = function(p, z) {
|
||||
var dx = p.x - this.x,
|
||||
dy = p.y - this.y,
|
||||
dz = p.z - this.z,
|
||||
|
|
@ -406,7 +406,7 @@ var gs_base_point = exports;
|
|||
* @param {Point} p
|
||||
* @returns {boolean}
|
||||
*/
|
||||
PoP.isEqual2D = function(p) {
|
||||
PRO.isEqual2D = function(p) {
|
||||
return this === p || (this.x === p.x && this.y === p.y);
|
||||
};
|
||||
|
||||
|
|
@ -416,7 +416,7 @@ var gs_base_point = exports;
|
|||
* @param {Point} p
|
||||
* @returns {boolean}
|
||||
*/
|
||||
PoP.isMergable2D = function(p) {
|
||||
PRO.isMergable2D = function(p) {
|
||||
return this.isEqual2D(p) || (this.distToSq2D(p) < CONF.precision_merge_sq);
|
||||
};
|
||||
|
||||
|
|
@ -426,7 +426,7 @@ var gs_base_point = exports;
|
|||
* @param {Point} p
|
||||
* @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);
|
||||
};
|
||||
|
||||
|
|
@ -436,7 +436,7 @@ var gs_base_point = exports;
|
|||
* @param {Point} p
|
||||
* @returns {boolean}
|
||||
*/
|
||||
PoP.isMergable3D = function(p) {
|
||||
PRO.isMergable3D = function(p) {
|
||||
return this.isEqual(p) || (this.distToSq3D(p) < CONF.precision_merge_sq);
|
||||
};
|
||||
|
||||
|
|
@ -447,7 +447,7 @@ var gs_base_point = exports;
|
|||
* @param {number} dist
|
||||
* @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;
|
||||
};
|
||||
|
||||
|
|
@ -458,7 +458,7 @@ var gs_base_point = exports;
|
|||
* @param {Polygon} poly
|
||||
* @param {number} [threshold] stop looking if under threshold
|
||||
*/
|
||||
PoP.distToPolySegments = function(poly, threshold) {
|
||||
PRO.distToPolySegments = function(poly, threshold) {
|
||||
var point = this,
|
||||
mindist = Infinity;
|
||||
poly.forEachSegment(function(p1, p2) {
|
||||
|
|
@ -474,7 +474,7 @@ var gs_base_point = exports;
|
|||
* @param {Polygon} poly
|
||||
* @param {number} [threshold] stop looking if under threshold
|
||||
*/
|
||||
PoP.distToPolyPoints = function(poly, threshold) {
|
||||
PRO.distToPolyPoints = function(poly, threshold) {
|
||||
var point = this, mindist = Infinity;
|
||||
poly.forEachPoint(function(pp) {
|
||||
mindist = Math.min(mindist, point.distTo2D(pp));
|
||||
|
|
@ -488,7 +488,7 @@ var gs_base_point = exports;
|
|||
* @param {number} max
|
||||
* @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";
|
||||
var mind = Infinity,
|
||||
minp = null,
|
||||
|
|
@ -509,7 +509,7 @@ var gs_base_point = exports;
|
|||
* @param {Point[]} 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;
|
||||
for (i = 0; i < points.length; i++) {
|
||||
if (points[i] != this) {
|
||||
|
|
@ -526,7 +526,7 @@ var gs_base_point = exports;
|
|||
* @param {Point} p
|
||||
* @returns {number}
|
||||
*/
|
||||
PoP.distTo2D = function(p) {
|
||||
PRO.distTo2D = function(p) {
|
||||
var dx = this.x - p.x,
|
||||
dy = this.y - p.y;
|
||||
return Math.sqrt(dx * dx + dy * dy);
|
||||
|
|
@ -538,13 +538,13 @@ var gs_base_point = exports;
|
|||
* @param {Point} p
|
||||
* @returns {number}
|
||||
*/
|
||||
PoP.distToSq2D = function(p) {
|
||||
PRO.distToSq2D = function(p) {
|
||||
var dx = this.x - p.x,
|
||||
dy = this.y - p.y;
|
||||
return dx * dx + dy * dy;
|
||||
};
|
||||
|
||||
PoP.distTo3D = function(p) {
|
||||
PRO.distTo3D = function(p) {
|
||||
var dx = this.x - p.x,
|
||||
dy = this.y - p.y,
|
||||
dz = this.z - p.z;
|
||||
|
|
@ -557,7 +557,7 @@ var gs_base_point = exports;
|
|||
* @param {Point} p
|
||||
* @returns {number}
|
||||
*/
|
||||
PoP.distToSq3D = function(p) {
|
||||
PRO.distToSq3D = function(p) {
|
||||
var dx = this.x - p.x,
|
||||
dy = this.y - p.y,
|
||||
dz = this.z - p.z;
|
||||
|
|
@ -572,7 +572,7 @@ var gs_base_point = exports;
|
|||
* @param {Point} c
|
||||
* @returns {boolean}
|
||||
*/
|
||||
PoP.inTriangle = function(a, b, c) {
|
||||
PRO.inTriangle = function(a, b, c) {
|
||||
var as_x = this.x - a.x,
|
||||
as_y = this.y - a.y,
|
||||
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
|
||||
* @returns {boolean}
|
||||
*/
|
||||
PoP.onLine = function(p1, p2) {
|
||||
PRO.onLine = function(p1, p2) {
|
||||
return this.distToLine(p1, p2) < CONF.precision_point_on_line;
|
||||
};
|
||||
|
||||
|
|
@ -599,7 +599,7 @@ var gs_base_point = exports;
|
|||
* @param {THREE.Vector3} delta
|
||||
* @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);
|
||||
};
|
||||
|
||||
|
|
@ -608,7 +608,7 @@ var gs_base_point = exports;
|
|||
* @param {THREE.Vector3} delta
|
||||
* @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);
|
||||
};
|
||||
|
||||
|
|
@ -616,7 +616,7 @@ var gs_base_point = exports;
|
|||
*
|
||||
* @param {THREE.Vector3} delta
|
||||
*/
|
||||
PoP.move = function(delta) {
|
||||
PRO.move = function(delta) {
|
||||
this.x += delta.x;
|
||||
this.y += delta.y;
|
||||
this.z += delta.z;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ var gs_base_polygon = exports;
|
|||
DEG2RAD = PI / 180,
|
||||
Bounds = BASE.Bounds,
|
||||
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)),
|
||||
min_area_mult = 2.0,
|
||||
seqid = 1;
|
||||
|
|
@ -111,7 +111,7 @@ var gs_base_polygon = exports;
|
|||
* Polygon Prototype Functions
|
||||
******************************************************************* */
|
||||
|
||||
PlP.createConvexHull = function(points) {
|
||||
PRO.createConvexHull = function(points) {
|
||||
function removeMiddle(a, b, c) {
|
||||
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);
|
||||
|
|
@ -138,7 +138,7 @@ var gs_base_polygon = exports;
|
|||
return this;
|
||||
};
|
||||
|
||||
PlP.stepsFromRoot = function() {
|
||||
PRO.stepsFromRoot = function() {
|
||||
var p = this.parent, steps = 0;
|
||||
while (p) {
|
||||
if (p.inner && p.inner.length > 1) steps++;
|
||||
|
|
@ -147,15 +147,15 @@ var gs_base_polygon = exports;
|
|||
return steps;
|
||||
};
|
||||
|
||||
PlP.first = function() {
|
||||
PRO.first = function() {
|
||||
return this.points[0];
|
||||
};
|
||||
|
||||
PlP.last = function() {
|
||||
PRO.last = function() {
|
||||
return this.points[this.length-1];
|
||||
};
|
||||
|
||||
PlP.swap = function(x,y) {
|
||||
PRO.swap = function(x,y) {
|
||||
var poly = this,
|
||||
points = poly.points,
|
||||
length = points.length;
|
||||
|
|
@ -176,7 +176,7 @@ var gs_base_polygon = exports;
|
|||
* @param {boolean} [point] return just the center point
|
||||
* @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;
|
||||
pa.forEach(function(p) {
|
||||
ap.x += p.x;
|
||||
|
|
@ -200,7 +200,7 @@ var gs_base_polygon = exports;
|
|||
/**
|
||||
* @returns {Point} center of a polygon assuming it's a circle
|
||||
*/
|
||||
PlP.circleCenter = function() {
|
||||
PRO.circleCenter = function() {
|
||||
var points = this.points,
|
||||
length = points.length,
|
||||
incr = Math.floor(length / 3),
|
||||
|
|
@ -229,7 +229,7 @@ var gs_base_polygon = exports;
|
|||
* @param {number} width
|
||||
* @param {number} height
|
||||
*/
|
||||
PlP.centerRectangle = function(center, width, height) {
|
||||
PRO.centerRectangle = function(center, width, height) {
|
||||
width /= 2;
|
||||
height /= 2;
|
||||
this.push(newPoint(center.x - width, center.y - height, center.z));
|
||||
|
|
@ -247,7 +247,7 @@ var gs_base_polygon = exports;
|
|||
* @param {number} points
|
||||
* @param {boolean} clockwise
|
||||
*/
|
||||
PlP.centerCircle = function(center, radius, points, clockwise) {
|
||||
PRO.centerCircle = function(center, radius, points, clockwise) {
|
||||
var angle = 0, add = 360 / points;
|
||||
if (clockwise) add = -add;
|
||||
while (points-- > 0) {
|
||||
|
|
@ -266,7 +266,7 @@ var gs_base_polygon = exports;
|
|||
* @param {THREE.Vector3} offset
|
||||
* @returns {Polygon}
|
||||
*/
|
||||
PlP.move = function(offset) {
|
||||
PRO.move = function(offset) {
|
||||
var scope = this,
|
||||
bounds = scope.bounds = new Bounds();
|
||||
scope.points.forEach(function(p) {
|
||||
|
|
@ -277,7 +277,7 @@ var gs_base_polygon = exports;
|
|||
return scope;
|
||||
};
|
||||
|
||||
PlP.scale = function(scale, round) {
|
||||
PRO.scale = function(scale, round) {
|
||||
var scope = this,
|
||||
bounds = scope.bounds = new Bounds();
|
||||
scope.points.forEach(function(p) {
|
||||
|
|
@ -297,7 +297,7 @@ var gs_base_polygon = exports;
|
|||
/**
|
||||
* add fill angle hinting from longest segment
|
||||
*/
|
||||
PlP.hintFillAngle = function() {
|
||||
PRO.hintFillAngle = function() {
|
||||
var index = 0,
|
||||
points = this.points,
|
||||
length = points.length,
|
||||
|
|
@ -332,7 +332,7 @@ var gs_base_polygon = exports;
|
|||
* @param {Boolean} deep
|
||||
* @returns {Polygon}
|
||||
*/
|
||||
PlP.clone = function(deep) {
|
||||
PRO.clone = function(deep) {
|
||||
var np = newPolygon(),
|
||||
ln = this.length,
|
||||
i = 0;
|
||||
|
|
@ -356,7 +356,7 @@ var gs_base_polygon = exports;
|
|||
* @param {number} z
|
||||
* @returns {Polygon} this
|
||||
*/
|
||||
PlP.setZ = function(z) {
|
||||
PRO.setZ = function(z) {
|
||||
var ar = this.points,
|
||||
ln = ar.length,
|
||||
i = 0;
|
||||
|
|
@ -368,7 +368,7 @@ var gs_base_polygon = exports;
|
|||
/**
|
||||
* @returns {number} z value of first point
|
||||
*/
|
||||
PlP.getZ = function() {
|
||||
PRO.getZ = function() {
|
||||
return this.points[0].z;
|
||||
};
|
||||
|
||||
|
|
@ -379,7 +379,7 @@ var gs_base_polygon = exports;
|
|||
* @param {boolean} [recursive]
|
||||
* @param {boolean} [open]
|
||||
*/
|
||||
PlP.render = function(layer, color, recursive, open) {
|
||||
PRO.render = function(layer, color, recursive, open) {
|
||||
layer.poly(this, color, recursive, open);
|
||||
};
|
||||
|
||||
|
|
@ -391,7 +391,7 @@ var gs_base_polygon = exports;
|
|||
* @param {number} [z]
|
||||
* @returns {Polygon}
|
||||
*/
|
||||
PlP.add = function(x,y,z) {
|
||||
PRO.add = function(x,y,z) {
|
||||
this.push(newPoint(x,y,z));
|
||||
return this;
|
||||
};
|
||||
|
|
@ -402,7 +402,7 @@ var gs_base_polygon = exports;
|
|||
* @param {Point[]} points
|
||||
* @returns {Polygon}
|
||||
*/
|
||||
PlP.addPoints = function(points) {
|
||||
PRO.addPoints = function(points) {
|
||||
var poly = this,
|
||||
length = points.length,
|
||||
i = 0;
|
||||
|
|
@ -418,7 +418,7 @@ var gs_base_polygon = exports;
|
|||
* @param {Point} p
|
||||
* @returns {Point}
|
||||
*/
|
||||
PlP.push = function(p) {
|
||||
PRO.push = function(p) {
|
||||
// clone any point belonging to another polygon
|
||||
if (p.poly) p = p.clone();
|
||||
p.poly = this;
|
||||
|
|
@ -434,46 +434,46 @@ var gs_base_polygon = exports;
|
|||
* @param {Point} p
|
||||
* @returns {Polygon}
|
||||
*/
|
||||
PlP.append = function(p) {
|
||||
PRO.append = function(p) {
|
||||
this.push(p);
|
||||
return this;
|
||||
};
|
||||
|
||||
/** close polygon */
|
||||
PlP.setClosed = function() {
|
||||
PRO.setClosed = function() {
|
||||
this.open = false;
|
||||
return this;
|
||||
};
|
||||
|
||||
/** open polygon */
|
||||
PlP.setOpen = function() {
|
||||
PRO.setOpen = function() {
|
||||
this.open = true;
|
||||
return this;
|
||||
};
|
||||
|
||||
PlP.isOpen = function() {
|
||||
PRO.isOpen = function() {
|
||||
return this.open;
|
||||
};
|
||||
|
||||
PlP.isClosed = function() {
|
||||
PRO.isClosed = function() {
|
||||
return !this.open;
|
||||
};
|
||||
|
||||
PlP.setClockwise = function() {
|
||||
PRO.setClockwise = function() {
|
||||
if (!this.isClockwise()) this.reverse();
|
||||
return this;
|
||||
};
|
||||
|
||||
PlP.setCounterClockwise = function() {
|
||||
PRO.setCounterClockwise = function() {
|
||||
if (this.isClockwise()) this.reverse();
|
||||
return this;
|
||||
};
|
||||
|
||||
PlP.isClockwise = function() {
|
||||
PRO.isClockwise = function() {
|
||||
return this.area(true) > 0;
|
||||
};
|
||||
|
||||
PlP.showKey = function() {
|
||||
PRO.showKey = function() {
|
||||
return [this.first().key,this.last().key,this.length].join('~~');
|
||||
};
|
||||
|
||||
|
|
@ -484,7 +484,7 @@ var gs_base_polygon = exports;
|
|||
* @param [boolean] toLongest
|
||||
* @returns {Polygon} self
|
||||
*/
|
||||
PlP.alignWinding = function(poly, toLongest) {
|
||||
PRO.alignWinding = function(poly, toLongest) {
|
||||
if (toLongest && this.length > poly.length) {
|
||||
poly.alignWinding(this, false);
|
||||
} else if (this.isClockwise() !== poly.isClockwise()) {
|
||||
|
|
@ -499,7 +499,7 @@ var gs_base_polygon = exports;
|
|||
* @param [boolean] toLongest
|
||||
* @returns {Polygon} self
|
||||
*/
|
||||
PlP.opposeWinding = function(poly, toLongest) {
|
||||
PRO.opposeWinding = function(poly, toLongest) {
|
||||
if (toLongest && this.length > poly.length) {
|
||||
poly.opposeWinding(this, false);
|
||||
} else if (this.isClockwise() === poly.isClockwise()) {
|
||||
|
|
@ -511,7 +511,7 @@ var gs_base_polygon = exports;
|
|||
* reverse direction of polygon points.
|
||||
* @returns {Polygon} self
|
||||
*/
|
||||
PlP.reverse = function() {
|
||||
PRO.reverse = function() {
|
||||
this.area2 = -this.area2;
|
||||
this.points = this.points.reverse();
|
||||
return this;
|
||||
|
|
@ -523,7 +523,7 @@ var gs_base_polygon = exports;
|
|||
* @param {Polygon} parent
|
||||
* @returns {boolean}
|
||||
*/
|
||||
PlP.isNested = function(parent) {
|
||||
PRO.isNested = function(parent) {
|
||||
if (parent.bounds.contains(this.bounds)) {
|
||||
//var int = POLY().rayIntersect(this.bounds.leftMost, nest_test_slope, [parent], false);
|
||||
//return int.length % 2 === 1 || this.isInside(parent, CONF.precision_nested_sq);
|
||||
|
|
@ -532,7 +532,7 @@ var gs_base_polygon = exports;
|
|||
return false;
|
||||
};
|
||||
|
||||
PlP.forEachPointEaseDown = function(fn, fromPoint) {
|
||||
PRO.forEachPointEaseDown = function(fn, fromPoint) {
|
||||
var index = this.findClosestPointTo(fromPoint).index,
|
||||
fromZ = fromPoint.z,
|
||||
offset = 0,
|
||||
|
|
@ -573,7 +573,7 @@ var gs_base_polygon = exports;
|
|||
return last;
|
||||
};
|
||||
|
||||
PlP.forEachPoint = function(fn, close, start) {
|
||||
PRO.forEachPoint = function(fn, close, start) {
|
||||
var index = start || 0,
|
||||
points = this.points,
|
||||
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,
|
||||
points = this.points,
|
||||
length = points.length,
|
||||
|
|
@ -606,7 +606,7 @@ var gs_base_polygon = exports;
|
|||
/**
|
||||
* returns intersections sorted by closest to lp1
|
||||
*/
|
||||
PlP.intersections = function(lp1, lp2) {
|
||||
PRO.intersections = function(lp1, lp2) {
|
||||
var list = [];
|
||||
this.forEachSegment(function(pp1, pp2, ip1, ip2) {
|
||||
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
|
||||
*/
|
||||
PlP.emitSegment = function(i1, i2) {
|
||||
PRO.emitSegment = function(i1, i2) {
|
||||
var poly = newPolygon(),
|
||||
start = i1.p2.pos,
|
||||
end = i2.p1.pos,
|
||||
|
|
@ -648,7 +648,7 @@ var gs_base_polygon = exports;
|
|||
* @param {number} [tolerance]
|
||||
* @returns {boolean} any points inside OR on edge
|
||||
*/
|
||||
PlP.hasPointsInside = function(poly, tolerance) {
|
||||
PRO.hasPointsInside = function(poly, tolerance) {
|
||||
if (!poly.overlaps(this)) return false;
|
||||
|
||||
var mid, exit = false;
|
||||
|
|
@ -676,7 +676,7 @@ var gs_base_polygon = exports;
|
|||
* @param {number} [tolerance]
|
||||
* @returns {boolean} all points inside OR on edge
|
||||
*/
|
||||
PlP.isInside = function(poly, tolerance) {
|
||||
PRO.isInside = function(poly, tolerance) {
|
||||
// throw new Error("isInside");
|
||||
if (!(
|
||||
// poly.overlaps(this) &&
|
||||
|
|
@ -710,7 +710,7 @@ var gs_base_polygon = exports;
|
|||
* @param {number} [tolerance]
|
||||
* @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));
|
||||
};
|
||||
|
||||
|
|
@ -719,7 +719,7 @@ var gs_base_polygon = exports;
|
|||
* @param polys
|
||||
* @returns {boolean}
|
||||
*/
|
||||
PlP.containedBySet = function(polys) {
|
||||
PRO.containedBySet = function(polys) {
|
||||
if (!polys) return false;
|
||||
for (var i=0; i<polys.length; i++) {
|
||||
if (polys[i].contains(this)) return true;
|
||||
|
|
@ -731,7 +731,7 @@ var gs_base_polygon = exports;
|
|||
* @param {Polygon} child
|
||||
* @returns {Polygon} self
|
||||
*/
|
||||
PlP.addInner = function(child) {
|
||||
PRO.addInner = function(child) {
|
||||
child.parent = this;
|
||||
if (this.inner) {
|
||||
this.inner.push(child);
|
||||
|
|
@ -744,14 +744,14 @@ var gs_base_polygon = exports;
|
|||
/**
|
||||
* @returns {number} number of inner polygons
|
||||
*/
|
||||
PlP.innerCount = function() {
|
||||
PRO.innerCount = function() {
|
||||
return this.inner ? this.inner.length : 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {boolean} if has 1 or more inner polygons
|
||||
*/
|
||||
PlP.hasInner = function() {
|
||||
PRO.hasInner = function() {
|
||||
return this.inner && this.inner.length > 0;
|
||||
};
|
||||
|
||||
|
|
@ -759,12 +759,12 @@ var gs_base_polygon = exports;
|
|||
* remove all inner polygons
|
||||
* @returns {Polygon} self
|
||||
*/
|
||||
PlP.clearInner = function() {
|
||||
PRO.clearInner = function() {
|
||||
this.inner = null;
|
||||
return this;
|
||||
};
|
||||
|
||||
PlP.newUndeleted = function() {
|
||||
PRO.newUndeleted = function() {
|
||||
var poly = newPolygon();
|
||||
this.forEachPoint(function(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
|
||||
* @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());
|
||||
};
|
||||
|
||||
PlP.circularityDeep = function() {
|
||||
PRO.circularityDeep = function() {
|
||||
return (4 * PI * this.areaDeep()) / UTIL.sqr(this.perimeter());
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {number} perimeter length (sum of all segment lengths)
|
||||
*/
|
||||
PlP.perimeter = function() {
|
||||
PRO.perimeter = function() {
|
||||
var len = 0.0;
|
||||
|
||||
this.forEachSegment(function(prev,next) {
|
||||
|
|
@ -797,7 +797,7 @@ var gs_base_polygon = exports;
|
|||
return len;
|
||||
};
|
||||
|
||||
PlP.perimeterDeep = function() {
|
||||
PRO.perimeterDeep = function() {
|
||||
var len = this.perimeter();
|
||||
if (this.inner) this.inner.forEach(function(p) { len += p.perimeter() });
|
||||
return len;
|
||||
|
|
@ -811,7 +811,7 @@ var gs_base_polygon = exports;
|
|||
* @param {boolean} [raw]
|
||||
* @returns {number} area
|
||||
*/
|
||||
PlP.area = function(raw) {
|
||||
PRO.area = function(raw) {
|
||||
if (this.length < 3) return 0;
|
||||
if (this.area2 === 0.0) {
|
||||
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
|
||||
*/
|
||||
PlP.areaDeep = function() {
|
||||
PRO.areaDeep = function() {
|
||||
if (!this.inner) return this.area();
|
||||
var i, c = this.inner, a = this.area();
|
||||
for (i=0; i<c.length; i++) {
|
||||
|
|
@ -842,7 +842,7 @@ var gs_base_polygon = exports;
|
|||
* @param {Polygon} poly
|
||||
* @returns {boolean}
|
||||
*/
|
||||
PlP.overlaps = function(poly) {
|
||||
PRO.overlaps = function(poly) {
|
||||
return this.bounds.overlaps(poly.bounds, CONF.precision_merge);
|
||||
};
|
||||
|
||||
|
|
@ -852,7 +852,7 @@ var gs_base_polygon = exports;
|
|||
* @param {number[]} arr
|
||||
* @param {number} [z]
|
||||
*/
|
||||
PlP.fromXYArray = function(arr,z) {
|
||||
PRO.fromXYArray = function(arr,z) {
|
||||
var i = 0;
|
||||
while (i < arr.length) {
|
||||
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
|
||||
* non-nested polygons. used primarily in slicer/connectLines.
|
||||
*/
|
||||
PlP.clean = function() {
|
||||
PRO.clean = function() {
|
||||
var clib = self.ClipperLib,
|
||||
clip = clib.Clipper,
|
||||
clean = clip.CleanPolygon(this.toClipper()[0], CONF.clipperClean),
|
||||
|
|
@ -878,7 +878,7 @@ var gs_base_polygon = exports;
|
|||
return poly;
|
||||
};
|
||||
|
||||
PlP.toClipper = function(inout,debug) {
|
||||
PRO.toClipper = function(inout,debug) {
|
||||
var poly = this,
|
||||
cur = [],
|
||||
out = inout || [];
|
||||
|
|
@ -908,7 +908,7 @@ var gs_base_polygon = exports;
|
|||
/**
|
||||
* todo for debugging
|
||||
*/
|
||||
PlP.dump = function(msg,prec) {
|
||||
PRO.dump = function(msg,prec) {
|
||||
var scope = this,
|
||||
txt = [JSON.stringify({
|
||||
len:scope.length,
|
||||
|
|
@ -941,7 +941,7 @@ var gs_base_polygon = exports;
|
|||
* @param {Polygon[]} [output]
|
||||
* @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);
|
||||
};
|
||||
|
||||
|
|
@ -954,7 +954,7 @@ var gs_base_polygon = exports;
|
|||
* @param {number} [precision]
|
||||
* @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");
|
||||
var debug = DBUG.get('circularity');
|
||||
if (debug) {
|
||||
|
|
@ -1023,7 +1023,7 @@ var gs_base_polygon = exports;
|
|||
* @param {Point} target
|
||||
* @return {Object} {point:point, distance:distance}
|
||||
*/
|
||||
PlP.findClosestPointTo = function(target) {
|
||||
PRO.findClosestPointTo = function(target) {
|
||||
var dist,
|
||||
index,
|
||||
closest,
|
||||
|
|
@ -1045,7 +1045,7 @@ var gs_base_polygon = exports;
|
|||
* @param {Polygon[]} out
|
||||
* @returns {Polygon[]}
|
||||
*/
|
||||
PlP.flattenTo = function(out) {
|
||||
PRO.flattenTo = function(out) {
|
||||
out.push(this);
|
||||
if (this.inner) out.appendAll(this.inner);
|
||||
return out;
|
||||
|
|
@ -1055,7 +1055,7 @@ var gs_base_polygon = exports;
|
|||
* @param {Polygon} poly clipping mask
|
||||
* @returns {?Polygon[]}
|
||||
*/
|
||||
PlP.diff = function(poly) {
|
||||
PRO.diff = function(poly) {
|
||||
var fillang = this.fillang && this.area() > poly.area() ? this.fillang : poly.fillang,
|
||||
clib = self.ClipperLib,
|
||||
ctyp = clib.ClipType,
|
||||
|
|
@ -1084,7 +1084,7 @@ var gs_base_polygon = exports;
|
|||
* @param {Polygon} poly clipping mask
|
||||
* @returns {?Polygon[]}
|
||||
*/
|
||||
PlP.mask = function(poly) {
|
||||
PRO.mask = function(poly) {
|
||||
var fillang = this.fillang && this.area() > poly.area() ? this.fillang : poly.fillang,
|
||||
clib = self.ClipperLib,
|
||||
ctyp = clib.ClipType,
|
||||
|
|
@ -1115,7 +1115,7 @@ var gs_base_polygon = exports;
|
|||
* @param {Polygon} poly
|
||||
* @returns {?Polygon} intersected polygon or null if no intersection
|
||||
*/
|
||||
PlP.union = function(poly) {
|
||||
PRO.union = function(poly) {
|
||||
if (!this.overlaps(poly)) return null;
|
||||
|
||||
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
|
||||
* furthest apart and lowest when there is a tie breaker
|
||||
*/
|
||||
PlP.spread = function() {
|
||||
PRO.spread = function() {
|
||||
var poly = this,
|
||||
points = poly.points,
|
||||
plen = points.length,
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ var gs_base_slope = exports;
|
|||
var BASE = self.base,
|
||||
CONF = BASE.config,
|
||||
ABS = Math.abs,
|
||||
SlP = Slope.prototype,
|
||||
PRO = Slope.prototype,
|
||||
DEG2RAD = Math.PI / 180,
|
||||
RAD2DEG = 180 / Math.PI;
|
||||
|
||||
|
|
@ -44,7 +44,7 @@ var gs_base_slope = exports;
|
|||
* Slope Prototype Functions
|
||||
******************************************************************* */
|
||||
|
||||
SlP.toString = function() {
|
||||
PRO.toString = function() {
|
||||
return [this.dx, this.dy, this.angle].join(',');
|
||||
};
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ var gs_base_slope = exports;
|
|||
* @param {Slope} s
|
||||
* @returns {boolean}
|
||||
*/
|
||||
SlP.isSame = function(s) {
|
||||
PRO.isSame = function(s) {
|
||||
// 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.dy) <= CONF.precision_merge && ABS(s.dy) <= CONF.precision_merge) return true;
|
||||
|
|
@ -66,7 +66,7 @@ var gs_base_slope = exports;
|
|||
*
|
||||
* @returns {Slope}
|
||||
*/
|
||||
SlP.normal = function() {
|
||||
PRO.normal = function() {
|
||||
var t = this.dx;
|
||||
this.dx = -this.dy;
|
||||
this.dy = t;
|
||||
|
|
@ -74,14 +74,14 @@ var gs_base_slope = exports;
|
|||
return this;
|
||||
};
|
||||
|
||||
SlP.toUnit = function() {
|
||||
PRO.toUnit = function() {
|
||||
var max = Math.max(ABS(this.dx), ABS(this.dy));
|
||||
this.dx = this.dx / max;
|
||||
this.dy = this.dy / max;
|
||||
return this;
|
||||
};
|
||||
|
||||
SlP.factor = function(f) {
|
||||
PRO.factor = function(f) {
|
||||
this.dx *= f;
|
||||
this.dy *= f;
|
||||
return this;
|
||||
|
|
@ -92,7 +92,7 @@ var gs_base_slope = exports;
|
|||
*
|
||||
* @returns {Slope}
|
||||
*/
|
||||
SlP.invert = function() {
|
||||
PRO.invert = function() {
|
||||
this.dx = -this.dx;
|
||||
this.dy = -this.dy;
|
||||
this.angle = 360 - this.angle;//Math.atan2(this.dy, this.dx) * RAD2DEG;
|
||||
|
|
|
|||
11
js/geo.js
11
js/geo.js
|
|
@ -10,7 +10,6 @@ var gs_base = exports;
|
|||
if (self.base.util) return;
|
||||
|
||||
var BASE = self.base,
|
||||
ABS = Math.abs,
|
||||
round_decimal_precision = 8;
|
||||
|
||||
/** ******************************************************************
|
||||
|
|
@ -93,7 +92,7 @@ var gs_base = exports;
|
|||
* @returns {boolean}
|
||||
*/
|
||||
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}
|
||||
*/
|
||||
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
|
||||
d = (d2y * d1x) - (d2x * d1y); // det
|
||||
|
||||
//if (ABS(d) < 0.0000000001) {
|
||||
if (ABS(d) < 0.0001) {
|
||||
//if (Math.abs(d) < 0.0000000001) {
|
||||
if (Math.abs(d) < 0.0001) {
|
||||
// lines are parallel or collinear
|
||||
return test && !parallelok ? null : keys.PARALLEL;
|
||||
}
|
||||
|
|
@ -259,7 +258,7 @@ var gs_base = exports;
|
|||
n1 = (s2x * a) - (s2y * b),
|
||||
n2 = (s1x * a) - (s1y * b);
|
||||
|
||||
if (ABS(d) < 0.000000000001) {
|
||||
if (Math.abs(d) < 0.000000000001) {
|
||||
// lines are parallel or collinear
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -365,7 +365,7 @@ var gs_kiri_fdm = exports;
|
|||
// for flashforge finder that uses cumulative extruder position
|
||||
o.append(" E").append(UTIL.round(outputLength, decimals));
|
||||
} else {
|
||||
o.append(" E").append(UTIL.round(newpos.e,decimals));
|
||||
o.append(" E").append(UTIL.round(newpos.e, decimals));
|
||||
}
|
||||
}
|
||||
if (rate && rate != pos.f) {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ var gs_kiri_print = exports;
|
|||
POLY = BASE.polygons,
|
||||
SQRT = Math.sqrt,
|
||||
PI = Math.PI,
|
||||
PROTO = Print.prototype,
|
||||
PRO = Print.prototype,
|
||||
Polygon = BASE.Polygon,
|
||||
newPoint = BASE.newPoint;
|
||||
|
||||
|
|
@ -46,15 +46,15 @@ var gs_kiri_print = exports;
|
|||
this.bounds = null;
|
||||
}
|
||||
|
||||
PROTO.newOut = newOut;
|
||||
PROTO.tip2tipEmit = tip2tipEmit;
|
||||
PROTO.extrudePerMM = extrudePerMM;
|
||||
PROTO.constReplace = constReplace;
|
||||
PROTO.poly2polyEmit = poly2polyEmit;
|
||||
PROTO.addPrintPoints = addPrintPoints;
|
||||
PROTO.poly2polyDepthFirstEmit = poly2polyDepthFirstEmit;
|
||||
PRO.newOut = newOut;
|
||||
PRO.tip2tipEmit = tip2tipEmit;
|
||||
PRO.extrudePerMM = extrudePerMM;
|
||||
PRO.constReplace = constReplace;
|
||||
PRO.poly2polyEmit = poly2polyEmit;
|
||||
PRO.addPrintPoints = addPrintPoints;
|
||||
PRO.poly2polyDepthFirstEmit = poly2polyDepthFirstEmit;
|
||||
|
||||
PROTO.parseGCode = function(gcode, offset) {
|
||||
PRO.parseGCode = function(gcode, offset) {
|
||||
var lines = gcode
|
||||
.toUpperCase()
|
||||
.replace("X", " X")
|
||||
|
|
@ -136,7 +136,7 @@ var gs_kiri_print = exports;
|
|||
scope.bytes = gcode.length;
|
||||
};
|
||||
|
||||
PROTO.setup = function(remote, onupdate, ondone) {
|
||||
PRO.setup = function(remote, onupdate, ondone) {
|
||||
var scope = this,
|
||||
settings = scope.settings,
|
||||
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,
|
||||
settings = scope.settings,
|
||||
mode = settings.mode;
|
||||
|
|
@ -184,19 +184,19 @@ var gs_kiri_print = exports;
|
|||
}
|
||||
};
|
||||
|
||||
PROTO.exportLaserGCode = function() {
|
||||
PRO.exportLaserGCode = function() {
|
||||
return KIRI.driver.LASER.exportGCode(this);
|
||||
};
|
||||
|
||||
PROTO.exportSVG = function() {
|
||||
PRO.exportSVG = function() {
|
||||
return KIRI.driver.LASER.exportSVG(this);
|
||||
};
|
||||
|
||||
PROTO.exportDXF = function() {
|
||||
PRO.exportDXF = function() {
|
||||
return KIRI.driver.LASER.exportDXF(this);
|
||||
};
|
||||
|
||||
PROTO.encodeOutput = function() {
|
||||
PRO.encodeOutput = function() {
|
||||
var newout = [], newlayer;
|
||||
|
||||
this.output.forEach(function(layerout) {
|
||||
|
|
@ -209,7 +209,7 @@ var gs_kiri_print = exports;
|
|||
return newout;
|
||||
};
|
||||
|
||||
PROTO.render = function() {
|
||||
PRO.render = function() {
|
||||
var scope = this,
|
||||
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;
|
||||
// render layered output
|
||||
scope.lines = 0;
|
||||
|
|
@ -257,17 +257,17 @@ var gs_kiri_print = exports;
|
|||
});
|
||||
}
|
||||
|
||||
PROTO.getLayerCount = function() {
|
||||
PRO.getLayerCount = function() {
|
||||
return this.output.length;
|
||||
}
|
||||
|
||||
PROTO.hide = function() {
|
||||
PRO.hide = function() {
|
||||
this.layerView.forEach(function(layer) {
|
||||
layer.setVisible(false);
|
||||
})
|
||||
};
|
||||
|
||||
PROTO.showLayer = function(index, show) {
|
||||
PRO.showLayer = function(index, show) {
|
||||
if (this.layerView[index]) this.layerView[index].setVisible(show);
|
||||
};
|
||||
|
||||
|
|
@ -300,7 +300,7 @@ var gs_kiri_print = exports;
|
|||
* @param {number} [extrude] wipe distance
|
||||
* @return {Point} last output point
|
||||
*/
|
||||
PROTO.polyPrintPath = function(poly, startPoint, output, extrude, wipe) {
|
||||
PRO.polyPrintPath = function(poly, startPoint, output, extrude, wipe) {
|
||||
// poly.setClosed();
|
||||
poly.setClockwise();
|
||||
|
||||
|
|
@ -350,7 +350,7 @@ var gs_kiri_print = exports;
|
|||
* @param {boolean} isFDM controls whether we emit wipe or not
|
||||
* @return {Point} last output point
|
||||
*/
|
||||
PROTO.slicePrintPath = function(slice, startPoint, offset, output, isFDM) {
|
||||
PRO.slicePrintPath = function(slice, startPoint, offset, output, isFDM) {
|
||||
var i,
|
||||
preout = [],
|
||||
scope = this,
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ var gs_kiri_slice = exports;
|
|||
UTIL = BASE.util,
|
||||
DBUG = BASE.debug,
|
||||
POLY = BASE.polygons,
|
||||
SiP = Slice.prototype,
|
||||
PRO = Slice.prototype,
|
||||
fillArea = POLY.fillArea,
|
||||
newPoint = BASE.newPoint,
|
||||
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
|
||||
*/
|
||||
SiP.clone = function(deep) {
|
||||
PRO.clone = function(deep) {
|
||||
var from = this,
|
||||
slice = newSlice(from.z, from.view);
|
||||
from.tops.forEach(function(top) {
|
||||
|
|
@ -130,7 +130,7 @@ var gs_kiri_slice = exports;
|
|||
*
|
||||
* @param {THREE.Group} view
|
||||
*/
|
||||
SiP.addLayers = function(view) {
|
||||
PRO.addLayers = function(view) {
|
||||
if (this.layers) return;
|
||||
|
||||
// create views client side only
|
||||
|
|
@ -154,7 +154,7 @@ var gs_kiri_slice = exports;
|
|||
*
|
||||
* @param {Polygon} poly to merge into a top
|
||||
*/
|
||||
SiP.mergeTop = function(poly) {
|
||||
PRO.mergeTop = function(poly) {
|
||||
var scope = this,
|
||||
tops = scope.tops,
|
||||
union, i;
|
||||
|
|
@ -172,7 +172,7 @@ var gs_kiri_slice = exports;
|
|||
*
|
||||
* @param {Polygon} poly to add
|
||||
*/
|
||||
SiP.addTop = function(poly) {
|
||||
PRO.addTop = function(poly) {
|
||||
var top = new Top(poly);
|
||||
this.tops.push(top);
|
||||
return top;
|
||||
|
|
@ -184,7 +184,7 @@ var gs_kiri_slice = exports;
|
|||
* @param {Polygon[]} out array to populate
|
||||
* @returns {Polygon[]} array of top polygons
|
||||
*/
|
||||
SiP.gatherTopPolys = function(out) {
|
||||
PRO.gatherTopPolys = function(out) {
|
||||
this.tops.forEach(function(top) {
|
||||
out.push(top.poly);
|
||||
});
|
||||
|
|
@ -198,7 +198,7 @@ var gs_kiri_slice = exports;
|
|||
* @param {Polygon[]} out array to populate
|
||||
* @returns {Polygon[]} array of top polygons
|
||||
*/
|
||||
SiP.gatherTopPolyInners = function(out) {
|
||||
PRO.gatherTopPolyInners = function(out) {
|
||||
this.tops.forEach(function(top) {
|
||||
if (top.poly.inner) out.appendAll(top.poly.inner);
|
||||
});
|
||||
|
|
@ -211,7 +211,7 @@ var gs_kiri_slice = exports;
|
|||
* @param {Polygon[]} out array to populate
|
||||
* @returns {Polygon[]} array of top polygons
|
||||
*/
|
||||
SiP.gatherTraces = function(out) {
|
||||
PRO.gatherTraces = function(out) {
|
||||
this.tops.forEach(function(top) {
|
||||
out.appendAll(top.traces);
|
||||
});
|
||||
|
|
@ -224,7 +224,7 @@ var gs_kiri_slice = exports;
|
|||
* @param {Polygon[]} out array to populate
|
||||
* @returns {Polygon[]} array of top polygons
|
||||
*/
|
||||
SiP.gatherInner = function(out) {
|
||||
PRO.gatherInner = function(out) {
|
||||
this.tops.forEach(function(top) {
|
||||
out.appendAll(top.inner);
|
||||
});
|
||||
|
|
@ -237,7 +237,7 @@ var gs_kiri_slice = exports;
|
|||
* @param {Polygon[]} out array to populate
|
||||
* @returns {Polygon[]} array of top polygons
|
||||
*/
|
||||
SiP.gatherOuter = function(out) {
|
||||
PRO.gatherOuter = function(out) {
|
||||
this.tops.forEach(function(top) {
|
||||
out.appendAll(top.outer);
|
||||
});
|
||||
|
|
@ -250,7 +250,7 @@ var gs_kiri_slice = exports;
|
|||
* @param {Polygon[]} out array to populate
|
||||
* @returns {Polygon[]} array of top polygons
|
||||
*/
|
||||
SiP.gatherSolids = function(out) {
|
||||
PRO.gatherSolids = function(out) {
|
||||
this.tops.forEach(function(top) {
|
||||
out.appendAll(top.solids);
|
||||
});
|
||||
|
|
@ -263,7 +263,7 @@ var gs_kiri_slice = exports;
|
|||
*
|
||||
* @param {Point[]} [lines] array to append to
|
||||
*/
|
||||
SiP.gatherFillLines = function(lines) {
|
||||
PRO.gatherFillLines = function(lines) {
|
||||
this.tops.forEach(function(top) {
|
||||
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
|
||||
*/
|
||||
SiP.invalidateSolids = function() {
|
||||
PRO.invalidateSolids = function() {
|
||||
var solids = this.solids;
|
||||
solids.poly = [];
|
||||
solids.trimmed = null;
|
||||
|
|
@ -282,7 +282,7 @@ var gs_kiri_slice = exports;
|
|||
/**
|
||||
* Clear support cache in preparation for a new slicing calculation
|
||||
*/
|
||||
SiP.invalidateSupports = function() {
|
||||
PRO.invalidateSupports = function() {
|
||||
this.supports = null;
|
||||
};
|
||||
|
||||
|
|
@ -291,7 +291,7 @@ var gs_kiri_slice = exports;
|
|||
*
|
||||
* @param {number} renderMode
|
||||
*/
|
||||
SiP.renderOutline = function(renderMode) {
|
||||
PRO.renderOutline = function(renderMode) {
|
||||
if (!this.view) return;
|
||||
|
||||
var process = KIRI.driver.CAM.process,
|
||||
|
|
@ -362,7 +362,7 @@ var gs_kiri_slice = exports;
|
|||
* @param {number} offsetN all subsequent offsets
|
||||
* @param {number} fillOffset
|
||||
*/
|
||||
SiP.doShells = function(count, offset1, offsetN, fillOffset, vase) {
|
||||
PRO.doShells = function(count, offset1, offsetN, fillOffset, vase) {
|
||||
var slice = this;
|
||||
|
||||
slice.tops.forEach(function(top) {
|
||||
|
|
@ -398,7 +398,7 @@ var gs_kiri_slice = exports;
|
|||
*
|
||||
* @param {number} renderMode
|
||||
*/
|
||||
SiP.renderShells = function(renderMode) {
|
||||
PRO.renderShells = function(renderMode) {
|
||||
var scope = this,
|
||||
layers = scope.layers,
|
||||
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
|
||||
*/
|
||||
SiP.invalidateFill = function() {
|
||||
PRO.invalidateFill = function() {
|
||||
this.tops.forEach(function(top) {
|
||||
top.fill_lines = null;
|
||||
top.fill_sparse = null;
|
||||
|
|
@ -452,7 +452,7 @@ var gs_kiri_slice = exports;
|
|||
*
|
||||
* @param {number} minDist
|
||||
*/
|
||||
SiP.doThinWallDetection = function(mindist) {
|
||||
PRO.doThinWallDetection = function(mindist) {
|
||||
this.tops.forEach(function(top) {
|
||||
if (top.inner && top.inner.length > 0) {
|
||||
// using next line2line algo from print lib
|
||||
|
|
@ -468,7 +468,7 @@ var gs_kiri_slice = exports;
|
|||
* @param {number} angle
|
||||
* @param {number} density
|
||||
*/
|
||||
SiP.doSolidLayerFill = function(linewidth, angle, density) {
|
||||
PRO.doSolidLayerFill = function(linewidth, angle, density) {
|
||||
this.isSolidFill = false;
|
||||
|
||||
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.
|
||||
*/
|
||||
SiP.renderSolidFill = function() {
|
||||
PRO.renderSolidFill = function() {
|
||||
var layer = this.layers.fill,
|
||||
render;
|
||||
|
||||
|
|
@ -515,7 +515,7 @@ var gs_kiri_slice = exports;
|
|||
* @param {number} percent infill 0.0 - 1.0
|
||||
* @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;
|
||||
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.
|
||||
*/
|
||||
SiP.renderSparseFill = function() {
|
||||
PRO.renderSparseFill = function() {
|
||||
var layer = this.layers.sparse;
|
||||
|
||||
layer.clear();
|
||||
|
|
@ -601,7 +601,7 @@ var gs_kiri_slice = exports;
|
|||
* Find difference between fill inset poly on two adjacent layers.
|
||||
* Used to calculate bridges, flats and then solid projections.
|
||||
*/
|
||||
SiP.doDiff = function(minArea) {
|
||||
PRO.doDiff = function(minArea) {
|
||||
if (!this.down) return;
|
||||
|
||||
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.
|
||||
*/
|
||||
SiP.renderDiff = function() {
|
||||
PRO.renderDiff = function() {
|
||||
var scope = this,
|
||||
layers = scope.layers,
|
||||
bridgeLayer = layers.bridge,
|
||||
|
|
@ -657,14 +657,14 @@ var gs_kiri_slice = exports;
|
|||
*
|
||||
* @param {Polygon[]} polys
|
||||
*/
|
||||
SiP.addSolidFills = function(polys) {
|
||||
PRO.addSolidFills = function(polys) {
|
||||
this.solids.poly.appendAll(polys);
|
||||
};
|
||||
|
||||
/**
|
||||
* project bottom flats down
|
||||
*/
|
||||
SiP.projectFlats = function(count) {
|
||||
PRO.projectFlats = function(count) {
|
||||
if (this.isSolidFill || !this.down || !this.flats) return;
|
||||
projectSolid(this, this.flats, count, false, true);
|
||||
};
|
||||
|
|
@ -672,7 +672,7 @@ var gs_kiri_slice = exports;
|
|||
/**
|
||||
* project top bridges up
|
||||
*/
|
||||
SiP.projectBridges = function(count) {
|
||||
PRO.projectBridges = function(count) {
|
||||
if (this.isSolidFill || !this.up || !this.bridges) return;
|
||||
projectSolid(this, this.bridges, count, true, true);
|
||||
};
|
||||
|
|
@ -681,7 +681,7 @@ var gs_kiri_slice = exports;
|
|||
* fill projected areas and store line data
|
||||
* @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,
|
||||
scope = this,
|
||||
|
|
@ -769,7 +769,7 @@ var gs_kiri_slice = exports;
|
|||
return true;
|
||||
};
|
||||
|
||||
SiP.renderSolidOutlines = function() {
|
||||
PRO.renderSolidOutlines = function() {
|
||||
var layer = this.layers.solid,
|
||||
trimmed = this.solids.trimmed;
|
||||
|
||||
|
|
@ -791,7 +791,7 @@ var gs_kiri_slice = exports;
|
|||
* @param {number} expand outer 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,
|
||||
size = (pillarSize || 2),
|
||||
mergeDist = size * 3, // pillar merge dist
|
||||
|
|
@ -919,7 +919,7 @@ var gs_kiri_slice = exports;
|
|||
* @param {number} density
|
||||
* @param {number} offset
|
||||
*/
|
||||
SiP.doSupportFill = function(linewidth, density, minArea) {
|
||||
PRO.doSupportFill = function(linewidth, density, minArea) {
|
||||
// return;
|
||||
var slice = this,
|
||||
supports = slice.supports,
|
||||
|
|
@ -965,7 +965,7 @@ var gs_kiri_slice = exports;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
SiP.renderSupport = function() {
|
||||
PRO.renderSupport = function() {
|
||||
var slice = this,
|
||||
layer = slice.layers.support,
|
||||
supports = slice.supports;
|
||||
|
|
@ -987,7 +987,7 @@ var gs_kiri_slice = exports;
|
|||
* @param {Point} target
|
||||
* @return {Object}
|
||||
*/
|
||||
SiP.findClosestPointTo = function(target) {
|
||||
PRO.findClosestPointTo = function(target) {
|
||||
var min, find;
|
||||
|
||||
this.tops.forEach(function(top) {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ var gs_kiri_widget = exports;
|
|||
newPolygon = BASE.newPolygon,
|
||||
newOrderedLine = BASE.newOrderedLine,
|
||||
time = UTIL.time,
|
||||
WP = Widget.prototype,
|
||||
PRO = Widget.prototype,
|
||||
solid_opacity = 1.0,
|
||||
nextId = 0;
|
||||
|
||||
|
|
@ -227,7 +227,7 @@ var gs_kiri_widget = exports;
|
|||
* Widget Prototype Functions
|
||||
******************************************************************* */
|
||||
|
||||
WP.saveToCatalog = function(filename) {
|
||||
PRO.saveToCatalog = function(filename) {
|
||||
var widget = this;
|
||||
var time = UTIL.time();
|
||||
KIRI.catalog.putFile(filename, this.getGeoVertices(), function(vertices) {
|
||||
|
|
@ -239,7 +239,7 @@ var gs_kiri_widget = exports;
|
|||
return this;
|
||||
};
|
||||
|
||||
WP.saveState = function(ondone) {
|
||||
PRO.saveState = function(ondone) {
|
||||
var widget = this;
|
||||
KIRI.odb.put('ws-save-'+this.id, {geo:widget.getGeoVertices(), orient:widget.orient}, function(result) {
|
||||
widget.saved = time();
|
||||
|
|
@ -247,7 +247,7 @@ var gs_kiri_widget = exports;
|
|||
});
|
||||
};
|
||||
|
||||
WP.encodeSlices = function() {
|
||||
PRO.encodeSlices = function() {
|
||||
var encoded = [];
|
||||
if (this.slices) this.slices.forEach(function(slice) {
|
||||
encoded.push(slice.encode());
|
||||
|
|
@ -255,7 +255,7 @@ var gs_kiri_widget = exports;
|
|||
return encoded;
|
||||
};
|
||||
|
||||
WP.decodeSlices = function(encoded) {
|
||||
PRO.decodeSlices = function(encoded) {
|
||||
this.slices = KIRI.codec.decode(encoded, { mesh:this.mesh });
|
||||
};
|
||||
|
||||
|
|
@ -264,7 +264,7 @@ var gs_kiri_widget = exports;
|
|||
* @param {Float32Array} vertices
|
||||
* @returns {Widget}
|
||||
*/
|
||||
WP.loadVertices = function(vertices) {
|
||||
PRO.loadVertices = function(vertices) {
|
||||
if (this.mesh) {
|
||||
this.mesh.geometry.addAttribute('position', new THREE.BufferAttribute(vertices, 3));
|
||||
this.mesh.geometry.computeFaceNormals();
|
||||
|
|
@ -282,7 +282,7 @@ var gs_kiri_widget = exports;
|
|||
* @param {THREE.Geometry} geometry
|
||||
* @returns {Widget}
|
||||
*/
|
||||
WP.loadGeometry = function(geometry) {
|
||||
PRO.loadGeometry = function(geometry) {
|
||||
var mesh = new THREE.Mesh(
|
||||
geometry,
|
||||
new THREE.MeshPhongMaterial({
|
||||
|
|
@ -312,7 +312,7 @@ var gs_kiri_widget = exports;
|
|||
* @param {Point[]} points
|
||||
* @returns {Widget}
|
||||
*/
|
||||
WP.setPoints = function(points) {
|
||||
PRO.setPoints = function(points) {
|
||||
this.points = points || null;
|
||||
return this;
|
||||
};
|
||||
|
|
@ -320,7 +320,7 @@ var gs_kiri_widget = exports;
|
|||
/**
|
||||
* remove slice data and their views
|
||||
*/
|
||||
WP.clearSlices = function() {
|
||||
PRO.clearSlices = function() {
|
||||
var slices = this.slices,
|
||||
mesh = this.mesh;
|
||||
if (slices) {
|
||||
|
|
@ -334,7 +334,7 @@ var gs_kiri_widget = exports;
|
|||
/**
|
||||
* @param {number} color
|
||||
*/
|
||||
WP.setColor = function(color) {
|
||||
PRO.setColor = function(color) {
|
||||
var material = this.mesh.material;
|
||||
material.color.set(color);
|
||||
};
|
||||
|
|
@ -342,7 +342,7 @@ var gs_kiri_widget = exports;
|
|||
/**
|
||||
* @param {number} value
|
||||
*/
|
||||
WP.setOpacity = function(value) {
|
||||
PRO.setOpacity = function(value) {
|
||||
var mesh = this.mesh;
|
||||
if (value <= 0.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
|
||||
*/
|
||||
WP.center = function() {
|
||||
PRO.center = function() {
|
||||
var i = 0,
|
||||
mesh = this.mesh,
|
||||
geo = mesh.geometry,
|
||||
|
|
@ -391,7 +391,7 @@ var gs_kiri_widget = exports;
|
|||
*
|
||||
* @param {number} z position
|
||||
*/
|
||||
WP.setTopZ = function(z) {
|
||||
PRO.setTopZ = function(z) {
|
||||
var mesh = this.mesh,
|
||||
pos = this.orient.pos;
|
||||
if (z) {
|
||||
|
|
@ -411,7 +411,7 @@ var gs_kiri_widget = exports;
|
|||
* @param {number} z
|
||||
* @param {boolean} abs
|
||||
*/
|
||||
WP.move = function(x, y, z, abs) {
|
||||
PRO.move = function(x, y, z, abs) {
|
||||
var mesh = this.mesh,
|
||||
pos = this.orient.pos;
|
||||
// do not allow moves in pure slice view
|
||||
|
|
@ -438,7 +438,7 @@ var gs_kiri_widget = exports;
|
|||
* @param {number} y
|
||||
* @param {number} z
|
||||
*/
|
||||
WP.scale = function(x, y, z) {
|
||||
PRO.scale = function(x, y, z) {
|
||||
var mesh = this.mesh,
|
||||
scale = this.orient.scale;
|
||||
this.setWireframe(false);
|
||||
|
|
@ -456,7 +456,7 @@ var gs_kiri_widget = exports;
|
|||
* @param {number} y
|
||||
* @param {number} z
|
||||
*/
|
||||
WP.rotate = function(x, y, z) {
|
||||
PRO.rotate = function(x, y, z) {
|
||||
this.setWireframe(false);
|
||||
this.clearSlices();
|
||||
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);
|
||||
};
|
||||
|
||||
WP.mirror = function() {
|
||||
PRO.mirror = function() {
|
||||
this.setWireframe(false);
|
||||
this.clearSlices();
|
||||
var i,
|
||||
|
|
@ -486,11 +486,11 @@ var gs_kiri_widget = exports;
|
|||
o.mirror = !o.mirror;
|
||||
};
|
||||
|
||||
WP.getGeoVertices = function() {
|
||||
PRO.getGeoVertices = function() {
|
||||
return this.mesh.geometry.getAttribute('position').array;
|
||||
};
|
||||
|
||||
WP.getPoints = function() {
|
||||
PRO.getPoints = function() {
|
||||
if (!this.points) {
|
||||
// convert and cache points from geometry vertices
|
||||
this.points = Widget.verticesToPoints(this.getGeoVertices());
|
||||
|
|
@ -498,7 +498,7 @@ var gs_kiri_widget = exports;
|
|||
return this.points;
|
||||
};
|
||||
|
||||
WP.getBoundingBox = function(refresh) {
|
||||
PRO.getBoundingBox = function(refresh) {
|
||||
// if (this.mesh) return this.mesh.getBoundingBox();
|
||||
if (!this.bounds || refresh) {
|
||||
this.bounds = new THREE.Box3();
|
||||
|
|
@ -507,7 +507,7 @@ var gs_kiri_widget = exports;
|
|||
return this.bounds;
|
||||
};
|
||||
|
||||
WP.isModified = function() {
|
||||
PRO.isModified = function() {
|
||||
return this.modified;
|
||||
};
|
||||
|
||||
|
|
@ -525,7 +525,7 @@ var gs_kiri_widget = exports;
|
|||
* @params {Function} [onupdate]
|
||||
* @params {boolean} [remote]
|
||||
*/
|
||||
WP.slice = function(settings, ondone, onupdate, remote) {
|
||||
PRO.slice = function(settings, ondone, onupdate, remote) {
|
||||
var widget = this,
|
||||
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();
|
||||
bounds.max.z += settings.process.camZTopOffset;
|
||||
return bounds;
|
||||
|
|
@ -597,7 +597,7 @@ var gs_kiri_widget = exports;
|
|||
* @param {number} renderMode
|
||||
* @param {boolean} cam mode
|
||||
*/
|
||||
WP.render = function(renderMode, cam) {
|
||||
PRO.render = function(renderMode, cam) {
|
||||
var slices = this.slices;
|
||||
if (!slices) return;
|
||||
// render outline
|
||||
|
|
@ -616,7 +616,7 @@ var gs_kiri_widget = exports;
|
|||
if (!cam) slices.forEach(function(s) { s.renderSupport() });
|
||||
};
|
||||
|
||||
WP.hideSlices = function() {
|
||||
PRO.hideSlices = function() {
|
||||
var showing = false;
|
||||
if (this.slices) this.slices.forEach(function(slice) {
|
||||
showing = showing || slice.view.visible;
|
||||
|
|
@ -625,11 +625,11 @@ var gs_kiri_widget = exports;
|
|||
return showing;
|
||||
};
|
||||
|
||||
WP.toggleWireframe = function (color, opacity) {
|
||||
PRO.toggleWireframe = function (color, opacity) {
|
||||
this.setWireframe(!this.wire, color, opacity);
|
||||
};
|
||||
|
||||
WP.setWireframe = function(set, color, opacity) {
|
||||
PRO.setWireframe = function(set, color, opacity) {
|
||||
var mesh = this.mesh,
|
||||
widget = this;
|
||||
if (this.wire) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue