core.field
Class Vec2FieldCache
java.lang.Object
core.field.Vec2Field
core.field.Vec2FieldCache
- public class Vec2FieldCache
- extends Vec2Field
Precomputed Vec2Field on a grid with bilinear interpolation.
A Vec2FieldCache wraps around a given Vec2Field, precomputing the
field on a specified grid in order to speed up later computation.
The continuous values between grids are filled in by bilinear
interpolation.
If get() is called with a point outside the region that is cached,
it will fall through and call get() for the original field.
Constructor Summary |
Vec2FieldCache(Vec2Field field,
Vec2 p1,
Vec2 p2,
int width,
int height)
Constructs a new Vec2FieldCache that approximates "field" inside the
rectangular region whose corners are given by "p1" and "p2". |
Method Summary |
void |
Compute()
Precomputes the field at every point of the grid. |
Vec2 |
get(Vec2 p,
Vec2 f)
Sets "f" to an approximate value of the field at "p". |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
field
private Vec2Field field
p1
private Vec2 p1
p2
private Vec2 p2
width
private int width
height
private int height
size
private int size
x
private float[] x
y
private float[] y
offset
private int[] offset
mx
private double mx
my
private double my
sx
private double sx
sy
private double sy
ox
private double ox
oy
private double oy
Vec2FieldCache
public Vec2FieldCache(Vec2Field field,
Vec2 p1,
Vec2 p2,
int width,
int height)
- Constructs a new Vec2FieldCache that approximates "field" inside the
rectangular region whose corners are given by "p1" and "p2". The number
of horizontal and vertical grid points is given by "width" and "height".
Note that Compute() must be called before any call to get().
Compute
public void Compute()
- Precomputes the field at every point of the grid. This must be called
before any call to get().
get
public Vec2 get(Vec2 p,
Vec2 f)
- Sets "f" to an approximate value of the field at "p". Inside the
cached region, the value is bilinearly interpolated between the four
surrounding grid points, while outside, the original field function
is queried. "p" is not modified
Returns: resulting "f"
- Specified by:
get
in class Vec2Field