Skip to content

Commit 0ddb4c1

Browse files
authored
refactor: use matrix transform to calculate positions
1 parent 3549ebe commit 0ddb4c1

29 files changed

+736
-167
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# These are supported funding model platforms
22

3-
github: ksassnowski
3+
github: ksassnowski

.github/workflows/commitlint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ jobs:
88
- uses: actions/checkout@v4
99
with:
1010
fetch-depth: 0
11-
- uses: wagoid/commitlint-github-action@v5
11+
- uses: wagoid/commitlint-github-action@v5

.github/workflows/release-please.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ jobs:
2525
- run: npm publish
2626
env:
2727
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
28-
if: ${{ steps.release.outputs.release_created }}
28+
if: ${{ steps.release.outputs.release_created }}

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ jobs:
1313
- name: Install dependencies
1414
run: bun install
1515
- name: Run tests
16-
run: bun test
16+
run: bun test

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

CHANGELOG.md

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,86 +11,74 @@
1111

1212
## [1.1.1](https://github.com/ksassnowski/vueclid/compare/v1.1.0...v1.1.1) (2024-02-22)
1313

14-
1514
### Bug Fixes
1615

17-
* remove small gaps in function plot ([a960411](https://github.com/ksassnowski/vueclid/commit/a9604111d64c306f840769b8dc18617274796566))
18-
* scale arrow correctly for short vectors ([635e936](https://github.com/ksassnowski/vueclid/commit/635e936ac8c83869ee502d9b97a777846bb72a96))
16+
- remove small gaps in function plot ([a960411](https://github.com/ksassnowski/vueclid/commit/a9604111d64c306f840769b8dc18617274796566))
17+
- scale arrow correctly for short vectors ([635e936](https://github.com/ksassnowski/vueclid/commit/635e936ac8c83869ee502d9b97a777846bb72a96))
1918

2019
## [1.1.0](https://github.com/ksassnowski/vueclid/compare/v1.0.2...v1.1.0) (2024-01-30)
2120

22-
2321
### Features
2422

25-
* add rotation parameter to ellipse ([fa1bb9d](https://github.com/ksassnowski/vueclid/commit/fa1bb9ddba99b01991708d564052fb3872ed98a3))
23+
- add rotation parameter to ellipse ([fa1bb9d](https://github.com/ksassnowski/vueclid/commit/fa1bb9ddba99b01991708d564052fb3872ed98a3))
2624

2725
## [1.0.2](https://github.com/ksassnowski/vueclid/compare/v1.0.1...v1.0.2) (2024-01-30)
2826

29-
3027
### Bug Fixes
3128

32-
* fix typescript type declarations (maybe) ([11eeec4](https://github.com/ksassnowski/vueclid/commit/11eeec4badf01098ff2326eb4f6c1334805980f9))
29+
- fix typescript type declarations (maybe) ([11eeec4](https://github.com/ksassnowski/vueclid/commit/11eeec4badf01098ff2326eb4f6c1334805980f9))
3330

3431
## [1.0.1](https://github.com/ksassnowski/vueclid/compare/v1.0.0...v1.0.1) (2024-01-30)
3532

36-
3733
### Bug Fixes
3834

39-
* point typescript to correct declaration file ([641877e](https://github.com/ksassnowski/vueclid/commit/641877e6aa351bb6b5fe99d2ae8b955e1f0212a3))
35+
- point typescript to correct declaration file ([641877e](https://github.com/ksassnowski/vueclid/commit/641877e6aa351bb6b5fe99d2ae8b955e1f0212a3))
4036

4137
## [1.0.0](https://github.com/ksassnowski/vueclid/compare/v0.1.0...v1.0.0) (2024-01-30)
4238

43-
4439
### Features
4540

46-
* allow vector to be constructed from a single value ([f07be5f](https://github.com/ksassnowski/vueclid/commit/f07be5f1a05aa8fcf4980e5310a7d44adfd06510))
47-
41+
- allow vector to be constructed from a single value ([f07be5f](https://github.com/ksassnowski/vueclid/commit/f07be5f1a05aa8fcf4980e5310a7d44adfd06510))
4842

4943
### Miscellaneous Chores
5044

51-
* release 1.0.0 ([e0f73bf](https://github.com/ksassnowski/vueclid/commit/e0f73bfc2243ac8f5b889a2d7ba3f3eff12575c2))
45+
- release 1.0.0 ([e0f73bf](https://github.com/ksassnowski/vueclid/commit/e0f73bfc2243ac8f5b889a2d7ba3f3eff12575c2))
5246

5347
## [0.1.0](https://github.com/ksassnowski/vueclid/compare/v0.0.7...v0.1.0) (2024-01-30)
5448

55-
5649
### Features
5750

58-
* add configuration function ([#21](https://github.com/ksassnowski/vueclid/issues/21)) ([aa5d554](https://github.com/ksassnowski/vueclid/commit/aa5d5546e91867d4a86ce40d4723a9b89aa3b02b))
59-
* make diagrams responsive ([#20](https://github.com/ksassnowski/vueclid/issues/20)) ([2b96c7c](https://github.com/ksassnowski/vueclid/commit/2b96c7c2d0e7149547de8c87ab4c6dfaec0ac331))
60-
* make setColors reactive ([9a0275e](https://github.com/ksassnowski/vueclid/commit/9a0275e0cd54aeff541c972f0914e57cd87b8855))
51+
- add configuration function ([#21](https://github.com/ksassnowski/vueclid/issues/21)) ([aa5d554](https://github.com/ksassnowski/vueclid/commit/aa5d5546e91867d4a86ce40d4723a9b89aa3b02b))
52+
- make diagrams responsive ([#20](https://github.com/ksassnowski/vueclid/issues/20)) ([2b96c7c](https://github.com/ksassnowski/vueclid/commit/2b96c7c2d0e7149547de8c87ab4c6dfaec0ac331))
53+
- make setColors reactive ([9a0275e](https://github.com/ksassnowski/vueclid/commit/9a0275e0cd54aeff541c972f0914e57cd87b8855))
6154

6255
## [0.0.7](https://github.com/ksassnowski/vueclid/compare/v0.0.6...v0.0.7) (2024-01-29)
6356

64-
6557
### Bug Fixes
6658

67-
* remove path alias ([acea770](https://github.com/ksassnowski/vueclid/commit/acea770ea5a54772299f4a8e0aee885bbe1574eb))
59+
- remove path alias ([acea770](https://github.com/ksassnowski/vueclid/commit/acea770ea5a54772299f4a8e0aee885bbe1574eb))
6860

6961
## [0.0.6](https://github.com/ksassnowski/vueclid/compare/v0.0.5...v0.0.6) (2024-01-29)
7062

71-
7263
### Bug Fixes
7364

74-
* export component types properly ([07deefe](https://github.com/ksassnowski/vueclid/commit/07deefe8f0c648a230ad3a1a0d7a6625e4e73b64))
65+
- export component types properly ([07deefe](https://github.com/ksassnowski/vueclid/commit/07deefe8f0c648a230ad3a1a0d7a6625e4e73b64))
7566

7667
## [0.0.5](https://github.com/ksassnowski/vueclid/compare/v0.0.4...v0.0.5) (2024-01-29)
7768

78-
7969
### Bug Fixes
8070

81-
* use correct name for type declarations file ([d688f8a](https://github.com/ksassnowski/vueclid/commit/d688f8af70a0f6677b3bdfcb2158956c822138b3))
71+
- use correct name for type declarations file ([d688f8a](https://github.com/ksassnowski/vueclid/commit/d688f8af70a0f6677b3bdfcb2158956c822138b3))
8272

8373
## [0.0.4](https://github.com/ksassnowski/vueclid/compare/v0.0.3...v0.0.4) (2024-01-29)
8474

85-
8675
### Bug Fixes
8776

88-
* generate type declaration file in correct location ([f7fb5b2](https://github.com/ksassnowski/vueclid/commit/f7fb5b2b81962a4e92e16759dc76598329accf02))
89-
77+
- generate type declaration file in correct location ([f7fb5b2](https://github.com/ksassnowski/vueclid/commit/f7fb5b2b81962a4e92e16759dc76598329accf02))
9078

9179
### Miscellaneous Chores
9280

93-
* release 0.0.3 ([e2733bb](https://github.com/ksassnowski/vueclid/commit/e2733bbf7c66d3b0288b1f2ce039369d94aa7da6))
94-
* release 0.0.4 ([0c4cc7a](https://github.com/ksassnowski/vueclid/commit/0c4cc7a74482e675bc2d590edbe99023db6ea72e))
81+
- release 0.0.3 ([e2733bb](https://github.com/ksassnowski/vueclid/commit/e2733bbf7c66d3b0288b1f2ce039369d94aa7da6))
82+
- release 0.0.4 ([0c4cc7a](https://github.com/ksassnowski/vueclid/commit/0c4cc7a74482e675bc2d590edbe99023db6ea72e))
9583

9684
## Changelog

bun.lockb

1.51 KB
Binary file not shown.

bunfig.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[test]
2+
preload = "./tests/setup.ts"

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
"build": "vite build && vue-tsc --emitDeclarationOnly"
2424
},
2525
"devDependencies": {
26+
"@happy-dom/global-registrator": "^13.4.1",
2627
"@types/node": "^20.11.5",
2728
"@vitejs/plugin-vue": "^4.5.2",
28-
"vue": "^3.3.11",
2929
"prettier": "^3.2.4",
3030
"typescript": "^5.2.2",
3131
"vite": "^5.0.8",
32+
"vue": "^3.3.11",
3233
"vue-tsc": "^1.8.25"
3334
}
3435
}

src/components/Angle.vue

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<g>
2+
<g v-bind="$attrs">
33
<path
44
v-if="fill"
55
:d="`M ${scaledB.x} ${scaledB.y} L ${start.x} ${start.y} A ${scaledRadius} ${scaledRadius} 0 ${sweep} 0 ${end.x} ${end.y}`"
@@ -32,8 +32,9 @@ import { PossibleVector2, Vector2 } from "../utils/Vector2.ts";
3232
import { useGraphContext } from "../composables/useGraphContext.ts";
3333
import { Color } from "../types.ts";
3434
import { useColors } from "../composables/useColors.ts";
35+
import { usePointerIntersection } from "../composables/usePointerIntersection.ts";
36+
import { pointInsideSector } from "../utils/geometry.ts";
3537
import Label from "./Label.vue";
36-
import { TAU } from "../utils/constants.ts";
3738
3839
const props = withDefaults(
3940
defineProps<{
@@ -57,11 +58,15 @@ const props = withDefaults(
5758
},
5859
);
5960
60-
const { scale, offset, invScale } = useGraphContext();
61+
const { matrix, invScale } = useGraphContext();
6162
const { parseColor } = useColors();
6263
6364
const stroke = parseColor(toRef(props, "color"), "stroke");
6465
const fill = parseColor(toRef(props, "fill"));
66+
const active = defineModel("active", { default: false });
67+
usePointerIntersection(active, (point) =>
68+
pointInsideSector(a.value, b.value, c.value, props.radius, point),
69+
);
6570
6671
const a = computed(() => Vector2.wrap(props.a));
6772
const b = computed(() => Vector2.wrap(props.b));
@@ -73,39 +78,26 @@ const sweep = computed(() => {
7378
c.value.x * (a.value.y - b.value.y);
7479
return orientation > 0 ? 1 : 0;
7580
});
76-
const scaledB = computed(() =>
77-
b.value.mul(new Vector2(1, -1)).mul(scale.value).add(offset.value),
78-
);
79-
const scaledRadius = computed(() => props.radius * scale.value.x);
81+
const scaledB = computed(() => b.value.transform(matrix.value));
82+
const scaledRadius = computed(() => props.radius * matrix.value.a);
8083
const start = computed(() => {
81-
const direction = a.value.sub(b.value).normalized().mul(new Vector2(1, -1));
82-
return b.value
83-
.mul(new Vector2(1, -1))
84-
.add(direction.scale(props.radius))
85-
.mul(scale.value)
86-
.add(offset.value);
84+
const direction = a.value.sub(b.value).normalized();
85+
return b.value.add(direction.scale(props.radius)).transform(matrix.value);
8786
});
8887
const end = computed(() => {
89-
const direction = c.value.sub(b.value).normalized().mul(new Vector2(1, -1));
90-
return b.value
91-
.mul(new Vector2(1, -1))
92-
.add(direction.scale(props.radius))
93-
.mul(scale.value)
94-
.add(offset.value);
88+
const direction = c.value.sub(b.value).normalized();
89+
return b.value.add(direction.scale(props.radius)).transform(matrix.value);
9590
});
9691
const dashArray = computed(() =>
9792
props.dashed ? [6 * invScale.value, 4 * invScale.value].join(",") : "0,0",
9893
);
9994
const labelPosition = computed(() => {
10095
const bToA = a.value.sub(b.value);
10196
const bToC = c.value.sub(b.value);
102-
const dot = bToA.dot(bToC);
103-
const det = bToA.x * bToC.y - bToA.y * bToC.x;
104-
const angle = (Math.atan2(det, dot) + TAU) % TAU;
10597
return bToA
10698
.normalized()
10799
.scale(props.radius)
108-
.rotate(angle / 2)
100+
.rotate(bToA.clockwiseAngleTo(bToC) / 2)
109101
.add(b.value);
110102
});
111103
</script>

0 commit comments

Comments
 (0)