-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
5 changed files
with
70 additions
and
17 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
48 changes: 48 additions & 0 deletions
48
src/main/java/lib/math/interpolation/InterpolatingLong.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,48 @@ | ||
package lib.math.interpolation; | ||
|
||
/** | ||
* A Long that can be interpolated using the InterpolatingTreeMap. | ||
* | ||
* @see InterpolatingTreeMap | ||
*/ | ||
public class InterpolatingLong | ||
implements Interpolable<InterpolatingLong>, | ||
InverseInterpolable<InterpolatingLong>, | ||
Comparable<InterpolatingLong> { | ||
public Long value = 0L; | ||
|
||
public InterpolatingLong(Long val) { | ||
value = val; | ||
} | ||
|
||
@Override | ||
public InterpolatingLong interpolate(InterpolatingLong other, double x) { | ||
Long dydx = other.value - value; | ||
Double searchY = dydx * x + value; | ||
return new InterpolatingLong(searchY.longValue()); | ||
} | ||
|
||
@Override | ||
public double inverseInterpolate(InterpolatingLong upper, InterpolatingLong query) { | ||
long upper_to_lower = upper.value - value; | ||
if (upper_to_lower <= 0) { | ||
return 0; | ||
} | ||
long query_to_lower = query.value - value; | ||
if (query_to_lower <= 0) { | ||
return 0; | ||
} | ||
return query_to_lower / (double) upper_to_lower; | ||
} | ||
|
||
@Override | ||
public int compareTo(InterpolatingLong other) { | ||
if (other.value < value) { | ||
return 1; | ||
} else if (other.value > value) { | ||
return -1; | ||
} else { | ||
return 0; | ||
} | ||
} | ||
} |
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