-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added toGlobalPosition(Quantity, Quantity), toLocalPosition(Quantity,…
… Quantity)
- Loading branch information
Showing
1 changed file
with
48 additions
and
1 deletion.
There are no files selected for viewing
49 changes: 48 additions & 1 deletion
49
src/generator/com/perunlabs/tool/jvalgen/var/spec/QuantitySpec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,58 @@ | ||
package com.perunlabs.tool.jvalgen.var.spec; | ||
|
||
import static com.perunlabs.tool.jvalgen.Utils.list; | ||
import static com.perunlabs.tool.jvalgen.var.expr.VComponentAccesss.vComponentAccess; | ||
import static com.perunlabs.tool.jvalgen.var.expr.VCreate.vCreate; | ||
import static com.perunlabs.tool.jvalgen.var.spec.AllVTypes.QUANTITY; | ||
import static com.perunlabs.tool.jvalgen.var.type.VFunctions.vFunction; | ||
import static com.perunlabs.tool.jvalgen.var.type.VParam.vParam; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.perunlabs.tool.jvalgen.var.expr.VExpression; | ||
import com.perunlabs.tool.jvalgen.var.type.VFunction; | ||
import com.perunlabs.tool.jvalgen.var.type.VParam; | ||
|
||
public class QuantitySpec { | ||
private QuantitySpec() {} | ||
|
||
public static final ImmutableList<VFunction> ALL_OPERATIONS = ImmutableList.of(); | ||
public static final VFunction TO_GLOBAL_POSITION = toGlobalPosition(); | ||
public static final VFunction TO_LOCAL_POSITION = toLocalPosition(); | ||
|
||
public static final ImmutableList<VFunction> ALL_OPERATIONS = ImmutableList.of( | ||
TO_GLOBAL_POSITION, TO_LOCAL_POSITION); | ||
|
||
private static VFunction toGlobalPosition() { | ||
VParam quantity = vParam(QUANTITY, "quantity"); | ||
VParam position = vParam(QUANTITY, "position"); | ||
|
||
VExpression quantityVector = vComponentAccess(quantity, QUANTITY.vector); | ||
VExpression quantityAngle = vComponentAccess(quantity, QUANTITY.angle); | ||
|
||
VExpression positionAngle = vComponentAccess(position, QUANTITY.angle); | ||
|
||
VExpression positionedVector = VectorSpec.TO_GLOBAL_POINT.vCall(quantityVector, position); | ||
VExpression positionedAngle = FloatSpec.ADD.vCall(quantityAngle, positionAngle); | ||
|
||
VExpression result = vCreate(QUANTITY, list(positionedVector, positionedAngle)); | ||
|
||
return vFunction(QUANTITY, QUANTITY, "toGlobalPosition", list(quantity, position), result, | ||
false); | ||
} | ||
|
||
private static VFunction toLocalPosition() { | ||
VParam quantity = vParam(QUANTITY, "quantity"); | ||
VParam position = vParam(QUANTITY, "position"); | ||
|
||
VExpression quantityVector = vComponentAccess(quantity, QUANTITY.vector); | ||
VExpression quantityAngle = vComponentAccess(quantity, QUANTITY.angle); | ||
|
||
VExpression positionAngle = vComponentAccess(position, QUANTITY.angle); | ||
|
||
VExpression positionedVector = VectorSpec.TO_LOCAL_POINT.vCall(quantityVector, position); | ||
VExpression positionedAngle = FloatSpec.SUB.vCall(quantityAngle, positionAngle); | ||
|
||
VExpression result = vCreate(QUANTITY, list(positionedVector, positionedAngle)); | ||
|
||
return vFunction(QUANTITY, QUANTITY, "toLocalPosition", list(quantity, position), result, false); | ||
} | ||
} |