commit f626d5539bec1ecd10140c7f6d9f80ec14fb0393
parent 74609993a94e8a9c6c383cb0d6870288bc31e63a
Author: fen123456 <fenwthompson@gmail.com>
Date: Sat, 15 Aug 2026 13:47:49 +0100
add truemod to utils
Diffstat:
3 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/src/components/RotationTextElement.jsx b/src/components/RotationTextElement.jsx
@@ -1,8 +1,9 @@
+import { trueMod } from "../scripts/utils"
import Equation from "./Equation"
export default function RotationTextElement({ angle }) {
- angle = angle > 0 ? angle % (2*Math.PI) : 2*Math.PI - (-angle % (2*Math.PI)) // range 0 to 2pi, actual modulus lol
+ angle = trueMod(angle, 2*Math.PI)
angle = Math.round(angle * 180 / Math.PI) // range 0 to 360
let directionText = ""
if (Math.abs(angle) == 180) { directionText = "" }
diff --git a/src/components/questions/DoubleReflectionQuestion.jsx b/src/components/questions/DoubleReflectionQuestion.jsx
@@ -90,8 +90,8 @@ export default function DoubleReflectionQuestion({ seed, showAnswer }) {
const intersect = findIntersect(line1, line2)
let answer = <></>
- if (intersect === null) { // translation
-
+ if (intersect === null) { // translation, lines parallel
+
} else { // rotation 180
const angle = 2*(getLineAngle(line2) - getLineAngle(line1))
answer = (<>
diff --git a/src/scripts/utils.js b/src/scripts/utils.js
@@ -1,5 +1,3 @@
-import Equation from "../components/Equation";
-
export function getRandomInt(min, max, seed) {
return min + Math.floor((max - min + 1) * getRandomNumber(seed));
}
@@ -108,3 +106,8 @@ export function interpolateDistance(start, end, distance) {
export function getMidpoint(points) {
return interpolate(points[0], points[1], 0.5);
}
+
+export function trueMod(a, b) {
+ // a mod b, but with expected behaviour for negatives.
+ return a >= 0 ? a % b : b - (-a % b)
+}
+\ No newline at end of file