Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a sine wave tool to the graphtool. #1157

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
82 changes: 44 additions & 38 deletions htdocs/js/GraphTool/cubictool.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,25 +179,30 @@
}
);
point.setAttribute({ snapToGrid: true });
if (typeof grouped_points !== 'undefined' && grouped_points.length) {
point.grouped_points = [];
grouped_points.forEach((paired_point) => {
point.grouped_points.push(paired_point);
if (!paired_point.grouped_points) {
paired_point.grouped_points = [];
paired_point.on('drag', gt.graphObjectTypes.cubic.groupedPointDrag);
}
paired_point.grouped_points.push(point);
if (
!paired_point.eventHandlers.drag ||
paired_point.eventHandlers.drag.every(
(dragHandler) => dragHandler.handler !== gt.graphObjectTypes.cubic.groupedPointDrag

if (!gt.isStatic) {
if (typeof grouped_points !== 'undefined' && grouped_points.length) {
point.grouped_points = [];
grouped_points.forEach((paired_point) => {
point.grouped_points.push(paired_point);
if (!paired_point.grouped_points) {
paired_point.grouped_points = [];
paired_point.on('drag', gt.graphObjectTypes.cubic.groupedPointDrag);
}
paired_point.grouped_points.push(point);
if (
!paired_point.eventHandlers.drag ||
paired_point.eventHandlers.drag.every(
(dragHandler) =>
dragHandler.handler !== gt.graphObjectTypes.cubic.groupedPointDrag
)
)
)
paired_point.on('drag', gt.graphObjectTypes.cubic.groupedPointDrag);
});
point.on('drag', gt.graphObjectTypes.cubic.groupedPointDrag, point);
paired_point.on('drag', gt.graphObjectTypes.cubic.groupedPointDrag);
});
point.on('drag', gt.graphObjectTypes.cubic.groupedPointDrag, point);
}
}

return point;
}
}
Expand Down Expand Up @@ -235,13 +240,12 @@
};

this.phase2 = (coords) => {
// Don't allow the second point to be created on the same
// vertical line as the first point or off the board.
if (
this.point1.X() == gt.snapRound(coords[1], gt.snapSizeX) ||
!gt.boardHasPoint(coords[1], coords[2])
)
return;
if (!gt.boardHasPoint(coords[1], coords[2])) return;

// If the current coordinates are on the same vertical line as the first point,
// then use the highlight point coordinates instead.
if (Math.abs(this.point1.X() - gt.snapRound(coords[1], gt.snapSizeX)) < JXG.Math.eps)
coords = this.hlObjs.hl_point.coords.usrCoords;

gt.board.off('up');

Expand All @@ -267,14 +271,15 @@
};

this.phase3 = (coords) => {
// Don't allow the third point to be created on the same vertical line as the
// first point, on the same vertical line as the second point, or off the board.
if (!gt.boardHasPoint(coords[1], coords[2])) return;

// If the current coordinates are on the same vertical line as the first point, or on the same
// vertical line as the second point, then use the highlight point coordinates instead.
if (
this.point1.X() == gt.snapRound(coords[1], gt.snapSizeX) ||
this.point2.X() == gt.snapRound(coords[1], gt.snapSizeX) ||
!gt.boardHasPoint(coords[1], coords[2])
Math.abs(this.point1.X() - gt.snapRound(coords[1], gt.snapSizeX)) < JXG.Math.eps ||
Math.abs(this.point2.X() - gt.snapRound(coords[1], gt.snapSizeX)) < JXG.Math.eps
)
return;
coords = this.hlObjs.hl_point.coords.usrCoords;

gt.board.off('up');
this.point3 = gt.graphObjectTypes.cubic.createPoint(coords[1], coords[2], [
Expand Down Expand Up @@ -306,16 +311,17 @@
};

this.phase4 = (coords) => {
// Don't allow the fourth point to be created on the same vertical line as the first
// point, on the same vertical line as the second point, on the same vertical line as
// the third point, or off the board.
if (!gt.boardHasPoint(coords[1], coords[2])) return;

// If the current coordinates are on the same vertical line as the first point, on the same vertical
// line as the second point, or on the same vertical line as the third point, then use the highlight
// point coordinates instead.
if (
this.point1.X() == gt.snapRound(coords[1], gt.snapSizeX) ||
this.point2.X() == gt.snapRound(coords[1], gt.snapSizeX) ||
this.point3.X() == gt.snapRound(coords[1], gt.snapSizeX) ||
!gt.boardHasPoint(coords[1], coords[2])
Math.abs(this.point1.X() - gt.snapRound(coords[1], gt.snapSizeX)) < JXG.Math.eps ||
Math.abs(this.point2.X() - gt.snapRound(coords[1], gt.snapSizeX)) < JXG.Math.eps ||
Math.abs(this.point3.X() - gt.snapRound(coords[1], gt.snapSizeX)) < JXG.Math.eps
)
return;
coords = this.hlObjs.hl_point.coords.usrCoords;

gt.board.off('up');

Expand Down
Loading