• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"use strict";
2/*
3 * Copyright (c) 2022-2025 Huawei Device Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16Object.defineProperty(exports, "__esModule", { value: true });
17exports.Point = void 0;
18class Point {
19    constructor(x, y) {
20        this.coordinates = new Float32Array(2);
21        this.coordinates[0] = x;
22        this.coordinates[1] = y;
23    }
24    get x() {
25        return this.coordinates[0];
26    }
27    get y() {
28        return this.coordinates[1];
29    }
30    offsetXY(dx, dy) {
31        return new Point(this.x + dx, this.y + dy);
32    }
33    offset(vec) {
34        return this.offsetXY(vec.x, vec.y);
35    }
36    scale(scale) {
37        return this.scaleXY(scale, scale);
38    }
39    scaleXY(sx, sy) {
40        return new Point(this.x * sx, this.y * sy);
41    }
42    toArray() {
43        return this.coordinates;
44    }
45    static flattenArray(points) {
46        let array = new Float32Array(points.length * 2);
47        for (let i = 0; i < points.length; i++) {
48            array[i * 2] = points[i].x;
49            array[i * 2 + 1] = points[i].y;
50        }
51        return array;
52    }
53    static fromArray(points) {
54        if (points.length % 2 != 0)
55            throw new Error("Expected " + points.length + " % 2 == 0");
56        let array = new Array(points.length / 2);
57        for (let i = 0; i < points.length / 2; i++) {
58            array[i] = new Point(points[i * 2], points[i * 2 + 1]);
59        }
60        return array;
61    }
62}
63exports.Point = Point;
64Point.ZERO = new Point(0.0, 0.0);
65//# sourceMappingURL=Point.js.map