mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Merge remote branch 'origin/master'
This commit is contained in:
commit
c875953198
8 changed files with 88 additions and 89 deletions
|
@ -70,9 +70,7 @@
|
||||||
curHandleSeg = path.lastSegment;
|
curHandleSeg = path.lastSegment;
|
||||||
// clone as we want the unmodified one:
|
// clone as we want the unmodified one:
|
||||||
prevPoint = curHandleSeg.point.clone();
|
prevPoint = curHandleSeg.point.clone();
|
||||||
// TODO: potential bug - in SG we don't need to clone this
|
path.add(curHandleSeg);
|
||||||
// point, why?
|
|
||||||
path.add(curHandleSeg.clone());
|
|
||||||
curPoint = path.lastSegment.point;
|
curPoint = path.lastSegment.point;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,7 +159,7 @@ var Point = this.Point = Base.extend({
|
||||||
if (this.isZero()) {
|
if (this.isZero()) {
|
||||||
if (this._angle != null) {
|
if (this._angle != null) {
|
||||||
var a = this._angle;
|
var a = this._angle;
|
||||||
// Use #set() instead of direct assignment, so ObservedPoint
|
// Use #set() instead of direct assignment, so LinkedPoint
|
||||||
// can optimise
|
// can optimise
|
||||||
this.set(
|
this.set(
|
||||||
Math.cos(a) * length,
|
Math.cos(a) * length,
|
||||||
|
@ -177,7 +177,7 @@ var Point = this.Point = Base.extend({
|
||||||
// x and y are 0
|
// x and y are 0
|
||||||
this.getAngle();
|
this.getAngle();
|
||||||
}
|
}
|
||||||
// Use #set() instead of direct assignment, so ObservedPoint
|
// Use #set() instead of direct assignment, so LinkedPoint
|
||||||
// can optimise
|
// can optimise
|
||||||
this.set(
|
this.set(
|
||||||
this.x * scale,
|
this.x * scale,
|
||||||
|
@ -237,7 +237,7 @@ var Point = this.Point = Base.extend({
|
||||||
angle = this._angle = angle * Math.PI / 180;
|
angle = this._angle = angle * Math.PI / 180;
|
||||||
if (!this.isZero()) {
|
if (!this.isZero()) {
|
||||||
var length = this.getLength();
|
var length = this.getLength();
|
||||||
// Use #set() instead of direct assignment, so ObservedPoint
|
// Use #set() instead of direct assignment, so LinkedPoint
|
||||||
// can optimise
|
// can optimise
|
||||||
this.set(
|
this.set(
|
||||||
Math.cos(angle) * length,
|
Math.cos(angle) * length,
|
||||||
|
@ -573,13 +573,19 @@ var Point = this.Point = Base.extend({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var ObservedPoint = Point.extend({
|
/**
|
||||||
|
* An internal version of Point that notifies its owner of each change through
|
||||||
|
* setting itself again on the setter that corresponds to the getter that
|
||||||
|
* produced this LinkedPoint. See uses of LinkedPoint.create()
|
||||||
|
* Note: This prototype is not exported.
|
||||||
|
*/
|
||||||
|
var LinkedPoint = Point.extend({
|
||||||
beans: true,
|
beans: true,
|
||||||
|
|
||||||
set: function(x, y) {
|
set: function(x, y) {
|
||||||
this._x = x;
|
this._x = x;
|
||||||
this._y = y;
|
this._y = y;
|
||||||
this._observer[this._set](this);
|
this._owner[this._set](this);
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -589,7 +595,7 @@ var ObservedPoint = Point.extend({
|
||||||
|
|
||||||
setX: function(x) {
|
setX: function(x) {
|
||||||
this._x = x;
|
this._x = x;
|
||||||
this._observer[this._set](this);
|
this._owner[this._set](this);
|
||||||
},
|
},
|
||||||
|
|
||||||
getY: function() {
|
getY: function() {
|
||||||
|
@ -598,24 +604,15 @@ var ObservedPoint = Point.extend({
|
||||||
|
|
||||||
setY: function(y) {
|
setY: function(y) {
|
||||||
this._y = y;
|
this._y = y;
|
||||||
this._observer[this._set](this);
|
this._owner[this._set](this);
|
||||||
},
|
},
|
||||||
|
|
||||||
statics: {
|
statics: {
|
||||||
/**
|
create: function(owner, set, x, y) {
|
||||||
* Provide a faster creator for Points out of two coordinates that
|
var point = new LinkedPoint(LinkedPoint.dont);
|
||||||
* does not rely on Point#initialize at all. This speeds up all math
|
|
||||||
* operations a lot.
|
|
||||||
*/
|
|
||||||
create: function(observer, set, x, y) {
|
|
||||||
// Don't use the shorter form as we want absolute maximum
|
|
||||||
// performance here:
|
|
||||||
// return new Point(Point.dont).set(x, y);
|
|
||||||
// TODO: Benchmark and decide
|
|
||||||
var point = new ObservedPoint(ObservedPoint.dont);
|
|
||||||
point._x = x;
|
point._x = x;
|
||||||
point._y = y;
|
point._y = y;
|
||||||
point._observer = observer;
|
point._owner = owner;
|
||||||
point._set = set;
|
point._set = set;
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ var Rectangle = this.Rectangle = Base.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
getPoint: function() {
|
getPoint: function() {
|
||||||
return ObservedPoint.create(this, 'setPoint', this.x, this.y);
|
return LinkedPoint.create(this, 'setPoint', this.x, this.y);
|
||||||
},
|
},
|
||||||
|
|
||||||
setPoint: function(point) {
|
setPoint: function(point) {
|
||||||
|
@ -97,7 +97,6 @@ var Rectangle = this.Rectangle = Base.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
setLeft: function(left) {
|
setLeft: function(left) {
|
||||||
// right should not move
|
|
||||||
this.width -= left - this.x;
|
this.width -= left - this.x;
|
||||||
this.x = left;
|
this.x = left;
|
||||||
return this;
|
return this;
|
||||||
|
@ -150,7 +149,7 @@ var Rectangle = this.Rectangle = Base.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
getCenter: function() {
|
getCenter: function() {
|
||||||
return ObservedPoint.create(this, 'setCenter',
|
return LinkedPoint.create(this, 'setCenter',
|
||||||
this.getCenterX(), this.getCenterY());
|
this.getCenterX(), this.getCenterY());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -255,19 +254,28 @@ var Rectangle = this.Rectangle = Base.extend({
|
||||||
getX = 'get' + x,
|
getX = 'get' + x,
|
||||||
getY = 'get' + y,
|
getY = 'get' + y,
|
||||||
setX = 'set' + x,
|
setX = 'set' + x,
|
||||||
setY = 'set' + y;
|
setY = 'set' + y,
|
||||||
this['get' + part] = function() {
|
get = 'get' + part,
|
||||||
return ObservedPoint.create(this, 'set' + part,
|
set = 'set' + part;
|
||||||
|
this[get] = function() {
|
||||||
|
return LinkedPoint.create(this, set,
|
||||||
this[getX](), this[getY]());
|
this[getX](), this[getY]());
|
||||||
};
|
};
|
||||||
this['set' + part] = function(point) {
|
this[set] = function(point) {
|
||||||
point = Point.read(arguments);
|
point = Point.read(arguments);
|
||||||
return this[setX](point.x)[setY](point.y); // Note: call chaining!
|
// Note: call chaining happens here.
|
||||||
|
return this[setX](point.x)[setY](point.y);
|
||||||
};
|
};
|
||||||
}, { beans: true });
|
}, { beans: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
var ObservedRectangle = Rectangle.extend({
|
/**
|
||||||
|
* An internal version of Rectangle that notifies its owner of each change
|
||||||
|
* through setting itself again on the setter that corresponds to the getter
|
||||||
|
* that produced this LinkedRectangle. See uses of LinkedRectangle.create()
|
||||||
|
* Note: This prototype is not exported.
|
||||||
|
*/
|
||||||
|
var LinkedRectangle = Rectangle.extend({
|
||||||
beans: true,
|
beans: true,
|
||||||
|
|
||||||
set: function(x, y, width, height) {
|
set: function(x, y, width, height) {
|
||||||
|
@ -275,52 +283,8 @@ var ObservedRectangle = Rectangle.extend({
|
||||||
this._y = y;
|
this._y = y;
|
||||||
this._width = width;
|
this._width = width;
|
||||||
this._height = height;
|
this._height = height;
|
||||||
if (this._observer)
|
if (this._owner)
|
||||||
this._observer[this._set](this);
|
this._owner[this._set](this);
|
||||||
return this;
|
|
||||||
},
|
|
||||||
|
|
||||||
// TODO: Use loop to create these?
|
|
||||||
getX: function() {
|
|
||||||
return this._x;
|
|
||||||
},
|
|
||||||
|
|
||||||
setX: function(x) {
|
|
||||||
this._x = x;
|
|
||||||
this._observer[this._set](this);
|
|
||||||
},
|
|
||||||
|
|
||||||
getY: function() {
|
|
||||||
return this._y;
|
|
||||||
},
|
|
||||||
|
|
||||||
setY: function(y) {
|
|
||||||
this._y = y;
|
|
||||||
this._observer[this._set](this);
|
|
||||||
},
|
|
||||||
|
|
||||||
getWidth: function() {
|
|
||||||
return this._width;
|
|
||||||
},
|
|
||||||
|
|
||||||
setWidth: function(width) {
|
|
||||||
this._width = width;
|
|
||||||
this._observer[this._set](this);
|
|
||||||
},
|
|
||||||
|
|
||||||
getHeight: function() {
|
|
||||||
return this._height;
|
|
||||||
},
|
|
||||||
|
|
||||||
setHeight: function(height) {
|
|
||||||
this._height = height;
|
|
||||||
this._observer[this._set](this);
|
|
||||||
},
|
|
||||||
|
|
||||||
// TODO: Implement for all properties on ObservedRectangle using loop
|
|
||||||
setCenter: function(center) {
|
|
||||||
Rectangle.prototype.setCenter.apply(this, center);
|
|
||||||
this._observer[this._set](this);
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -330,16 +294,47 @@ var ObservedRectangle = Rectangle.extend({
|
||||||
* does not rely on Point#initialize at all. This speeds up all math
|
* does not rely on Point#initialize at all. This speeds up all math
|
||||||
* operations a lot.
|
* operations a lot.
|
||||||
*/
|
*/
|
||||||
create: function(observer, set, x, y, width, height) {
|
create: function(owner, set, x, y, width, height) {
|
||||||
// Don't use the shorter form as we want absolute maximum
|
var rect = new LinkedRectangle(LinkedRectangle.dont).set(x, y,
|
||||||
// performance here:
|
|
||||||
// return new Point(Point.dont).set(x, y);
|
|
||||||
// TODO: Benchmark and decide
|
|
||||||
var rect = new ObservedRectangle(ObservedRectangle.dont).set(x, y,
|
|
||||||
width, height);
|
width, height);
|
||||||
rect._observer = observer;
|
rect._owner = owner;
|
||||||
rect._set = set;
|
rect._set = set;
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}, new function() {
|
||||||
|
var proto = Rectangle.prototype;
|
||||||
|
|
||||||
|
return Base.each(['x', 'y', 'width', 'height'], function(key) {
|
||||||
|
var part = Base.capitalize(key);
|
||||||
|
var internal = '_' + key;
|
||||||
|
this['get' + part] = function() {
|
||||||
|
return this[internal];
|
||||||
|
}
|
||||||
|
|
||||||
|
this['set' + part] = function(value) {
|
||||||
|
this[internal] = value;
|
||||||
|
// Check if this setter is called from another one which sets
|
||||||
|
// _dontNotify, as it will notify itself
|
||||||
|
if (!this._dontNotify)
|
||||||
|
this._owner[this._set](this);
|
||||||
|
}
|
||||||
|
}, Base.each(['Point', 'Size', 'Center',
|
||||||
|
'Left', 'Top', 'Right', 'Bottom', 'CenterX', 'CenterY',
|
||||||
|
'TopLeft', 'TopRight', 'BottomLeft', 'BottomRight',
|
||||||
|
'LeftCenter', 'TopCenter', 'RightCenter', 'BottomCenter'],
|
||||||
|
function(key) {
|
||||||
|
var name = 'set' + key;
|
||||||
|
this[name] = function(value) {
|
||||||
|
// Make sure the above setters of x, y, width, height do not
|
||||||
|
// each notify the owner, as we're going to take care of this
|
||||||
|
// afterwards here, only once per change.
|
||||||
|
this._dontNotify = true;
|
||||||
|
proto[name].apply(this, arguments);
|
||||||
|
delete this._dontNotify;
|
||||||
|
this._owner[this._set](this);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}, { beans: true })
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -43,7 +43,7 @@ var Group = this.Group = Item.extend({
|
||||||
y2 = Math.max(rect2.y + rect2.height, y1 + y2 - y1);
|
y2 = Math.max(rect2.y + rect2.height, y1 + y2 - y1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ObservedRectangle.create(this, 'setBounds',
|
return LinkedRectangle.create(this, 'setBounds',
|
||||||
x1, y1, x2 - x1, y2 - y1);
|
x1, y1, x2 - x1, y2 - y1);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ var PlacedSymbol = this.PlacedSymbol = Item.extend({
|
||||||
|
|
||||||
getBounds: function() {
|
getBounds: function() {
|
||||||
var bounds = this.symbol._definition.getStrokeBounds(this.matrix, true);
|
var bounds = this.symbol._definition.getStrokeBounds(this.matrix, true);
|
||||||
return ObservedRectangle.create(this, 'setBounds',
|
return LinkedRectangle.create(this, 'setBounds',
|
||||||
bounds.x, bounds.y, bounds.width, bounds.height);
|
bounds.x, bounds.y, bounds.width, bounds.height);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ var CompoundPath = this.CompoundPath = PathItem.extend({
|
||||||
y2 = Math.max(rect2.y + rect2.height, y1 + y2 - y1);
|
y2 = Math.max(rect2.y + rect2.height, y1 + y2 - y1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ObservedRectangle.create(this, 'setBounds',
|
return LinkedRectangle.create(this, 'setBounds',
|
||||||
x1, y1, x2 - x1, y2 - y1);
|
x1, y1, x2 - x1, y2 - y1);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -301,7 +301,7 @@ var Curve = this.Curve = Base.extend({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Amount of integral evaluations
|
// Amount of integral evaluations for the interval 0 <= a < b <= 1
|
||||||
function getIterations(a, b) {
|
function getIterations(a, b) {
|
||||||
// Guess required precision based and size of range...
|
// Guess required precision based and size of range...
|
||||||
// TODO: There should be much better educated guesses for
|
// TODO: There should be much better educated guesses for
|
||||||
|
|
|
@ -59,6 +59,15 @@ var Path = this.Path = PathItem.extend({
|
||||||
return this._segments[this._segments.length - 1];
|
return this._segments[this._segments.length - 1];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getFirstCurve: function() {
|
||||||
|
return this.getCurves()[0];
|
||||||
|
},
|
||||||
|
|
||||||
|
getLastCurve: function() {
|
||||||
|
var curves = this.getCurves();
|
||||||
|
return curves[curves - 1];
|
||||||
|
},
|
||||||
|
|
||||||
// TODO: Consider adding getSubPath(a, b), returning a part of the current
|
// TODO: Consider adding getSubPath(a, b), returning a part of the current
|
||||||
// path, with the added benefit that b can be < a, and closed looping is
|
// path, with the added benefit that b can be < a, and closed looping is
|
||||||
// taken into account.
|
// taken into account.
|
||||||
|
@ -701,7 +710,7 @@ var Path = this.Path = PathItem.extend({
|
||||||
// Pass the matrix hidden from Bootstrap, so it still inject
|
// Pass the matrix hidden from Bootstrap, so it still inject
|
||||||
// getBounds as bean too.
|
// getBounds as bean too.
|
||||||
var bounds = getBounds(this, arguments[0]);
|
var bounds = getBounds(this, arguments[0]);
|
||||||
return ObservedRectangle.create(this, 'setBounds',
|
return LinkedRectangle.create(this, 'setBounds',
|
||||||
bounds.x, bounds.y, bounds.width, bounds.height);
|
bounds.x, bounds.y, bounds.width, bounds.height);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue