forked from fadookie/particleman
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MinAngle, Fix Asin/Atan/Acos functions
- Loading branch information
1 parent
df14efb
commit e9f65b2
Showing
5 changed files
with
32 additions
and
3 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
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
28 changes: 28 additions & 0 deletions
28
src/main/java/com/eliotlash/molang/functions/utility/MinAngle.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.eliotlash.molang.functions.utility; | ||
|
||
import com.eliotlash.molang.ast.Expr; | ||
import com.eliotlash.molang.functions.Function; | ||
import com.eliotlash.molang.utils.Interpolations; | ||
import com.eliotlash.molang.variables.ExecutionContext; | ||
|
||
public class MinAngle extends Function { | ||
|
||
public MinAngle(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public int getRequiredArguments() { | ||
return 3; | ||
} | ||
|
||
@Override | ||
public double _evaluate(Expr[] arguments, ExecutionContext ctx) { | ||
double result = this.evaluateArgument(arguments, ctx, 0); | ||
// Clamp the result to -360 to 360, then add 360 to make it positive, then mod 360 to get the positive angle | ||
result = ((result % 360) + 360) % 360; | ||
// If the result is greater than 180, subtract 360 to get the negative angle | ||
if (result > 179) result -= 360; | ||
return result; | ||
} | ||
} |
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