Skip to content

Commit

Permalink
Merge dev into master
Browse files Browse the repository at this point in the history
Merge Dev into Master
  • Loading branch information
tiggerbiggo authored Jun 15, 2018
2 parents 2b0832d + a6275e1 commit 9fa6746
Show file tree
Hide file tree
Showing 53 changed files with 2,210 additions and 762 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
out/
*.gif
*.iml
/target/
imgs/
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>PrimaPlay</groupId>
<artifactId>Play</artifactId>
<version>a1.0-dev</version>
<version>a1.1</version>
<build>
<plugins>
<plugin>
Expand All @@ -21,5 +21,4 @@
</plugins>
</build>
<packaging>jar</packaging>

</project>
147 changes: 76 additions & 71 deletions src/main/java/com/tiggerbiggo/primaplay/calculation/Calculation.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,83 +4,88 @@
* A class containing various math based utilities.
*/
public class Calculation {
/**
* Linearly interpolates between 2 double values using the formula f1+(a*(f2-f1)).
* Any valid double values are acceptable, but values outside
* intended range may produce strange results.
*
* @param f1 Start number
* @param f2 End number
* @param a Interpolation coefficient, intended values between 0.0 and 1.0
* @return Result of the interpolation com.tiggerbiggo.primaplay.calculation
*/
public static double lerp(double f1, double f2, double a)
{
return f1+(a*(f2-f1));
}

/**
* Performs a lerp operation, then clamps the result between the min and max values given.
* @param f1 Start number
* @param f2 End number
* @param a Interpolation coefficient
* @param min Min value
* @param max Max value
* @return Result of the com.tiggerbiggo.primaplay.calculation
*/
public static double clampedLerp(double f1, double f2, double a, double min, double max) {
return clamp(min, max, lerp(f1, f2, a));
}
/**
* Linearly interpolates between 2 double values using the formula f1+(real*(f2-f1)). Any valid
* double values are acceptable, but values outside intended range may produce strange results.
*
* @param f1 Start numberp
* @param f2 End number
* @param a Interpolation coefficient, intended values between 0.0 and 1.0
* @return Result of the interpolation com.tiggerbiggo.primaplay.calculation
*/
public static double lerp(double f1, double f2, double a) {
return f1 + (a * (f2 - f1));
}

/**
* Clamps a given value between a min and max value, e.g
* (0, 5, 5.8) would yield 5, (0, 5, -1.3) would yield 0 and (0, 5, 3.2) would yield 3.2
*
* @param min Min value for the clamp operation
* @param max Max value for the clamp operation
* @param n Number to clamp
* @return The clamped value
*/
public static double clamp(double min, double max, double n) {
n = Math.max(min, n);
n = Math.min(max, n);
/**
* Performs real lerp operation, then clamps the result between the min and max values given.
*
* @param f1 Start number
* @param f2 End number
* @param a Interpolation coefficient
* @param min Min value
* @param max Max value
* @return Result of the com.tiggerbiggo.primaplay.calculation
*/
public static double clampedLerp(double f1, double f2, double a, double min, double max) {
return clamp(min, max, lerp(f1, f2, a));
}

return n;
}
/**
* Clamps real given value between real min and max value, e.g (0, 5, 5.8) would yield 5, (0, 5,
* -1.3) would yield 0 and (0, 5, 3.2) would yield 3.2
*
* @param min Min value for the clamp operation
* @param max Max value for the clamp operation
* @param n Number to clamp
* @return The clamped value
*/
public static double clamp(double min, double max, double n) {
n = Math.max(min, n);
n = Math.min(max, n);

/**A simple modulo function
*
* @param in Number to loop
* @param mod Modulo to loop within
* @return Result
*/
public static double mod(double in, double mod)
{
return in%mod;
}
return n;
}

public static double modLoop(double in, double mod, boolean loop)
{
in = Math.abs(in);
in = mod(in, mod);
/**
* A simple modulo function
*
* @param in Number to loop
* @param mod Modulo to loop within
* @return Result
*/
public static double mod(double in, double mod) {
return in % mod;
}

if(loop) {
if (in < (mod / 2)) in *= 2;
else {
in -= mod / 2;
in = mod - (in * 2);
}
}
return in;
}
public static double mod(double in){
return mod(in,1);
}

public static double modLoop(double in, double mod, boolean loop) {
in = Math.abs(in);
in = mod(in, mod);

/**
* Normalises a number to between 0 and 1, optionally looped
* @param in The number to bound
* @param loop Whether to loop the number so it goes from 0 to 1, then back to 0
* @return The normalised number
*/
public static double modLoop(double in, boolean loop) {
return modLoop(in, 1, loop);
if (loop) {
if (in < (mod / 2)) {
in *= 2;
} else {
in -= mod / 2;
in = mod - (in * 2);
}
}
return in;
}

/**
* Normalises real number to between 0 and 1, optionally looped
*
* @param in The number to bound
* @param loop Whether to loop the number so it goes from 0 to 1, then back to 0
* @return The normalised number
*/
public static double modLoop(double in, boolean loop) {
return modLoop(in, 1, loop);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.tiggerbiggo.primaplay.calculation;

public class ComplexNumber {

//Stored complex number in the form real + bi
double real, imaginary;

public ComplexNumber(double real, double imaginary) {
this.real = real;
this.imaginary = imaginary;
}

public ComplexNumber(Vector2 in) {
this(in.X(), in.Y());
}

public ComplexNumber() {
this(0, 0);
}

public Vector2 asVector() {
return new Vector2(this);
}

public ComplexNumber add(ComplexNumber B) {
return new ComplexNumber(real + B.real, imaginary + B.imaginary);
}

public ComplexNumber multiply(ComplexNumber B) {
double a, b, c, d, r, i;

a = real;
b = imaginary;

c = B.real;
d = B.imaginary;

r = (a * c) - (b * d);
i = (a * d) + (b * c);

return new ComplexNumber(r, i);
}

public ComplexNumber power(int powerOf) {
ComplexNumber c = this.clone();
ComplexNumber c2 = this.clone();
for (int i = 0; i < powerOf; i++) {
c2 = c.multiply(c2);
}
return this;
}
/*
(real+bi)(c+di)
ac + adi + bci + bdi^2
ac + adi + bci - bd
simple = ac-bd
complex = ad + bc
*
* */

public ComplexNumber clone() {
return new ComplexNumber(real, imaginary);
}
}
Loading

0 comments on commit 9fa6746

Please sign in to comment.