Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract class Func {
- public abstract double apply(double x);
- public Func scale(double fx, double fy) {
- final Func that = this;
- return new Func() {
- public double apply(double x) {
- return that.apply(x/fx)*fy;
- }
- };
- }
- public Func shift(double dx, double dy) {
- final Func that = this;
- return new Func() {
- public double apply(double x) {
- return that.apply(x-dx)+dy;
- }
- };
- }
- public Func combine(double p, Func other) {
- final Func that = this;
- return new Func() {
- public double apply(double x) {
- if(x <= p) return that.apply(x);
- else return other.apply(x);
- }
- };
- }
- public Func flipX() {
- return scale(-1, 1).shift(1, 0);
- }
- public Func flipY() {
- return scale(1, -1).shift(0, 1);
- }
- public Func flipXY() {
- return scale(-1, -1).shift(1, 1);
- }
- public Func inOut() {
- return scale(0.5, 0.5).combine(
- 0.5,
- flipXY().scale(0.5, 0.5).shift(0.5, 0.5));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement