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.Matrix33 = exports.mat33 = void 0; 18const compat_1 = require("#koalaui/compat"); 19function mat33(array) { 20 return (array == undefined) ? new Matrix33() : new Matrix33(array); 21} 22exports.mat33 = mat33; 23const tolerance = (1.0 / (1 << 12)); 24class Matrix33 { 25 constructor(array = new Float32Array((0, compat_1.Array_from_number)([ 26 1.0, 0.0, 0.0, 27 0.0, 1.0, 0.0, 28 0.0, 0.0, 1.0 29 ]))) { 30 this.array = array.slice(); 31 } 32 static zero() { 33 return new Matrix33(new Float32Array((0, compat_1.Array_from_number)([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]))); 34 } 35 static makeTranslate(dx, dy) { 36 return new Matrix33(new Float32Array((0, compat_1.Array_from_number)([1.0, 0.0, dx, 0.0, 1.0, dy, 0.0, 0.0, 1.0]))); 37 } 38 static makeScale(dx, dy = dx) { 39 return new Matrix33(new Float32Array((0, compat_1.Array_from_number)([dx, 0.0, 0.0, 0.0, dy, 0.0, 0.0, 0.0, 1.0]))); 40 } 41 static makeRotate(degrees, pivotX, pivotY) { 42 let rads = degrees * Math.PI / 180; 43 let cos = Math.cos(rads); 44 let sin = Math.sin(rads); 45 if (Math.abs(sin) <= tolerance) 46 sin = 0.0; 47 if (Math.abs(cos) <= tolerance) 48 cos = 0.0; 49 if (pivotX !== undefined && pivotY != undefined) { 50 let dx = pivotX - pivotX * cos + pivotY * sin; 51 let dy = pivotY - pivotY * cos - pivotX * sin; 52 return new Matrix33(new Float32Array((0, compat_1.Array_from_number)([cos, -sin, dx, sin, cos, dy, 0.0, 0.0, 1.0]))); 53 } 54 else { 55 return new Matrix33(new Float32Array((0, compat_1.Array_from_number)([cos, -sin, 0.0, sin, cos, 0.0, 0.0, 0.0, 1.0]))); 56 } 57 } 58 static makeSkew(sx, sy) { 59 return new Matrix33(new Float32Array((0, compat_1.Array_from_number)([1.0, sx, 0.0, sy, 1.0, 0.0, 0.0, 0.0, 1.0]))); 60 } 61 makeConcat(rhs) { 62 return new Matrix33(new Float32Array((0, compat_1.Array_from_number)([ 63 this.array[0] * rhs.array[0] + this.array[1] * rhs.array[3] + this.array[2] * rhs.array[6], 64 this.array[0] * rhs.array[1] + this.array[1] * rhs.array[4] + this.array[2] * rhs.array[7], 65 this.array[0] * rhs.array[2] + this.array[1] * rhs.array[5] + this.array[2] * rhs.array[8], 66 this.array[3] * rhs.array[0] + this.array[4] * rhs.array[3] + this.array[5] * rhs.array[6], 67 this.array[3] * rhs.array[1] + this.array[4] * rhs.array[4] + this.array[5] * rhs.array[7], 68 this.array[3] * rhs.array[2] + this.array[4] * rhs.array[5] + this.array[5] * rhs.array[8], 69 this.array[6] * rhs.array[0] + this.array[7] * rhs.array[3] + this.array[8] * rhs.array[6], 70 this.array[6] * rhs.array[1] + this.array[7] * rhs.array[4] + this.array[8] * rhs.array[7], 71 this.array[6] * rhs.array[2] + this.array[7] * rhs.array[5] + this.array[8] * rhs.array[8], 72 ]))); 73 } 74 makeTranspose() { 75 return new Matrix33(new Float32Array((0, compat_1.Array_from_number)([ 76 this.array[0], this.array[3], this.array[6], 77 this.array[1], this.array[4], this.array[7], 78 this.array[2], this.array[5], this.array[8] 79 ]))); 80 } 81} 82exports.Matrix33 = Matrix33; 83//# sourceMappingURL=Matrix33.js.map