UNPKG

1.27 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.segmentLineFactory = void 0;
4var mid_point_1 = require("./mid-point");
5var distance_square_root_1 = require("./distance-square-root");
6/**
7 * Returns a {x,y} point at a given length, the total length and
8 * the minimum and maximum {x,y} coordinates of a line (L,V,H,Z) segment.
9 */
10function segmentLineFactory(x1, y1, x2, y2, distance) {
11 var length = (0, distance_square_root_1.distanceSquareRoot)([x1, y1], [x2, y2]);
12 var point = { x: 0, y: 0 };
13 if (typeof distance === 'number') {
14 if (distance <= 0) {
15 point = { x: x1, y: y1 };
16 }
17 else if (distance >= length) {
18 point = { x: x2, y: y2 };
19 }
20 else {
21 var _a = (0, mid_point_1.midPoint)([x1, y1], [x2, y2], distance / length), x = _a[0], y = _a[1];
22 point = { x: x, y: y };
23 }
24 }
25 return {
26 length: length,
27 point: point,
28 min: {
29 x: Math.min(x1, x2),
30 y: Math.min(y1, y2),
31 },
32 max: {
33 x: Math.max(x1, x2),
34 y: Math.max(y1, y2),
35 },
36 };
37}
38exports.segmentLineFactory = segmentLineFactory;
39//# sourceMappingURL=segment-line-factory.js.map
\No newline at end of file