PageSourceSearch

https://www.bretagne-reisen.de/app/dist/crt-bretagne/addons/woody-…/Core/Geometry/GeometryUtilities.js

js bretagne-reisen.de collected 2026-10-02 07:10:49 UTC 3,002 bytes, 105 lines download raw bytes

vendor: 3,002 bytes, lines 1-105
1/* *
2 *
3 *  (c) 2010-2024 Highsoft AS
4 *
5 *  License: www.highcharts.com/license
6 *
7 *  !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
8 *
9 * */
10'use strict';
11/* *
12 *
13 *  Namespace
14 *
15 * */
16var GeometryUtilities;
17(function (GeometryUtilities) {
18    /* *
19     *
20     *  Functions
21     *
22     * */
23    /**
24     * Calculates the center between a list of points.
25     *
26     * @private
27     *
28     * @param {Array<Highcharts.PositionObject>} points
29     * A list of points to calculate the center of.
30     *
31     * @return {Highcharts.PositionObject}
32     * Calculated center
33     */
34    function getCenterOfPoints(points) {
35        const sum = points.reduce((sum, point) => {
36            sum.x += point.x;
37            sum.y += point.y;
38            return sum;
39        }, { x: 0, y: 0 });
40        return {
41            x: sum.x / points.length,
42            y: sum.y / points.length
43        };
44    }
45    GeometryUtilities.getCenterOfPoints = getCenterOfPoints;
46    /**
47     * Calculates the distance between two points based on their x and y
48     * coordinates.
49     *
50     * @private
51     *
52     * @param {Highcharts.PositionObject} p1
53     * The x and y coordinates of the first point.
54     *
55     * @param {Highcharts.PositionObject} p2
56     * The x and y coordinates of the second point.
57     *
58     * @return {number}
59     * Returns the distance between the points.
60     */
61    function getDistanceBetweenPoints(p1, p2) {
62        return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
63    }
64    GeometryUtilities.getDistanceBetweenPoints = getDistanceBetweenPoints;
65    /**
66     * Calculates the angle between two points.
67     * @todo add unit tests.
68     * @private
69     * @param {Highcharts.PositionObject} p1 The first point.
70     * @param {Highcharts.PositionObject} p2 The second point.
71     * @return {number} Returns the angle in radians.
72     */
73    function getAngleBetweenPoints(p1, p2) {
74        return Math.atan2(p2.x - p1.x, p2.y - p1.y);
75    }
76    GeometryUtilities.getAngleBetweenPoints = getAngleBetweenPoints;
77    /**
78     * Test for point in polygon. Polygon defined as array of [x,y] points.
79     * @private
80     * @param {PositionObject} point The point potentially within a polygon.
81     * @param {Array<Array<number>>} polygon The polygon potentially containing the point.
82     */
83    function pointInPolygon({ x, y }, polygon) {
84        const len = polygon.length;
85        let i, j, inside = false;
86        for (i = 0, j = len - 1; i < len; j = i++) {
87            const [x1, y1] = polygon[i], [x2, y2] = polygon[j];
88            if (y1 > y !== y2 > y &&
89                (x < (x2 - x1) *
90                    (y - y1) /
91                    (y2 - y1) +
92                    x1)) {
93                inside = !inside;
94            }
95        }
96        return inside;
97    }
98    GeometryUtilities.pointInPolygon = pointInPolygon;
99})(GeometryUtilities || (GeometryUtilities = {}));
100/* *
101 *
102 *  Default Export
103 *
104 * */
105export default GeometryUtilities;

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.