Merge remote branch 'origin/master'

This commit is contained in:
Jonathan Puckey 2011-04-28 20:46:39 +02:00
commit b1d8922fd1
4 changed files with 32 additions and 25 deletions

View file

@ -353,15 +353,25 @@ var Point = this.Point = Base.extend({
}, },
/** /**
* Checks if the vector represented by this point is parallel (collinear) to * Checks if the vector represented by this point is colinear (parallel) to
* another vector. * another vector.
* *
* @param point the vector to check against * @param point the vector to check against
* @return {@true if it is parallel} * @return {@true if it is parallel}
*/ */
isParallel: function(point) { isColinear: function(point) {
// TODO: Tolerance seems rather high! return this.cross(point) < Numerical.TOLERANCE;
return Math.abs(this.x / point.x - this.y / point.y) < 0.00001; },
/**
* Checks if the vector represented by this point is orthogonal
* (perpendicular) to another vector.
*
* @param point the vector to check against
* @return {@true if it is orthogonal}
*/
isOrthogonal: function(point) {
return this.dot(point) < Numerical.TOLERANCE;
}, },
/** /**

View file

@ -107,24 +107,19 @@ var Path = this.Path = PathItem.extend({
segment = Segment.read(arguments, 1); segment = Segment.read(arguments, 1);
return segment ? this._add(segment, index) : null; return segment ? this._add(segment, index) : null;
}, },
// TODO: Port back to Sg
removeSegment: function(index) {
var segment = this._segments[index]
return segment && segment.remove() ? segment : null;
},
remove: function() { // TODO: Port back to Sg
if (!arguments.length) { removeSegments: function(from, to) {
// remove() var i = Base.pick(to, this._segments.length - 1),
this.base(); from = from || 0;
} else if (arguments.length == 1) { while (i >= from)
if (arguments[0].point) { this.removeSegment(i--);
// remove(segment)
arguments[0].remove();
} else {
// remove(index)
this._segments[arguments[0]].remove();
}
} else {
// remove(fromIndex, toIndex)
for(var i = arguments[1], l = arguments[0]; i >= l; i--)
this._segments[i].remove();
}
}, },
isSelected: function() { isSelected: function() {

View file

@ -208,8 +208,10 @@ var Segment = this.Segment = Base.extend({
remove: function() { remove: function() {
if (this._path) { if (this._path) {
this._path._segments.splice(this.getIndex(), 1); this._path._segments.splice(this.getIndex(), 1);
if (this.isSelected()) if (this._selectionState) {
this._path._selectedSegmentCount--; this._path._selectedSegmentCount--;
this._selectionState = 0;
}
return true; return true;
} }
return false; return false;

View file

@ -63,13 +63,13 @@ test('path.remove()', function() {
path.add(20, 0); path.add(20, 0);
path.add(30, 0); path.add(30, 0);
path.remove(0); path.removeSegment(0);
equals(path.segments.length, 3); equals(path.segments.length, 3);
path.remove(path.segments[0]); path.removeSegment(0);
equals(path.segments.length, 2); equals(path.segments.length, 2);
path.remove(0, 1); path.removeSegments(0, 1);
equals(path.segments.length, 0); equals(path.segments.length, 0);
path.remove(); path.remove();