task(B3): offset respects click side (fixes BUG-3)
This commit is contained in:
@@ -163,7 +163,14 @@ export function mirrorElement(el: CADElement, x1: number, y1: number, x2: number
|
||||
* Offset element by a distance (creates a parallel copy).
|
||||
* For lines: offset perpendicular. For circles/arcs: adjust radius.
|
||||
*/
|
||||
export function offsetElement(el: CADElement, distance: number): CADElement {
|
||||
/**
|
||||
* Versetzt ein Element senkrecht zur seiner Richtung.
|
||||
* @param distance positiver Betrag des Versatzes
|
||||
* @param side 1 = links der Laufrichtung (Standard), -1 = rechts —
|
||||
* bei circle/arc: 1 = Radius vergrößern, -1 = verkleinern
|
||||
*/
|
||||
export function offsetElement(el: CADElement, distance: number, side?: 1 | -1): CADElement {
|
||||
const signed = distance * (side ?? 1);
|
||||
const props = { ...el.properties };
|
||||
|
||||
if (el.type === 'line' && props.x1 !== undefined && props.y1 !== undefined && props.x2 !== undefined && props.y2 !== undefined) {
|
||||
@@ -174,8 +181,8 @@ export function offsetElement(el: CADElement, distance: number): CADElement {
|
||||
// Perpendicular unit vector
|
||||
const nx = -dy / len;
|
||||
const ny = dx / len;
|
||||
const ox = nx * distance;
|
||||
const oy = ny * distance;
|
||||
const ox = nx * signed;
|
||||
const oy = ny * signed;
|
||||
props.x1 += ox;
|
||||
props.y1 += oy;
|
||||
props.x2 += ox;
|
||||
@@ -184,7 +191,7 @@ export function offsetElement(el: CADElement, distance: number): CADElement {
|
||||
}
|
||||
|
||||
if ((el.type === 'circle' || el.type === 'arc') && props.radius !== undefined) {
|
||||
props.radius = Math.abs(props.radius + distance);
|
||||
props.radius = Math.abs(props.radius + signed);
|
||||
const d = props.radius * 2;
|
||||
return { ...el, width: d, height: d, properties: props };
|
||||
}
|
||||
@@ -201,7 +208,7 @@ export function offsetElement(el: CADElement, distance: number): CADElement {
|
||||
if (len === 0) return p;
|
||||
const nx = -dy / len;
|
||||
const ny = dx / len;
|
||||
return { x: p.x + nx * distance, y: p.y + ny * distance };
|
||||
return { x: p.x + nx * signed, y: p.y + ny * signed };
|
||||
});
|
||||
return { ...el, properties: props };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user