make ArithmeticEngine take a list

This commit is contained in:
Talia-12 2023-05-31 18:01:29 +10:00
parent 6f5c652554
commit cf91914f52
3 changed files with 19 additions and 17 deletions

View file

@ -5,21 +5,21 @@ import at.petrak.hexcasting.api.casting.math.HexDir;
import at.petrak.hexcasting.api.casting.math.HexPattern;
public interface Arithmetic {
public String arithName();
String arithName();
public abstract Iterable<HexPattern> opTypes();
Iterable<HexPattern> opTypes();
public abstract Operator getOperator(HexPattern pattern);
Operator getOperator(HexPattern pattern);
public static HexPattern ADD = HexPattern.fromAngles("waaw", HexDir.NORTH_EAST);
public static HexPattern SUB = HexPattern.fromAngles("wddw", HexDir.NORTH_WEST);
public static HexPattern MUL = HexPattern.fromAngles("waqaw", HexDir.SOUTH_EAST);
public static HexPattern DIV = HexPattern.fromAngles("wdedw", HexDir.NORTH_EAST);
public static HexPattern ABS = HexPattern.fromAngles("wqaqw", HexDir.NORTH_EAST);
public static HexPattern POW = HexPattern.fromAngles("wedew", HexDir.NORTH_WEST);
public static HexPattern FLOOR = HexPattern.fromAngles("ewq", HexDir.EAST);
public static HexPattern CEIL = HexPattern.fromAngles("qwe", HexDir.EAST);
public static HexPattern MOD = HexPattern.fromAngles("addwaad", HexDir.NORTH_EAST);
public static HexPattern PACK = HexPattern.fromAngles("eqqqqq", HexDir.EAST);
public static HexPattern UNPACK = HexPattern.fromAngles("qeeeee", HexDir.EAST);
HexPattern ADD = HexPattern.fromAngles("waaw", HexDir.NORTH_EAST);
HexPattern SUB = HexPattern.fromAngles("wddw", HexDir.NORTH_WEST);
HexPattern MUL = HexPattern.fromAngles("waqaw", HexDir.SOUTH_EAST);
HexPattern DIV = HexPattern.fromAngles("wdedw", HexDir.NORTH_EAST);
HexPattern ABS = HexPattern.fromAngles("wqaqw", HexDir.NORTH_EAST);
HexPattern POW = HexPattern.fromAngles("wedew", HexDir.NORTH_WEST);
HexPattern FLOOR = HexPattern.fromAngles("ewq", HexDir.EAST);
HexPattern CEIL = HexPattern.fromAngles("qwe", HexDir.EAST);
HexPattern MOD = HexPattern.fromAngles("addwaad", HexDir.NORTH_EAST);
HexPattern PACK = HexPattern.fromAngles("eqqqqq", HexDir.EAST);
HexPattern UNPACK = HexPattern.fromAngles("qeeeee", HexDir.EAST);
}

View file

@ -31,8 +31,8 @@ public class ArithmeticEngine {
private final Map<HexPattern, OpCandidates> operators = new HashMap<>();
private final Map<HashCons, Operator> cache = new HashMap<>();
public ArithmeticEngine(Arithmetic... arithmetics) {
this.arithmetics = arithmetics;
public ArithmeticEngine(List<Arithmetic> arithmetics) {
this.arithmetics = arithmetics.toArray(new Arithmetic[0]);
for (var arith : arithmetics) {
for (var op : arith.opTypes()) {
operators.compute(op, ($, info) -> {

View file

@ -4,6 +4,8 @@ import at.petrak.hexcasting.api.casting.arithmetic.engine.ArithmeticEngine;
import at.petrak.hexcasting.api.casting.arithmetic.impls.DoubleArithmetic;
import at.petrak.hexcasting.api.casting.arithmetic.impls.Vec3Arithmetic;
import java.util.List;
public class HexArithmetics {
public static ArithmeticEngine ENGINE = new ArithmeticEngine(DoubleArithmetic.INSTANCE, Vec3Arithmetic.INSTANCE);
public static ArithmeticEngine ENGINE = new ArithmeticEngine(List.of(DoubleArithmetic.INSTANCE, Vec3Arithmetic.INSTANCE));
}