From 1cbbb1b6ebdb2bbf0f05ee1dcbe9922236495f58 Mon Sep 17 00:00:00 2001 From: bobzel Date: Wed, 1 Dec 2021 00:18:02 -0500 Subject: cleanup DocDecorations ink rotation --- src/client/views/InkStrokeProperties.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/client/views/InkStrokeProperties.ts') diff --git a/src/client/views/InkStrokeProperties.ts b/src/client/views/InkStrokeProperties.ts index 7ab631b03..9634e6e83 100644 --- a/src/client/views/InkStrokeProperties.ts +++ b/src/client/views/InkStrokeProperties.ts @@ -183,10 +183,10 @@ export class InkStrokeProperties { */ @undoBatch @action - rotateInk = (inkStrokes: DocumentView[], angle: number, scrpt: { x: number, y: number }) => { + rotateInk = (inkStrokes: DocumentView[], angle: number, scrpt: PointData) => { this.applyFunction(inkStrokes, (view: DocumentView, ink: InkData, xScale: number, yScale: number, inkStrokeWidth: number) => { view.rootDoc.rotation = NumCast(view.rootDoc.rotation) + angle; - const inkCenterPt = view.ComponentView?.ptFromScreen?.({ X: scrpt.x, Y: scrpt.y }); + const inkCenterPt = view.ComponentView?.ptFromScreen?.(scrpt); return !inkCenterPt ? ink : ink.map(i => { const pt = { X: i.X - inkCenterPt.X, Y: i.Y - inkCenterPt.Y }; @@ -340,7 +340,7 @@ export class InkStrokeProperties { brokenIndices.splice(ind, 1); const [controlPoint, handleA, handleB] = [ink[controlIndex], ink[handleIndexA], ink[handleIndexB]]; const oppositeHandleA = this.rotatePoint(handleA, controlPoint, Math.PI); - const angleDifference = this.angleChange(handleB, oppositeHandleA, controlPoint); + const angleDifference = InkStrokeProperties.angleChange(handleB, oppositeHandleA, controlPoint); const inkCopy = ink.slice(); // have to make a new copy of the array to keep from corrupting undo/redo. without slicing, the same array will be stored in each undo step meaning earlier undo steps will be inadvertently updated to store the latest value. inkCopy[handleIndexB] = this.rotatePoint(handleB, controlPoint, angleDifference); return inkCopy; @@ -364,7 +364,7 @@ export class InkStrokeProperties { * * α = arccos(a·b / |a|·|b|), where a and b are both vectors. */ - angleBetweenTwoVectors = (vectorA: PointData, vectorB: PointData) => { + public static angleBetweenTwoVectors(vectorA: PointData, vectorB: PointData) { const magnitudeA = Math.sqrt(vectorA.X * vectorA.X + vectorA.Y * vectorA.Y); const magnitudeB = Math.sqrt(vectorB.X * vectorB.X + vectorB.Y * vectorB.Y); if (magnitudeA === 0 || magnitudeB === 0) return 0; @@ -377,14 +377,14 @@ export class InkStrokeProperties { /** * Finds the angle difference (in radians) between two vectors relative to an arbitrary origin. */ - angleChange = (a: PointData, b: PointData, origin: PointData) => { + public static angleChange(a: PointData, b: PointData, origin: PointData) { // Finding vector representation of inputted points relative to new origin. const vectorA = { X: a.X - origin.X, Y: a.Y - origin.Y }; const vectorB = { X: b.X - origin.X, Y: b.Y - origin.Y }; const crossProduct = vectorB.X * vectorA.Y - vectorB.Y * vectorA.X; // Determining whether rotation is clockwise or counterclockwise. const sign = crossProduct < 0 ? 1 : -1; - const theta = this.angleBetweenTwoVectors(vectorA, vectorB); + const theta = InkStrokeProperties.angleBetweenTwoVectors(vectorA, vectorB); return sign * theta; } @@ -408,7 +408,7 @@ export class InkStrokeProperties { // Rotate opposite handle if user hasn't held 'Alt' key or not first/final control (which have only 1 handle). if ((!brokenIndices || (!brokenIndices?.includes(controlIndex) && !brokenIndices?.includes(equivIndex))) && (closed || (handleIndex !== 1 && handleIndex !== ink.length - 2))) { - const angle = this.angleChange(oldHandlePoint, newHandlePoint, controlPoint); + const angle = InkStrokeProperties.angleChange(oldHandlePoint, newHandlePoint, controlPoint); inkCopy[oppositeHandleIndex] = this.rotatePoint(oppositeHandlePoint, controlPoint, angle); } return inkCopy; -- cgit v1.2.3-70-g09d2