Skip to content

Commit fb4ce71

Browse files
committed
Add 'separated' property to buffer zones
1 parent 2e3b6f5 commit fb4ce71

File tree

5 files changed

+552
-116
lines changed

5 files changed

+552
-116
lines changed

src/common/plotting.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,19 @@ export const areaPolygon = (...pts: IPoint[]): number => {
316316
}
317317
return Math.abs(sum / 2);
318318
}
319+
320+
// https://math.stackexchange.com/questions/3058210/how-to-shorten-a-line-but-maintain-its-angle
321+
// shortens a line by a percent; val must be between 0 and 1
322+
export const shortenLine = (x1: number, y1: number, x2: number, y2: number, val: number)
323+
: [number,number,number,number] => {
324+
if (val < 0 || val > 1) {
325+
throw new Error("The val parameter must be between 0 and 1.");
326+
}
327+
const t0 = val;
328+
const t1 = 1 - val;
329+
const newx1 = x1 + (t0 * (x2 - x1));
330+
const newy1 = y1 + (t0 * (y2 - y1));
331+
const newx2 = x1 + (t1 * (x2 - x1));
332+
const newy2 = y1 + (t1 * (y2 - y1));
333+
return [newx1, newy1, newx2, newy2];
334+
}

0 commit comments

Comments
 (0)