summaryrefslogtreecommitdiff
path: root/java/src/org/singinst/uf/presenter/GraphTransform.java
blob: e848ef3153d3bf92277857d687ced54c40c2d704 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package org.singinst.uf.presenter;

import org.singinst.uf.math.InvertableFunction;
import org.singinst.uf.math.LinearTransform;
import org.singinst.uf.math.SimplePoint;

public class GraphTransform {

	public static final GraphTransform IDENTITY = new GraphTransform(LinearTransform.IDENTITY, LinearTransform.IDENTITY);
	private final InvertableFunction transformX;
	private final InvertableFunction transformY;

	public GraphTransform(PlaneBounded from, PlaneBounded to) {
		transformX = new LinearTransform(from.getPlaneBounds().getBoundsX(), to.getPlaneBounds().getBoundsX());
		transformY = new LinearTransform(from.getPlaneBounds().getBoundsY(), to.getPlaneBounds().getBoundsY());
	}

	public GraphTransform(InvertableFunction transformX,
			InvertableFunction transformY) {
		this.transformX = transformX;
		this.transformY = transformY;
	}

	public SimplePoint apply(SimplePoint point) {
		return new SimplePoint(transformX.apply(point.x), transformY.apply(point.y));
	}

	public GraphTransform invert() {
		return new GraphTransform(transformX.invert(), transformY.invert());
	}

	public SimplePoint invert(SimplePoint point) {
		return invert().apply(point);
	}
	
	
}