Skip to content

Commit

Permalink
bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
w8r committed Oct 14, 2014
1 parent 3467c89 commit 04d1f5d
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 80 deletions.
50 changes: 42 additions & 8 deletions dist/greiner-hormann.es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,14 @@ var Intersection = function(s1, s2, c1, c2) {
return;
}

/**
* @type {Number}
*/
this.toSource = ((c2.x - c1.x) * (s1.y - c1.y) - (c2.y - c1.y) * (s1.x - c1.x)) / d;

/**
* @type {Number}
*/
this.toClip = ((s2.x - s1.x) * (s1.y - c1.y) - (s2.y - s1.y) * (s1.x - c1.x)) / d;

if (this.valid()) {
Expand Down Expand Up @@ -210,6 +217,11 @@ var Polygon = function(p) {
*/
this.vertices = 0;

/**
* @type {Vertex}
*/
this._lastUnprocessed = null;

for (var i = 0, len = p.length; i < len; i++) {
this.addVertex(new Vertex(p[i]));
}
Expand Down Expand Up @@ -280,14 +292,17 @@ Polygon.prototype.getNext = function(v) {
* @return {Vertex}
*/
Polygon.prototype.getFirstIntersect = function() {
var v = this.first;
var v = this._firstIntersect || this.first;

do {
if (v._isIntersection && !v._visited) {
break;
}

v = v.next;
} while (!v.equals(this.first));

this._firstIntersect = v;
return v;
};

Expand All @@ -296,14 +311,17 @@ Polygon.prototype.getFirstIntersect = function() {
* @return {Boolean} [description]
*/
Polygon.prototype.hasUnprocessed = function() {
var v = this.first;
var v = this._lastUnprocessed || this.first;
do {
if (v._isIntersection && !v._visited) {
this._lastUnprocessed = v;
return true;
}

v = v.next;
} while (!v.equals(this.first));

this._lastUnprocessed = null;
return false;
};

Expand All @@ -314,10 +332,11 @@ Polygon.prototype.getPoints = function() {
var points = [],
v = this.first;

for (var i = 0; i < this.vertices; i++) {
points[i] = [v.x, v.y];
do {
points.push([v.x, v.y]);
v = v.next;
}
} while (v !== this.first);

return points;
};

Expand All @@ -335,8 +354,10 @@ Polygon.prototype.getPoints = function() {
*/
Polygon.prototype.clip = function(clip, sourceForwards, clipForwards) {
var sourceVertex = this.first,
clipVertex = clip.first;
clipVertex = clip.first,
sourceInClip, clipInSource;

// calculate and mark intersections
do {
if (!sourceVertex._isIntersection) {
do {
Expand Down Expand Up @@ -376,8 +397,12 @@ Polygon.prototype.clip = function(clip, sourceForwards, clipForwards) {
sourceVertex = this.first;
clipVertex = clip.first;

sourceForwards ^= sourceVertex.isInside(clip);
clipForwards ^= clipVertex.isInside(this);
sourceInClip = sourceVertex.isInside(clip);
clipInSource = clipVertex.isInside(this);

sourceForwards ^= sourceInClip;
clipForwards ^= clipInSource;

do {
if (sourceVertex._isIntersection) {
sourceVertex._isEntry = sourceForwards;
Expand Down Expand Up @@ -422,6 +447,15 @@ Polygon.prototype.clip = function(clip, sourceForwards, clipForwards) {
list.push(clipped);
}

if (list.length === 0) {
if (sourceInClip) {
list.push(this);
}
if (clipInSource) {
list.push(this);
}
}

return list;
};
// Router
Expand Down
12 changes: 6 additions & 6 deletions dist/greiner-hormann.es5.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 42 additions & 8 deletions dist/greiner-hormann.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,14 @@ var Intersection = function(s1, s2, c1, c2) {
return;
}

/**
* @type {Number}
*/
this.toSource = ((c2.x - c1.x) * (s1.y - c1.y) - (c2.y - c1.y) * (s1.x - c1.x)) / d;

/**
* @type {Number}
*/
this.toClip = ((s2.x - s1.x) * (s1.y - c1.y) - (s2.y - s1.y) * (s1.x - c1.x)) / d;

if (this.valid()) {
Expand Down Expand Up @@ -215,6 +222,11 @@ var Polygon = function(p) {
*/
this.vertices = 0;

/**
* @type {Vertex}
*/
this._lastUnprocessed = null;

for (var i = 0, len = p.length; i < len; i++) {
this.addVertex(new Vertex(p[i]));
}
Expand Down Expand Up @@ -285,14 +297,17 @@ Polygon.prototype.getNext = function(v) {
* @return {Vertex}
*/
Polygon.prototype.getFirstIntersect = function() {
var v = this.first;
var v = this._firstIntersect || this.first;

do {
if (v._isIntersection && !v._visited) {
break;
}

v = v.next;
} while (!v.equals(this.first));

this._firstIntersect = v;
return v;
};

Expand All @@ -301,14 +316,17 @@ Polygon.prototype.getFirstIntersect = function() {
* @return {Boolean} [description]
*/
Polygon.prototype.hasUnprocessed = function() {
var v = this.first;
var v = this._lastUnprocessed || this.first;
do {
if (v._isIntersection && !v._visited) {
this._lastUnprocessed = v;
return true;
}

v = v.next;
} while (!v.equals(this.first));

this._lastUnprocessed = null;
return false;
};

Expand All @@ -319,10 +337,11 @@ Polygon.prototype.getPoints = function() {
var points = [],
v = this.first;

for (var i = 0; i < this.vertices; i++) {
points[i] = [v.x, v.y];
do {
points.push([v.x, v.y]);
v = v.next;
}
} while (v !== this.first);

return points;
};

Expand All @@ -340,8 +359,10 @@ Polygon.prototype.getPoints = function() {
*/
Polygon.prototype.clip = function(clip, sourceForwards, clipForwards) {
var sourceVertex = this.first,
clipVertex = clip.first;
clipVertex = clip.first,
sourceInClip, clipInSource;

// calculate and mark intersections
do {
if (!sourceVertex._isIntersection) {
do {
Expand Down Expand Up @@ -381,8 +402,12 @@ Polygon.prototype.clip = function(clip, sourceForwards, clipForwards) {
sourceVertex = this.first;
clipVertex = clip.first;

sourceForwards ^= sourceVertex.isInside(clip);
clipForwards ^= clipVertex.isInside(this);
sourceInClip = sourceVertex.isInside(clip);
clipInSource = clipVertex.isInside(this);

sourceForwards ^= sourceInClip;
clipForwards ^= clipInSource;

do {
if (sourceVertex._isIntersection) {
sourceVertex._isEntry = sourceForwards;
Expand Down Expand Up @@ -427,6 +452,15 @@ Polygon.prototype.clip = function(clip, sourceForwards, clipForwards) {
list.push(clipped);
}

if (list.length === 0) {
if (sourceInClip) {
list.push(this);
}
if (clipInSource) {
list.push(this);
}
}

return list;
};
// Router
Expand Down
Loading

0 comments on commit 04d1f5d

Please sign in to comment.