Reputation: 23009
I am modifying a CAD-in-a-browser app i found and i am trying to add some ''add new segment'' functionality. That means that the user can click on a pre-existing curve and add a segment there.
It uses Paper.js as the canvas library.
The app i found is this: https://github.com/memononen/stylii
This is the code snippet where the functionality is defined:
} else if (this.mode == 'insert') {
if (this.hitResult != null) {
var location = this.hitResult.location;
var values = location.curve.getValues();
var isLinear = location.curve.isLinear();
var parts = paper.Curve.subdivide(values, location.parameter);
var left = parts[0];
var right = parts[1];
var x = left[6], y = left[7];
var segment = new Segment(new paper.Point(x, y),
!isLinear && new paper.Point(left[4] - x, left[5] - y),
!isLinear && new paper.Point(right[2] - x, right[3] - y));
var seg = this.hitResult.item.insert(location.index + 1, segment);
if (!isLinear) {
seg.previous.handleOut.set(left[2] - left[0], left[3] - left[1]);
seg.next.handleIn.set(right[4] - right[6], right[5] - right[7]);
}
deselectAllPoints();
seg.selected = true;
this.hitResult = null;
}
It seems that when i try to use this function i keep getting ''Segment is not defined'' in Chrome Canary, but neither FF works.
The Paper version that Stylii uses : v0.9.15
Upvotes: 3
Views: 975
Reputation: 23009
I should have defined the segment upfront in the JS file by doing something like this:
var Base = paper.Base,
Segment = paper.segment;
Upvotes: 2