made all the maths stuff operators.
This commit is contained in:
parent
9ef5a8d15f
commit
67fd933397
|
@ -19,7 +19,18 @@ public interface Arithmetic {
|
|||
HexPattern POW = HexPattern.fromAngles("wedew", HexDir.NORTH_WEST);
|
||||
HexPattern FLOOR = HexPattern.fromAngles("ewq", HexDir.EAST);
|
||||
HexPattern CEIL = HexPattern.fromAngles("qwe", HexDir.EAST);
|
||||
HexPattern SIN = HexPattern.fromAngles("qqqqqaa", HexDir.SOUTH_EAST);
|
||||
HexPattern COS = HexPattern.fromAngles("qqqqqad", HexDir.SOUTH_EAST);
|
||||
HexPattern TAN = HexPattern.fromAngles("wqqqqqadq", HexDir.SOUTH_WEST);
|
||||
HexPattern ARCSIN = HexPattern.fromAngles("ddeeeee", HexDir.SOUTH_EAST);
|
||||
HexPattern ARCCOS = HexPattern.fromAngles("adeeeee", HexDir.NORTH_EAST);
|
||||
HexPattern ARCTAN = HexPattern.fromAngles("eadeeeeew", HexDir.NORTH_EAST);
|
||||
HexPattern ARCTAN2 = HexPattern.fromAngles("deadeeeeewd", HexDir.WEST);
|
||||
HexPattern LOG = HexPattern.fromAngles("eqaqe", HexDir.NORTH_WEST);
|
||||
HexPattern MOD = HexPattern.fromAngles("addwaad", HexDir.NORTH_EAST);
|
||||
|
||||
|
||||
// Vecs
|
||||
HexPattern PACK = HexPattern.fromAngles("eqqqqq", HexDir.EAST);
|
||||
HexPattern UNPACK = HexPattern.fromAngles("qeeeee", HexDir.EAST);
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import at.petrak.hexcasting.api.casting.arithmetic.operator.OperatorBinary;
|
|||
import at.petrak.hexcasting.api.casting.arithmetic.operator.OperatorUnary;
|
||||
import at.petrak.hexcasting.api.casting.iota.DoubleIota;
|
||||
import at.petrak.hexcasting.api.casting.math.HexPattern;
|
||||
import at.petrak.hexcasting.common.casting.arithmetic.operator.OperatorLog;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.DoubleBinaryOperator;
|
||||
|
@ -28,6 +29,14 @@ public enum DoubleArithmetic implements Arithmetic {
|
|||
POW,
|
||||
FLOOR,
|
||||
CEIL,
|
||||
SIN,
|
||||
COS,
|
||||
TAN,
|
||||
ARCSIN,
|
||||
ARCCOS,
|
||||
ARCTAN,
|
||||
ARCTAN2,
|
||||
LOG,
|
||||
MOD
|
||||
);
|
||||
|
||||
|
@ -61,6 +70,22 @@ public enum DoubleArithmetic implements Arithmetic {
|
|||
return make1(Math::floor);
|
||||
} else if (pattern.equals(CEIL)) {
|
||||
return make1(Math::ceil);
|
||||
} else if (pattern.equals(SIN)) {
|
||||
return make1(Math::sin);
|
||||
} else if (pattern.equals(COS)) {
|
||||
return make1(Math::cos);
|
||||
} else if (pattern.equals(TAN)) {
|
||||
return make1(Math::tan);
|
||||
} else if (pattern.equals(ARCSIN)) {
|
||||
return make1(Math::asin);
|
||||
} else if (pattern.equals(ARCCOS)) {
|
||||
return make1(Math::acos);
|
||||
} else if (pattern.equals(ARCTAN)) {
|
||||
return make1(Math::atan);
|
||||
} else if (pattern.equals(ARCTAN2)) {
|
||||
return make2(Math::atan2);
|
||||
} else if (pattern.equals(LOG)) {
|
||||
return OperatorLog.INSTANCE;
|
||||
} else if (pattern.equals(MOD)) {
|
||||
return make2((p, q) -> p % q);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package at.petrak.hexcasting.common.casting.arithmetic.operator
|
||||
|
||||
import at.petrak.hexcasting.api.casting.arithmetic.operator.Operator
|
||||
import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaMultiPredicate
|
||||
import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaPredicate
|
||||
import at.petrak.hexcasting.api.casting.asActionResult
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota
|
||||
import at.petrak.hexcasting.api.casting.mishaps.MishapDivideByZero
|
||||
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes.DOUBLE
|
||||
import kotlin.math.log
|
||||
|
||||
object OperatorLog : Operator(2, IotaMultiPredicate.all(IotaPredicate.ofType(DOUBLE))) {
|
||||
override fun apply(iotas: Iterable<Iota>): Iterable<Iota> {
|
||||
val it = iotas.iterator().withIndex()
|
||||
val value = it.nextDouble(arity)
|
||||
val base = it.nextDouble(arity)
|
||||
if (value <= 0.0 || base <= 0.0 || base == 1.0)
|
||||
throw MishapDivideByZero.of(iotas.first(), iotas.last(), "logarithm")
|
||||
return log(value, base).asActionResult
|
||||
}
|
||||
}
|
|
@ -16,6 +16,13 @@ fun Iterator<IndexedValue<Iota>>.nextList(argc: Int = 0): SpellList {
|
|||
throw MishapInvalidIota.ofType(x, if (argc == 0) idx else argc - (idx + 1), "list")
|
||||
}
|
||||
}
|
||||
|
||||
fun Iterator<IndexedValue<Iota>>.nextDouble(argc: Int = 0): Double {
|
||||
val (idx, x) = this.next()
|
||||
if (x is DoubleIota) return x.double
|
||||
throw MishapInvalidIota.of(x, if (argc == 0) idx else argc - (idx + 1), "double")
|
||||
}
|
||||
|
||||
fun Iterator<IndexedValue<Iota>>.nextInt(argc: Int = 0): Int {
|
||||
val (idx, x) = this.next()
|
||||
if (x is DoubleIota) {
|
||||
|
|
|
@ -11,42 +11,23 @@ import at.petrak.hexcasting.api.casting.math.HexDir;
|
|||
import at.petrak.hexcasting.api.casting.math.HexPattern;
|
||||
import at.petrak.hexcasting.api.misc.MediaConstants;
|
||||
import at.petrak.hexcasting.api.utils.HexUtils;
|
||||
import at.petrak.hexcasting.common.casting.operators.OpEntityHeight;
|
||||
import at.petrak.hexcasting.common.casting.operators.OpEntityLook;
|
||||
import at.petrak.hexcasting.common.casting.operators.OpEntityPos;
|
||||
import at.petrak.hexcasting.common.casting.operators.OpEntityVelocity;
|
||||
import at.petrak.hexcasting.common.casting.operators.akashic.OpAkashicRead;
|
||||
import at.petrak.hexcasting.common.casting.operators.akashic.OpAkashicWrite;
|
||||
import at.petrak.hexcasting.common.casting.operators.circles.OpCircleBounds;
|
||||
import at.petrak.hexcasting.common.casting.operators.circles.OpImpetusDir;
|
||||
import at.petrak.hexcasting.common.casting.operators.circles.OpImpetusPos;
|
||||
import at.petrak.hexcasting.common.casting.operators.eval.OpEval;
|
||||
import at.petrak.hexcasting.common.casting.operators.eval.OpForEach;
|
||||
import at.petrak.hexcasting.common.casting.operators.eval.OpHalt;
|
||||
import at.petrak.hexcasting.common.casting.operators.*;
|
||||
import at.petrak.hexcasting.common.casting.operators.akashic.*;
|
||||
import at.petrak.hexcasting.common.casting.operators.circles.*;
|
||||
import at.petrak.hexcasting.common.casting.operators.eval.*;
|
||||
import at.petrak.hexcasting.common.casting.operators.lists.*;
|
||||
import at.petrak.hexcasting.common.casting.operators.local.OpPeekLocal;
|
||||
import at.petrak.hexcasting.common.casting.operators.local.OpPushLocal;
|
||||
import at.petrak.hexcasting.common.casting.operators.local.*;
|
||||
import at.petrak.hexcasting.common.casting.operators.math.*;
|
||||
import at.petrak.hexcasting.common.casting.operators.math.logic.*;
|
||||
import at.petrak.hexcasting.common.casting.operators.math.trig.*;
|
||||
import at.petrak.hexcasting.common.casting.operators.raycast.OpBlockAxisRaycast;
|
||||
import at.petrak.hexcasting.common.casting.operators.raycast.OpBlockRaycast;
|
||||
import at.petrak.hexcasting.common.casting.operators.raycast.OpEntityRaycast;
|
||||
import at.petrak.hexcasting.common.casting.operators.raycast.*;
|
||||
import at.petrak.hexcasting.common.casting.operators.rw.*;
|
||||
import at.petrak.hexcasting.common.casting.operators.selectors.OpGetCaster;
|
||||
import at.petrak.hexcasting.common.casting.operators.selectors.OpGetEntitiesBy;
|
||||
import at.petrak.hexcasting.common.casting.operators.selectors.OpGetEntityAt;
|
||||
import at.petrak.hexcasting.common.casting.operators.selectors.*;
|
||||
import at.petrak.hexcasting.common.casting.operators.spells.*;
|
||||
import at.petrak.hexcasting.common.casting.operators.spells.great.*;
|
||||
import at.petrak.hexcasting.common.casting.operators.spells.sentinel.OpCreateSentinel;
|
||||
import at.petrak.hexcasting.common.casting.operators.spells.sentinel.OpDestroySentinel;
|
||||
import at.petrak.hexcasting.common.casting.operators.spells.sentinel.OpGetSentinelPos;
|
||||
import at.petrak.hexcasting.common.casting.operators.spells.sentinel.OpGetSentinelWayfind;
|
||||
import at.petrak.hexcasting.common.casting.operators.spells.sentinel.*;
|
||||
import at.petrak.hexcasting.common.casting.operators.stack.*;
|
||||
import at.petrak.hexcasting.common.lib.HexItems;
|
||||
import at.petrak.hexcasting.interop.pehkui.OpGetScale;
|
||||
import at.petrak.hexcasting.interop.pehkui.OpSetScale;
|
||||
import at.petrak.hexcasting.interop.pehkui.PehkuiInterop;
|
||||
import at.petrak.hexcasting.interop.pehkui.*;
|
||||
import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -200,21 +181,21 @@ public class HexActions {
|
|||
// == Advanced Math ==
|
||||
|
||||
public static final ActionRegistryEntry SIN = make("sin",
|
||||
new ActionRegistryEntry(HexPattern.fromAngles("qqqqqaa", HexDir.SOUTH_EAST), OpSin.INSTANCE));
|
||||
new OperationAction(HexPattern.fromAngles("qqqqqaa", HexDir.SOUTH_EAST)));
|
||||
public static final ActionRegistryEntry COS = make("cos",
|
||||
new ActionRegistryEntry(HexPattern.fromAngles("qqqqqad", HexDir.SOUTH_EAST), OpCos.INSTANCE));
|
||||
new OperationAction(HexPattern.fromAngles("qqqqqad", HexDir.SOUTH_EAST)));
|
||||
public static final ActionRegistryEntry TAN = make("tan",
|
||||
new ActionRegistryEntry(HexPattern.fromAngles("wqqqqqadq", HexDir.SOUTH_WEST), OpTan.INSTANCE));
|
||||
new OperationAction(HexPattern.fromAngles("wqqqqqadq", HexDir.SOUTH_WEST)));
|
||||
public static final ActionRegistryEntry ARCSIN = make("arcsin",
|
||||
new ActionRegistryEntry(HexPattern.fromAngles("ddeeeee", HexDir.SOUTH_EAST), OpArcSin.INSTANCE));
|
||||
new OperationAction(HexPattern.fromAngles("ddeeeee", HexDir.SOUTH_EAST)));
|
||||
public static final ActionRegistryEntry ARCCOS = make("arccos",
|
||||
new ActionRegistryEntry(HexPattern.fromAngles("adeeeee", HexDir.NORTH_EAST), OpArcCos.INSTANCE));
|
||||
new OperationAction(HexPattern.fromAngles("adeeeee", HexDir.NORTH_EAST)));
|
||||
public static final ActionRegistryEntry ARCTAN = make("arctan",
|
||||
new ActionRegistryEntry(HexPattern.fromAngles("eadeeeeew", HexDir.NORTH_EAST), OpArcTan.INSTANCE));
|
||||
new OperationAction(HexPattern.fromAngles("eadeeeeew", HexDir.NORTH_EAST)));
|
||||
public static final ActionRegistryEntry ARCTAN2 = make("arctan2",
|
||||
new ActionRegistryEntry(HexPattern.fromAngles("deadeeeeewd", HexDir.WEST), OpArcTan2.INSTANCE));
|
||||
new OperationAction(HexPattern.fromAngles("deadeeeeewd", HexDir.WEST)));
|
||||
public static final ActionRegistryEntry LOGARITHM = make("logarithm",
|
||||
new ActionRegistryEntry(HexPattern.fromAngles("eqaqe", HexDir.NORTH_WEST), OpLog.INSTANCE));
|
||||
new OperationAction(HexPattern.fromAngles("eqaqe", HexDir.NORTH_WEST)));
|
||||
public static final ActionRegistryEntry MODULO = make("modulo",
|
||||
new OperationAction(HexPattern.fromAngles("addwaad", HexDir.NORTH_EAST)));
|
||||
|
||||
|
|
Loading…
Reference in a new issue