task(B3): offset respects click side (fixes BUG-3)
This commit is contained in:
@@ -761,7 +761,23 @@ export class InteractionEngine {
|
||||
if (this.modifySelected.length === 1) {
|
||||
const first = this.state.points[0];
|
||||
const dist = distance(first, pt);
|
||||
const offsetted = offsetElement(this.modifySelected[0], dist);
|
||||
const base = this.modifySelected[0];
|
||||
// Seitigkeit bestimmen: Kreuzprodukt der Linienrichtung mit Klickvektor.
|
||||
// cross > 0 → Klick links der Laufrichtung (p1→p2) → side=+1, sonst -1.
|
||||
let side: 1 | -1 = 1;
|
||||
if (base.type === 'line' && base.properties.x1 !== undefined && base.properties.y1 !== undefined) {
|
||||
const p1x = base.properties.x1 as number;
|
||||
const p1y = base.properties.y1 as number;
|
||||
const p2x = base.properties.x2 as number;
|
||||
const p2y = base.properties.y2 as number;
|
||||
const cross = (p2x - p1x) * (pt.y - p1y) - (p2y - p1y) * (pt.x - p1x);
|
||||
side = cross >= 0 ? 1 : -1;
|
||||
} else if ((base.type === 'circle' || base.type === 'arc') && base.properties.radius !== undefined) {
|
||||
// Kreis/Bogen: Klick außerhalb → vergrößern (+1), innerhalb → verkleinern (-1)
|
||||
const clickDist = Math.hypot(pt.x - base.x, pt.y - base.y);
|
||||
side = clickDist >= base.properties.radius ? 1 : -1;
|
||||
}
|
||||
const offsetted = offsetElement(base, dist, side);
|
||||
// Create as new element (copy)
|
||||
this.onElementCreated?.({ ...offsetted, id: this.generateId() });
|
||||
this.resetModify();
|
||||
|
||||
Reference in New Issue
Block a user