Skip to content

Commit f21b131

Browse files
authored
bug(Polygon UI): Fix polygon edit UI not taking rotation into account
1 parent 077a787 commit f21b131

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ tech changes will usually be stripped from release notes for the public
1212

1313
### Fixed
1414

15+
- Polygon edit UI: was not taking rotation of shape into account
1516
- Teleport: shapes would not be removed on the old location until a refresh
1617

1718
## [2023.3.0] - 2023-09-17

client/src/game/shapes/variants/polygon.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ export class Polygon extends Shape implements IShape {
230230
cutPolygon(point: GlobalPoint): void {
231231
let lastVertex = -1;
232232
let nearVertex: GlobalPoint | null = null;
233+
const oldCenter = this.center;
234+
233235
for (let i = 1; i <= this.vertices.length - (this.openPolygon ? 1 : 0); i++) {
234236
const prevVertex = this.vertices[i - 1]!;
235237
const vertex = this.vertices[i % this.vertices.length]!;
@@ -253,12 +255,14 @@ export class Polygon extends Shape implements IShape {
253255
newPolygon.setLayer(this.floorId!, this.layerName!);
254256
newPolygon.fromDict({
255257
...oldDict,
258+
angle: 0,
256259
uuid,
257260
trackers: oldDict.trackers.map((t) => ({ ...t, uuid: uuidv4() as unknown as TrackerId })),
258261
auras: oldDict.auras.map((a) => ({ ...a, uuid: uuidv4() as unknown as AuraId })),
259262
});
260-
newPolygon._refPoint = nearVertex!;
261-
newPolygon._vertices = newVertices;
263+
newPolygon._refPoint = rotateAroundPoint(nearVertex!, oldCenter, this.angle);
264+
newPolygon._vertices = newVertices.map((v) => rotateAroundPoint(v, oldCenter, this.angle));
265+
newPolygon._center = newPolygon.__center();
262266

263267
const props = getProperties(this.id)!;
264268

client/src/game/tools/variants/select/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from "../../../../core/geometry";
1616
import type { GlobalPoint, LocalPoint } from "../../../../core/geometry";
1717
import { baseAdjust } from "../../../../core/http";
18-
import { equalPoints, snapToPoint } from "../../../../core/math";
18+
import { equalPoints, rotateAroundPoint, snapToPoint } from "../../../../core/math";
1919
import { InvalidationMode, NO_SYNC, SyncMode } from "../../../../core/models/types";
2020
import { ctrlOrCmdPressed } from "../../../../core/utils";
2121
import { i18n } from "../../../../i18n";
@@ -970,7 +970,7 @@ class SelectTool extends Tool implements ISelectTool {
970970

971971
const pw = g2lz(polygon.lineWidth[0]!);
972972

973-
const pv = polygon.vertices;
973+
const pv = polygon.vertices.map((v) => rotateAroundPoint(v, polygon.center, polygon.angle));
974974
let smallest = { distance: polygon.lineWidth[0]! * 2, nearest: gp, angle: 0, point: false };
975975
for (let i = 1; i < pv.length; i++) {
976976
const prevVertex = pv[i - 1]!;

client/src/game/ui/tools/SelectTool.vue

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<script setup lang="ts">
22
import { onMounted, toRef } from "vue";
33
4+
import type { GlobalPoint } from "../../../core/geometry";
5+
import { rotateAroundPoint } from "../../../core/math";
46
import type { Polygon } from "../../shapes/variants/polygon";
57
import { selectedSystem } from "../../systems/selected";
68
import { selectTool } from "../../tools/variants/select";
@@ -21,6 +23,10 @@ onMounted(() => {
2123
selectTool.checkRuler();
2224
});
2325
26+
function getGlobalRefPoint(polygon: Polygon): GlobalPoint {
27+
return rotateAroundPoint(selectTool.polygonTracer!.refPoint, polygon.center, -polygon.angle);
28+
}
29+
2430
function toggleShowRuler(event: MouseEvent): void {
2531
const state = (event.target as HTMLButtonElement).getAttribute("aria-pressed") ?? "false";
2632
_$.showRuler = state === "false";
@@ -29,17 +35,17 @@ function toggleShowRuler(event: MouseEvent): void {
2935
3036
function cutPolygon(): void {
3137
const selection = selectedSystem.get({ includeComposites: false })[0] as Polygon;
32-
selection.cutPolygon(selectTool.polygonTracer!.refPoint);
38+
selection.cutPolygon(getGlobalRefPoint(selection));
3339
}
3440
3541
function addPoint(): void {
3642
const selection = selectedSystem.get({ includeComposites: false })[0] as Polygon;
37-
selection.addPoint(selectTool.polygonTracer!.refPoint);
43+
selection.addPoint(getGlobalRefPoint(selection));
3844
}
3945
4046
function removePoint(): void {
4147
const selection = selectedSystem.get({ includeComposites: false })[0] as Polygon;
42-
selection.removePoint(selectTool.polygonTracer!.refPoint);
48+
selection.removePoint(getGlobalRefPoint(selection));
4349
}
4450
</script>
4551

0 commit comments

Comments
 (0)