aboutsummaryrefslogtreecommitdiff
path: root/src/arc.ts
diff options
context:
space:
mode:
authorJoris2021-05-13 14:50:51 +0200
committerJoris2021-05-13 14:58:26 +0200
commit221b6451fb4f8559a10e7fefebd13ce125ef29d0 (patch)
tree3ab337b7b2d40e8235f887046a580b0850540f11 /src/arc.ts
parent5c636f11cdfed82634ee572645d765b704941b68 (diff)
downloadtabata-221b6451fb4f8559a10e7fefebd13ce125ef29d0.tar.gz
tabata-221b6451fb4f8559a10e7fefebd13ce125ef29d0.tar.bz2
tabata-221b6451fb4f8559a10e7fefebd13ce125ef29d0.zip
Rewrite in TypeScript
BuckleScript is no longer maintained. Choose a widely used techno that will still be maintained in the following years.
Diffstat (limited to 'src/arc.ts')
-rw-r--r--src/arc.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/arc.ts b/src/arc.ts
new file mode 100644
index 0000000..d8e1e7d
--- /dev/null
+++ b/src/arc.ts
@@ -0,0 +1,37 @@
+function polarToCartesian(
+ centerX: number,
+ centerY: number,
+ radius: number,
+ degreesAngle: number
+): number[] {
+ const radianAngle = (degreesAngle - 90) * Math.PI / 180
+ return [
+ centerX + radius * Math.cos(radianAngle),
+ centerY + radius * Math.sin(radianAngle)
+ ]
+}
+
+export function describe(
+ x: number,
+ y: number,
+ radius: number,
+ startAngle: number,
+ endAngle: number
+): string {
+ const [startX, startY] = polarToCartesian(x, y, radius, endAngle)
+ const [endX, endY] = polarToCartesian(x, y, radius, startAngle)
+ const largeArcFlag = endAngle - startAngle <= 180 ? "0" : "1"
+ return [
+ "M",
+ startX.toString(),
+ startY,
+ "A",
+ radius.toString(),
+ radius.toString(),
+ "0",
+ largeArcFlag,
+ "0",
+ endX.toString(),
+ endY.toString(),
+ ].join(" ")
+}