1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.segmentLineFactory = void 0;
|
4 | var mid_point_1 = require("./mid-point");
|
5 | var distance_square_root_1 = require("./distance-square-root");
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | function 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 | }
|
38 | exports.segmentLineFactory = segmentLineFactory;
|
39 |
|
\ | No newline at end of file |