Add beginning of SegmentPoint class.

This commit is contained in:
Jürg Lehni 2011-04-21 13:21:56 +01:00
parent 00958afd09
commit 96f266b4d2
4 changed files with 64 additions and 14 deletions

View file

@ -43,6 +43,7 @@ var sources = [
'src/item/PathStyle.js',
'src/path/Segment.js',
'src/path/SegmentPoint.js',
'src/path/Curve.js',
'src/path/CurveLocation.js',
'src/path/PathItem.js',

View file

@ -91,7 +91,9 @@ Base.inject({
//#include "item/PathStyle.js"
//#include "path/Segment.js"
//#include "path/SegmentPoint.js"
//#include "path/Curve.js"
//#include "path/CurveLocation.js"
//#include "path/PathItem.js"
//#include "path/Path.js"
//#include "path/CompoundPath.js"

View file

@ -19,36 +19,36 @@ var Segment = this.Segment = Base.extend({
initialize: function(arg0, arg1, arg2, arg3, arg4, arg5) {
if (arguments.length == 0) {
this._point = new Point();
this._point = SegmentPoint.create(this, 0, 0);
} else if (arguments.length == 1) {
// TODO: If beans are not activated, this won't copy from
// an existing segment. OK?
if (arg0.point) {
this._point = new Point(arg0.point);
this._handleIn = new Point(arg0.handleIn);
this._handleOut = new Point(arg0.handleOut);
this._point = SegmentPoint.create(this, arg0.point);
this._handleIn = SegmentPoint.create(this, arg0.handleIn);
this._handleOut = SegmentPoint.create(this, arg0.handleOut);
} else {
this._point = new Point(arg0);
this._point = SegmentPoint.create(this, arg0);
}
} else if (arguments.length < 6) {
if (arguments.length == 2 && !arg1.x) {
this._point = new Point(arg0, arg1);
this._point = SegmentPoint.create(this, arg0, arg1);
} else {
this._point = new Point(arg0);
this._point = SegmentPoint.create(this, arg0);
// Doesn't matter if these arguments exist, it creates 0, 0
// points otherwise
this._handleIn = new Point(arg1);
this._handleOut = new Point(arg2);
this._handleIn = SegmentPoint.create(this, arg1);
this._handleOut = SegmentPoint.create(this, arg2);
}
} else if (arguments.length == 6) {
this._point = new Point(arg0, arg1);
this._handleIn = new Point(arg2, arg3);
this._handleOut = new Point(arg4, arg5);
this._point = SegmentPoint.create(this, arg0, arg1);
this._handleIn = SegmentPoint.create(this, arg2, arg3);
this._handleOut = SegmentPoint.create(this, arg4, arg5);
}
if (!this._handleIn)
this._handleIn = new Point();
this._handleIn = SegmentPoint.create(this, 0, 0);
if (!this._handleOut)
this._handleOut = new Point();
this._handleOut = SegmentPoint.create(this, 0, 0);
},
getPoint: function() {

47
src/path/SegmentPoint.js Normal file
View file

@ -0,0 +1,47 @@
/**
* An internal version of Point that notifies its segment of each change
* Note: This prototype is not exported.
*/
var SegmentPoint = Point.extend({
beans: true,
set: function(x, y) {
this._x = x;
this._y = y;
// this._segment._markDirty(DirtyFlags.BOUNDS);
return this;
},
getX: function() {
return this._x;
},
setX: function(x) {
this._x = x;
// this._segment._markDirty(DirtyFlags.BOUNDS);
},
getY: function() {
return this._y;
},
setY: function(y) {
this._y = y;
// this._segment._markDirty(DirtyFlags.BOUNDS);
},
statics: {
create: function(segment, arg1, arg2) {
var point;
if (arguments.length == 2) {
point = new SegmentPoint(arg1);
} else {
point = new SegmentPoint(SegmentPoint.dont);
point._x = arg1;
point._y = arg2;
}
point._segment = segment;
return point;
}
}
});