From 7bda87a63d9307cdc2c287b59c6f80f529d2464e Mon Sep 17 00:00:00 2001 From: Kai Sassnowski Date: Thu, 22 Feb 2024 10:10:41 +0100 Subject: [PATCH 1/2] refactor: use matrix transform to calculate positions --- bun.lockb | Bin 33182 -> 34730 bytes bunfig.toml | 2 + package.json | 3 +- src/components/Angle.vue | 38 +++--- src/components/Arc.vue | 21 ++- src/components/Circle.vue | 10 +- src/components/Ellipse.vue | 11 +- src/components/Graph.vue | 9 ++ src/components/Label.vue | 32 +++-- src/components/Line.vue | 38 ++---- src/components/Point.vue | 14 +- src/components/PolyLine.vue | 9 +- src/components/Polygon.vue | 6 +- src/components/Sector.vue | 9 +- src/components/Vector.vue | 18 +-- src/composables/useLocalToWorld.ts | 19 +++ src/index.ts | 1 + src/types.ts | 4 + src/utils/Matrix2D.ts | 197 +++++++++++++++++++++++++++++ src/utils/Vector2.ts | 123 +++++++++++++++--- tests/math/Matrix2D.test.ts | 172 +++++++++++++++++++++++++ tests/math/Vector2.test.ts | 30 +++++ tests/setup.ts | 84 ++++++++++++ 23 files changed, 715 insertions(+), 135 deletions(-) create mode 100644 bunfig.toml create mode 100644 src/composables/useLocalToWorld.ts create mode 100644 src/utils/Matrix2D.ts create mode 100644 tests/math/Matrix2D.test.ts create mode 100644 tests/setup.ts diff --git a/bun.lockb b/bun.lockb index 4396b7fb500e455e64c6df9e2aeafd5fe8f40110..c405dbe6769dc9603789744b03e3fb6f13d2c478 100755 GIT binary patch delta 6559 zcmb_h33yahvcC5woum^w3yY+)m;|ztq{+UgLs+vABm(IKBzq^_F(I)#2_S*Af(l_6 zjP*ubkWF-E6ci`!&WykyLRjXDD5&FzFgVZn*d}hz4+!tC+kI(7AD=RFzEoG$sXBG) zoKt7Hl}#(9=hjOP>tZU-u9{MiSg~j1!9AVY@#vT`8R99q^DK zm-1diNcR$hoe>0UXJdRzO}nYH!x-OgtrM~!@Dv1_)!5Q$v^&H!!GvvIj(}>-3>vyLl6h-1wIhi54cKY z@8B3P8`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uTdplTTbPTsFs8m4w>-c2x8rtHN@A{UoGm*~ z7&y0Xxm;EC*k|wW3RvzG=yaVqcD=uqjZS$Y^_;Z zB~op@S?UpKd3}!bfJj5ota?BfpZR8G?Mtg0zuRp7;32DLef2o?-Kw#JSM`THc;|A+ zIcmsCtddfT>Kme^GeNYf!R&tsX_tl`Z^-f6rD`o*gU#QEdO`4T$~!IM^vA2e7v&E= zhHqg`ta_4H4}y}oIvX$3mW@jU+E$Z;WcW*sMam4OPik_c3&AvMfjM8j4p2{%flA*W z6*)UFyAg5g0&}c-qmXiG>@%CbbWKJ2WZAONoe-_3oeRuTlAcQI%u<$~?gNzQ=^|A`=N{4ZD&7CL$f(bvsNQ@B0rR7|4Zclrxnzz4fSL!iK;~jh5od# zg(t3jDDNFRZ$rxd2}P0OVX`(Rh<~STqh3uMj2tm^!Nx6XHR3p1kqxsz z=%KhKOP+d_F>C9^i={hHUJKaO%MP9Qji%PuKbHcQbJW&kiBT^{3NPO|Gc^3(lL31? z^)*?e0ZrhHM=Lf7j%`RZVPw`v~iIoPrcd67@C$Vu79sDU{~*cTI(OY{$}rivVf(G z&Y)%WuIQsp-hcI#e0eZnZ>ET5i@1_9n=LWwRnzky^gcQ)YRXpuubor}yLvUHkFaMx zE&k?sz=ryE}yv7RS()PRo$SjC_7T{4p1Zja7vYiM>iT0Pz_cYCv^V`*2T3zwsv*2NyV@<5Y~9bGPZU`ZFn zd9`$VdkS4x5+n2b+S8ctkLfUp{lQ(YNIK=Vl1_Nz=stJ3PWh^VIEuzEzTWTr*~=1T Qbnfpz;=LM9L+{=EA7cg#&Hw-a diff --git a/bunfig.toml b/bunfig.toml new file mode 100644 index 0000000..083d96e --- /dev/null +++ b/bunfig.toml @@ -0,0 +1,2 @@ +[test] +preload = "./tests/setup.ts" \ No newline at end of file diff --git a/package.json b/package.json index 29c1b1f..20fc19b 100644 --- a/package.json +++ b/package.json @@ -23,12 +23,13 @@ "build": "vite build && vue-tsc --emitDeclarationOnly" }, "devDependencies": { + "@happy-dom/global-registrator": "^13.4.1", "@types/node": "^20.11.5", "@vitejs/plugin-vue": "^4.5.2", - "vue": "^3.3.11", "prettier": "^3.2.4", "typescript": "^5.2.2", "vite": "^5.0.8", + "vue": "^3.3.11", "vue-tsc": "^1.8.25" } } diff --git a/src/components/Angle.vue b/src/components/Angle.vue index ff9828e..d5f5921 100644 --- a/src/components/Angle.vue +++ b/src/components/Angle.vue @@ -1,5 +1,5 @@