Skip to content

Commit

Permalink
rename func and use getClockwiseAngle func
Browse files Browse the repository at this point in the history
  • Loading branch information
anakaren-rojas committed Dec 4, 2024
1 parent d71854b commit 2c9983c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
18 changes: 5 additions & 13 deletions packages/perseus/src/widgets/interactive-graphs/graphs/angle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ import {vec} from "mafs";
import * as React from "react";

import {usePerseusI18n} from "../../../components/i18n-context";
import {X, Y, calculateAngleInDegrees, polar} from "../math";
import {X, Y, calculateAngleInDegrees, getClockwiseAngle, polar} from "../math";
import {findIntersectionOfRays} from "../math/geometry";
import {actions} from "../reducer/interactive-graph-action";
import useGraphConfig from "../reducer/use-graph-config";

import {
Angle,
getWholeAngleMeasure,
getClockwiseCoords,
} from "./components/angle-indicators";
import {Angle} from "./components/angle-indicators";
import {trimRange} from "./components/movable-line";
import {MovablePoint} from "./components/movable-point";
import {SVGLine} from "./components/svg-line";
Expand Down Expand Up @@ -100,14 +96,10 @@ function AngleGraph({dispatch, graphState}: AngleGraphProps) {
showAngles: showAngles || false, // Whether to show the angle or not
};

// Get angle measure
const clockwiseCoords = getClockwiseCoords(
endPoints,
centerPoint,
const angleLabel = getClockwiseAngle(
[endPoints[0], centerPoint, endPoints[1]],
allowReflexAngles,
);
const angleMeasure = getWholeAngleMeasure(clockwiseCoords, centerPoint);
const angleLabel = `${allowReflexAngles ? 360 - angleMeasure : angleMeasure}`;

const {strings, locale} = usePerseusI18n();

Expand Down Expand Up @@ -144,7 +136,7 @@ function AngleGraph({dispatch, graphState}: AngleGraphProps) {
const label = showAngles
? strings.srVertexWithAngleAtCoordinates({
...formattedVertexCoordinates,
angle: angleLabel,
angle: `${angleLabel}`,
})
: strings.srVertexAtCoordinates(formattedVertexCoordinates);
setVertexAriaLabel(label);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {getClockwiseAngle} from "../../math";

import {
getClockwiseCoords,
adjustCoordsForAngleCalculation,
getWholeAngleMeasure,
shouldDrawArcOutside,
} from "./angle-indicators";
Expand Down Expand Up @@ -151,7 +151,9 @@ describe("getClockwiseCoords", () => {
[1, 1],
];

expect(getClockwiseCoords(coords, coords[0])).toEqual(coords);
expect(adjustCoordsForAngleCalculation(coords, coords[0])).toEqual(
coords,
);
});

test("should return the coordinates in counter-clockwise order when reflex angles are allowed", () => {
Expand All @@ -161,7 +163,9 @@ describe("getClockwiseCoords", () => {
[0, 1],
];

expect(getClockwiseCoords(coords, coords[0], true)).toEqual([
expect(
adjustCoordsForAngleCalculation(coords, coords[0], true),
).toEqual([
[0, 1],
[1, 0],
[0, 0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export function getWholeAngleMeasure(coords: Vector2[], vertex: vec.Vector2) {
return parseFloat(angle.toFixed(0));
}

export function getClockwiseCoords(
export function adjustCoordsForAngleCalculation(
coords: Vector2[],
vertex: vec.Vector2,
allowReflexAngles: boolean = false,
Expand All @@ -175,7 +175,7 @@ export const Angle = ({
range,
}: AngleProps) => {
// Get the clockwise coordinates
const clockwiseCoords = getClockwiseCoords(
const clockwiseCoords = adjustCoordsForAngleCalculation(
coords,
vertex,
allowReflexAngles,
Expand Down
10 changes: 7 additions & 3 deletions packages/perseus/src/widgets/interactive-graphs/math/angles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ export const getAngleFromVertex = (
return (180 + (Math.atan2(-y, -x) * 180) / Math.PI + 360) % 360;
};

// This function calculates the clockwise angle between three points,
// and is used to generate the labels and equation strings of the
// current angle for the interactive graph.
/**
* This function calculates the clockwise angle between three points,
* and is used to generate the labels and equation strings of the
* current angle for the interactive graph.
* @param coords - The three points that make up the angle. Points are saved as [point1, vertex, point2]
* @param allowReflexAngles - Whether or not to allow reflex angles
*/
export const getClockwiseAngle = (
coords: [Coord, Coord, Coord],
allowReflexAngles: boolean = false,
Expand Down

0 comments on commit 2c9983c

Please sign in to comment.