Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
segment1: { point: p1, handleIn: in1, handleOut: out1 },
segment2: { point: p2, handleIn: in2, handleOut: out2 },
});
return;
}
// Draw an 'extend path' preview curve if one of its end points
// is selected and the path is still open.
const singleSelectedSegmentIndex = this.findSingleSelectedEndSegmentIndex(editPath);
if (singleSelectedSegmentIndex !== undefined) {
this.ps.setCursorType(CursorType.PenAdd);
const vpStartSegment = this.localToVpSegment(
editPath,
editPath.segments[singleSelectedSegmentIndex],
);
const vpEndSegment = new paper.Segment(this.pl.globalToLocal(event.point));
const { pathData } = new paper.Path([vpStartSegment, vpEndSegment]);
this.ps.setCreatePathInfo({
pathData,
strokeColor: '#979797',
});
}
}
function newSplitCurveItem(info: SplitCurveInfo, cssScaling: number) {
const group = new paper.Group();
group.guide = true;
const { splitPoint, segment1, segment2 } = info;
const point1 = new paper.Point(segment1.point);
const handleIn1 = new paper.Point(segment1.handleIn);
const handleOut1 = new paper.Point(segment1.handleOut);
const point2 = new paper.Point(segment2.point);
const handleIn2 = new paper.Point(segment2.handleIn);
const handleOut2 = new paper.Point(segment2.handleOut);
const highlightedCurve = new paper.Path([
new paper.Segment(point1, handleIn1, handleOut1),
new paper.Segment(point2, handleIn2, handleOut2),
]);
highlightedCurve.guide = true;
highlightedCurve.strokeColor = '#3466A9';
highlightedCurve.strokeScaling = false;
highlightedCurve.strokeWidth = 2 / paper.view.zoom;
group.addChild(highlightedCurve);
const highlightedPoint = new paper.Path.Circle(
new paper.Point(splitPoint),
4 / paper.view.zoom / cssScaling,
);
highlightedPoint.guide = true;
highlightedPoint.fillColor = '#3466A9';
group.addChild(highlightedPoint);
private localToVpSegment(localItem: paper.Item, localSegment: paper.Segment) {
return new paper.Segment(
this.localToVpPoint(localItem, localSegment.point),
this.localToVpHandle(localItem, localSegment.point, localSegment.handleIn),
this.localToVpHandle(localItem, localSegment.point, localSegment.handleOut),
);
}
function newSplitCurveItem(info: SplitCurveInfo, cssScaling: number) {
const group = new paper.Group();
group.guide = true;
const { splitPoint, segment1, segment2 } = info;
const point1 = new paper.Point(segment1.point);
const handleIn1 = new paper.Point(segment1.handleIn);
const handleOut1 = new paper.Point(segment1.handleOut);
const point2 = new paper.Point(segment2.point);
const handleIn2 = new paper.Point(segment2.handleIn);
const handleOut2 = new paper.Point(segment2.handleOut);
const highlightedCurve = new paper.Path([
new paper.Segment(point1, handleIn1, handleOut1),
new paper.Segment(point2, handleIn2, handleOut2),
]);
highlightedCurve.guide = true;
highlightedCurve.strokeColor = '#3466A9';
highlightedCurve.strokeScaling = false;
highlightedCurve.strokeWidth = 2 / paper.view.zoom;
group.addChild(highlightedCurve);
const highlightedPoint = new paper.Path.Circle(
new paper.Point(splitPoint),
4 / paper.view.zoom / cssScaling,
);
highlightedPoint.guide = true;
highlightedPoint.fillColor = '#3466A9';
group.addChild(highlightedPoint);
onMouseDrag: (_, event: MouseEvent) =>
Action.addSegment(new Segment(event.point!))
}),
tool.onMouseDrag = (event: MouseEvent) => {
const segment = new Segment(event.point!)
store.process(Action.addSegment(segment))
}
return tool
private localToVpSegment(localItem: paper.Item, localSegment: paper.Segment) {
return new paper.Segment(
this.localToVpPoint(localItem, localSegment.point),
this.localToVpHandle(localItem, localSegment.point, localSegment.handleIn),
this.localToVpHandle(localItem, localSegment.point, localSegment.handleOut),
);
}
function newSplitCurveItem(info: SplitCurveInfo, cssScaling: number) {
const group = new paper.Group();
group.guide = true;
const { splitPoint, segment1, segment2 } = info;
const point1 = new paper.Point(segment1.point);
const handleIn1 = new paper.Point(segment1.handleIn);
const handleOut1 = new paper.Point(segment1.handleOut);
const point2 = new paper.Point(segment2.point);
const handleIn2 = new paper.Point(segment2.handleIn);
const handleOut2 = new paper.Point(segment2.handleOut);
const highlightedCurve = new paper.Path([
new paper.Segment(point1, handleIn1, handleOut1),
new paper.Segment(point2, handleIn2, handleOut2),
]);
highlightedCurve.guide = true;
highlightedCurve.strokeColor = '#3466A9';
highlightedCurve.strokeScaling = false;
highlightedCurve.strokeWidth = 2 / paper.view.zoom;
group.addChild(highlightedCurve);
const highlightedPoint = new paper.Path.Circle(
new paper.Point(splitPoint),
4 / paper.view.zoom / cssScaling,
);
highlightedPoint.guide = true;
highlightedPoint.fillColor = '#3466A9';
group.addChild(highlightedPoint);
return group;