Skip to content

Commit

Permalink
Clean up _getConicOffsets function
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb531 committed May 30, 2024
1 parent ff2de9f commit c58421e
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions src/jcanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2893,41 +2893,24 @@ function _getConicY(y: number, radiusY: number, angle: number) {
return y + radiusY * sin(angle);
}

// Modify the path
// Calculate angles and positioning for arcs/ellipses
function _getConicOffsets(params: JCanvasObject, path: JCanvasObject) {
let offsetX: number;
let offsetY: number;
let angleDiff: number;

// Determine offset from dragging
if (params === path) {
offsetX = 0;
offsetY = 0;
} else {
offsetX = params.x;
offsetY = params.y;
}
const offsetX = params === path ? 0 : params.x;
const offsetY = params === path ? 0 : params.y;
// Ensure arrows are pointed correctly for CCW arcs
const angleDiff = path.ccw ? -PI / 180 : PI / 180;

const pathX = path.x + offsetX;
const pathY = path.y + offsetY;

// Convert default end angle to radians
if (!path.inDegrees && path.end === 360) {
path.end = PI * 2;
}

// Convert angles to radians, then offset to make 0deg due north of arc
const pathStartAngle = path.start * params._toRad - PI / 2;
const pathEndAngle =
!path.inDegrees && path.end === 360
? PI * 2
: path.end * params._toRad - PI / 2;

// Ensure arrows are pointed correctly for CCW arcs
angleDiff = PI / 180;
if (path.ccw) {
angleDiff *= -1;
}
return { pathX, pathY, angleDiff, pathStartAngle, pathEndAngle };
}

Expand Down

0 comments on commit c58421e

Please sign in to comment.