1 /*
2 * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package hat.types;
26
27 import jdk.incubator.code.Reflect;
28 import jdk.incubator.code.dialect.java.JavaType;
29 import optkl.IfaceValue;
30
31 import java.util.concurrent.atomic.AtomicBoolean;
32 import java.util.concurrent.atomic.AtomicInteger;
33
34 public interface mat3 extends IfaceValue.mat {
35 Shape shape = IfaceValue.mat.Shape.of( JavaType.FLOAT,3,3);
36 float _00();
37 float _01();
38 float _02();
39 float _10();
40 float _11();
41 float _12();
42 float _20();
43 float _21();
44 float _22();
45
46 AtomicInteger count = new AtomicInteger(0);
47 AtomicBoolean collect = new AtomicBoolean(false);
48 // if (collect.get())count.getAndIncrement();
49 // A mutable variant needed for interface mapping
50 interface Field extends mat3 {
51 @Reflect
52 default void schema(){_00();_01();_02();_10();_11();_12();_20();_21();_22();}
53 void _00(float _00);
54 void _01(float _01);
55 void _02(float _02);
56 void _10(float _10);
57 void _11(float _11);
58 void _12(float _12);
59 void _20(float _20);
60 void _21(float _21);
61 void _22(float _22);
62 default mat3 of(float _00, float _01, float _02, float _10, float _11, float _12, float _20, float _21, float _22) {
63 _00(_00);_01(_01);_02(_02);_10(_10);_11(_11);_12(_12);_20(_20);_21(_21);_22(_22);
64 return this;
65 }
66 default mat3 of(mat3 mat3){
67 of(mat3._00(),mat3._01(),mat3._02(),mat3._10(),mat3._11(),mat3._12(),mat3._20(),mat3._21(),mat3._22() );
68 return this;
69 }
70 }
71
72
73
74
75 static mat3 mat3(float _00, float _01, float _02,float _10, float _11, float _12, float _20, float _21, float _22) {
76 record Impl(float _00, float _01, float _02, float _10, float _11, float _12, float _20, float _21, float _22) implements mat3 {
77 }
78 // if (collect.get())count.getAndIncrement();
79 return new Impl(_00, _01,_02, _10, _11, _12, _20, _21, _22);
80 }
81 static mat3 mat3(mat3 mat3) {return mat3(mat3._00(), mat3._01(), mat3._02(), mat3._10(), mat3._11(), mat3._12(), mat3._20(), mat3._21(), mat3._22());}
82 static mat3 mat3(float scalar) {return mat3(scalar,scalar,scalar,scalar,scalar,scalar,scalar,scalar,scalar);}
83
84 static mat3 add(mat3 l, mat3 r) {return mat3(
85 l._00()+r._00(),l._01()+r._01(),l._02()+r._02(),
86 l._10()+r._10(),l._11()+r._11(),l._12()+r._12(),
87 l._20()+r._20(),l._21()+r._21(),l._22()+r._22()
88 );}
89
90 static mat3 sub(mat3 l, mat3 r) {return mat3(
91 l._00()-r._00(),l._01()-r._01(),l._02()-r._02(),
92 l._10()-r._10(),l._11()-r._11(),l._12()-r._12(),
93 l._20()-r._20(),l._21()-r._21(),l._22()-r._22()
94 );}
95
96 static mat3 mul(mat3 l, mat3 r) {return mat3(
97 l._00()*r._00(),l._01()*r._01(),l._02()*r._02(),
98 l._10()*r._10(),l._11()*r._11(),l._12()*r._12(),
99 l._20()*r._20(),l._21()*r._21(),l._22()*r._22()
100 );}
101
102 static mat3 div(mat3 l, mat3 r) {return mat3(
103 l._00()/r._00(),l._01()/r._01(),l._02()/r._02(),
104 l._10()/r._10(),l._11()/r._11(),l._12()/r._12(),
105 l._20()/r._20(),l._21()/r._21(),l._22()/r._22()
106 );}
107 }