Merge remote-tracking branch 'origin/master' into bool-new-2

This commit is contained in:
Jürg Lehni 2014-02-19 14:35:52 +01:00
commit 093aae0836
3 changed files with 25 additions and 8 deletions

View file

@ -1071,7 +1071,8 @@ var Path = PathItem.extend(/** @lends Path# */{
index = arg.index;
parameter = arg.parameter;
}
if (parameter >= 1) {
var tolerance = /*#=*/ Numerical.TOLERANCE;
if (parameter >= 1 - tolerance) {
// t == 1 is the same as t == 0 and index ++
index++;
parameter--;
@ -1079,7 +1080,7 @@ var Path = PathItem.extend(/** @lends Path# */{
var curves = this.getCurves();
if (index >= 0 && index < curves.length) {
// Only divide curves if we're not on an existing segment already.
if (parameter > 0) {
if (parameter > tolerance) {
// Divide the curve with the index at given parameter.
// Increase because dividing adds more segments to the path.
curves[index++].divide(parameter, true);
@ -1347,13 +1348,13 @@ var Path = PathItem.extend(/** @lends Path# */{
var start = length,
curve = curves[i];
length += curve.getLength();
if (length >= offset) {
if (length > offset) {
// Found the segment within which the length lies
return curve.getLocationAt(offset - start);
}
}
// It may be that through impreciseness of getLength, that the end
// of the curves was missed:
// It may be that through imprecision of getLength, that the end of the
// last curve was missed:
if (offset <= this.getLength())
return new CurveLocation(curves[curves.length - 1], 1);
return null;

View file

@ -10,7 +10,7 @@
* All rights reserved.
*/
module('Item Contains');
module('PathItem Contains');
function testPoint(item, point, inside) {
equals(item.contains(point), inside, 'The point ' + point
@ -188,4 +188,19 @@ test('Path#contains() (touching stationary point with changing orientation)', fu
});
testPoint(path, new Point(200, 200), true);
})
});
test('Path#contains() (complex shape)', function() {
var path = new Path({
pathData: 'M301 162L307 154L315 149L325 139.5L332.5 135.5L341 128.5L357.5 117.5L364.5 114.5L368.5 110.5L380 105.5L390.5 102L404 96L410.5 96L415 97.5L421 104L425.5 113.5L428.5 126L429.5 134L429.5 141L429.5 148L425.5 161.5L425.5 169L414 184.5L409.5 191L401 201L395 209L386 214.5L378.5 217L368 220L348 219.5L338 218L323.5 212.5L312 205.5L302.5 197.5L295.5 189L291.5 171.5L294 168L298 165.5L301 162z',
fillColor: 'blue',
strokeColor: 'green',
strokeWidth: 2
});
testPoint(path, new Point(360, 160), true);
testPoint(path, new Point(377, 96), false);
testPoint(path, new Point(410, 218), false);
testPoint(path, new Point(431, 104), false);
});

View file

@ -23,7 +23,6 @@
/*#*/ include('Item_Cloning.js');
/*#*/ include('Item_Order.js');
/*#*/ include('Item_Bounds.js');
/*#*/ include('Item_Contains.js');
/*#*/ include('Layer.js');
/*#*/ include('Group.js');
@ -39,6 +38,8 @@
/*#*/ include('Path_Length.js');
/*#*/ include('CompoundPath.js');
/*#*/ include('PathItem_Contains.js');
/*#*/ include('PlacedSymbol.js');
/*#*/ include('Raster.js');