SymmetricGroup3 .java

com.mojang.math.SymmetricGroup3 (enum): members: P123, P213, P132, P312, P231, P321, permuteVector, permuteAxis, p0, p1, p2, INVERSE_TABLE, CAYLEY_TABLE.

com.mojang.mathenum90 linescommon2.5 KB

API Surface (7)

SymmetricGroup3 compose(final SymmetricGroup3 that)
SymmetricGroup3 inverse()
int permute(final int i)
Direction.Axis permuteAxis(final Direction.Axis axis)
Vector3f permuteVector(final Vector3f v)
Vector3i permuteVector(final Vector3i v)
Matrix3fc transformation()

Fields & Constants (6)

CAYLEY_TABLE
INVERSE_TABLE
p0
p1
p2
transformation

String literals (1)

"Must be 0, 1 or 2, but got "

Code Graph: Dependencies (3)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

SymmetricGroup3.java90 lines · Minecraft 26.3 · verbatim
1
package com.mojang.math;
2
3
import java.util.Arrays;
4
import net.minecraft.core.Direction;
5
import net.minecraft.util.Util;
6
import org.joml.Matrix3f;
7
import org.joml.Matrix3fc;
8
import org.joml.Vector3f;
9
import org.joml.Vector3i;
10
11
public enum SymmetricGroup3 {
12
	P123(0, 1, 2),
13
	P213(1, 0, 2),
14
	P132(0, 2, 1),
15
	P312(2, 0, 1),
16
	P231(1, 2, 0),
17
	P321(2, 1, 0);
18
19
	private final int p0;
20
	private final int p1;
21
	private final int p2;
22
	private final Matrix3fc transformation;
23
	private static final SymmetricGroup3[][] CAYLEY_TABLE = Util.make(() -> {
24
		SymmetricGroup3[] values = values();
25
		SymmetricGroup3[][] table = new SymmetricGroup3[values.length][values.length];
26
27
		for (SymmetricGroup3 first : values) {
28
			for (SymmetricGroup3 second : values) {
29
				int p0 = first.permute(second.p0);
30
				int p1 = first.permute(second.p1);
31
				int p2 = first.permute(second.p2);
32
				SymmetricGroup3 result = Arrays.stream(values).filter(p -> p.p0 == p0 && p.p1 == p1 && p.p2 == p2).findFirst().get();
33
				table[first.ordinal()][second.ordinal()] = result;
34
			}
35
		}
36
37
		return table;
38
	});
39
	private static final SymmetricGroup3[] INVERSE_TABLE = Util.make(() -> {
40
		SymmetricGroup3[] values = values();
41
		return Arrays.stream(values).map(f -> Arrays.stream(values()).filter(s -> f.compose(s) == P123).findAny().get()).toArray(SymmetricGroup3[]::new);
42
	});
43
44
	SymmetricGroup3(final int p0, final int p1, final int p2) {
45
		this.p0 = p0;
46
		this.p1 = p1;
47
		this.p2 = p2;
48
		this.transformation = new Matrix3f().zero().set(this.permute(0), 0, 1.0F).set(this.permute(1), 1, 1.0F).set(this.permute(2), 2, 1.0F);
49
	}
50
51
	public SymmetricGroup3 compose(final SymmetricGroup3 that) {
52
		return CAYLEY_TABLE[this.ordinal()][that.ordinal()];
53
	}
54
55
	public SymmetricGroup3 inverse() {
56
		return INVERSE_TABLE[this.ordinal()];
57
	}
58
59
	public int permute(final int i) {
60
		return switch (i) {
61
			case 0 -> this.p0;
62
			case 1 -> this.p1;
63
			case 2 -> this.p2;
64
			default -> throw new IllegalArgumentException("Must be 0, 1 or 2, but got " + i);
65
		};
66
	}
67
68
	public Direction.Axis permuteAxis(final Direction.Axis axis) {
69
		return Direction.Axis.VALUES[this.permute(axis.ordinal())];
70
	}
71
72
	public Vector3f permuteVector(final Vector3f v) {
73
		float v0 = v.get(this.p0);
74
		float v1 = v.get(this.p1);
75
		float v2 = v.get(this.p2);
76
		return v.set(v0, v1, v2);
77
	}
78
79
	public Vector3i permuteVector(final Vector3i v) {
80
		int v0 = v.get(this.p0);
81
		int v1 = v.get(this.p1);
82
		int v2 = v.get(this.p2);
83
		return v.set(v0, v1, v2);
84
	}
85
86
	public Matrix3fc transformation() {
87
		return this.transformation;
88
	}
89
}
90

Decompiled Minecraft 26.3 source of SymmetricGroup3 (com/mojang/math/SymmetricGroup3.java) with Mojang official mappings, stored verbatim on the site.