-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88a5fb0
commit bdfab80
Showing
5 changed files
with
100 additions
and
66 deletions.
There are no files selected for viewing
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,4 +1,5 @@ | ||
- Multiplication doesn't work with powered expressions, such as x^3, because only "x" is identified | ||
- Division has not been configured for variables, hence all expressions containing '/' and variables | ||
won't be reduced properly | ||
- Pow encounters the same issue as division | ||
- Pow encounters the same issue as division | ||
- Some math shortcuts currently don't work, such as "9x*y" instead of "9x*1y". Same for "(3+2)x" instead of "(3+2)*1x" |
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
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
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
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,57 +1,12 @@ | ||
package net.akami.mask; | ||
|
||
import net.akami.mask.math.MaskExpression; | ||
import net.akami.mask.math.MaskOperator; | ||
import net.akami.mask.utils.ReducerFactory; | ||
|
||
public class MathTest { | ||
|
||
public static void main(String... args) { | ||
|
||
// Creates the math expression | ||
MaskExpression curve = new MaskExpression("3x^2 + 2x + 6 + 2y"); | ||
// Prepares the operator. At least the next calculation will be performed from "curve" | ||
MaskOperator operator = MaskOperator.begin(curve); | ||
|
||
/* null indicates that the result of the calculation "imageFor" doesn't need to be saved as a mask. | ||
Instead, a final temporary variable will contain the result. The boolean indicates that the mask selected | ||
for calculations need to be changed after the first calculation. In fact, as we want to convert the result to | ||
an integer, we want the result of the calculation to be the actual mask, so that we can convert it to an | ||
integer afterwards | ||
*/ | ||
System.out.println("Image : "+operator.imageFor(null, true, 2, 0).asInt()); | ||
System.out.println("Expression : "+curve); | ||
|
||
// The default mask used for calculation is now set to null | ||
operator.end(); | ||
/* Output : | ||
Image : 22 | ||
Expression : 3x^2+2x+6+2y | ||
*/ | ||
|
||
// Let's now imagine we want to change the curve expression, by replacing all the x's by 3. | ||
|
||
/* We need to call begin again because we called end() before. If you know that there will be no calculations | ||
between the last one and this one, you don't need to call end(), neither do you need to call begin() again | ||
*/ | ||
operator.begin(curve); | ||
operator.imageFor(3); | ||
|
||
/* | ||
We use 'false' so the mask used for calculations remains 39+2y, not the result of the calculation. | ||
We use null again so that it affects the temporary variable, and not the mask itself. | ||
When calling asFloat, we need to specify that we want the float value of the temporary variable, | ||
by default the method gives us the value of the default mask, here 39+2y. | ||
*/ | ||
float image1 = operator.imageFor(null, false, 0).asFloat(MaskExpression.TEMP); | ||
float image2 = operator.imageFor(null, false, 2).asFloat(MaskExpression.TEMP); | ||
System.out.println(curve); | ||
System.out.println(image1 + " / " + image2); | ||
|
||
/* Output : 39+2y | ||
39.0 / 43.0 | ||
The expression has indeed been changed. Note that masks are mutable objects, so be careful with constants. | ||
*/ | ||
System.out.println(ReducerFactory.reduce("((1+2)*3)*4")); | ||
System.out.println(ReducerFactory.reduce("(5x+4x)*1y")); | ||
} | ||
} |