mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
Fix Path#contains() for unclosed paths that have a fill color.
This commit is contained in:
parent
589d4e6e73
commit
2061cb0517
1 changed files with 17 additions and 8 deletions
|
@ -131,20 +131,29 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
||||||
* @type Curve[]
|
* @type Curve[]
|
||||||
* @bean
|
* @bean
|
||||||
*/
|
*/
|
||||||
getCurves: function() {
|
getCurves: function(/* includeFill */) {
|
||||||
if (!this._curves) {
|
var curves = this._curves,
|
||||||
var segments = this._segments,
|
segments = this._segments;
|
||||||
length = segments.length;
|
if (!curves) {
|
||||||
|
var length = segments.length;
|
||||||
// Reduce length by one if it's an open path:
|
// Reduce length by one if it's an open path:
|
||||||
if (!this._closed && length > 0)
|
if (!this._closed && length > 0)
|
||||||
length--;
|
length--;
|
||||||
this._curves = new Array(length);
|
this._curves = curves = new Array(length);
|
||||||
for (var i = 0; i < length; i++)
|
for (var i = 0; i < length; i++)
|
||||||
this._curves[i] = Curve.create(this, segments[i],
|
curves[i] = Curve.create(this, segments[i],
|
||||||
// Use first segment for segment2 of closing curve
|
// Use first segment for segment2 of closing curve
|
||||||
segments[i + 1] || segments[0]);
|
segments[i + 1] || segments[0]);
|
||||||
}
|
}
|
||||||
return this._curves;
|
// If we're asked to include the closing curve for fill, even if the
|
||||||
|
// path is not closed for stroke, create a new uncached array and add
|
||||||
|
// the closing curve. Used in Path#contains()
|
||||||
|
if (arguments[0] && !this._closed && this._style._fillColor) {
|
||||||
|
curves = curves.concat([
|
||||||
|
Curve.create(this, segments[segments.length - 1], segments[0])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
return curves;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1276,7 +1285,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
||||||
// beam in right y-direction with the shape, and see if it's an odd
|
// beam in right y-direction with the shape, and see if it's an odd
|
||||||
// number, meaning the starting point is inside the shape.
|
// number, meaning the starting point is inside the shape.
|
||||||
// http://en.wikipedia.org/wiki/Point_in_polygon
|
// http://en.wikipedia.org/wiki/Point_in_polygon
|
||||||
var curves = this.getCurves(),
|
var curves = this.getCurves(true),
|
||||||
crossings = 0,
|
crossings = 0,
|
||||||
// Reuse one array for root-finding, give garbage collector a break
|
// Reuse one array for root-finding, give garbage collector a break
|
||||||
roots = [];
|
roots = [];
|
||||||
|
|
Loading…
Reference in a new issue