com.lizardtech.djvu.anno
Class Mapper

java.lang.Object
  extended by com.lizardtech.djvu.anno.Mapper

public class Mapper
extends java.lang.Object

Maps points from one rectangle to another rectangle. This class represents a relation between the points of two rectangles. Given the coordinates of a point in the first rectangle (input rectangle), function map computes the coordinates of the corresponding point in the second rectangle (the output rectangle). This function actually implements an affine transform which maps the corners of the first rectangle onto the matching corners of the second rectangle. The scaling operation is performed using integer fraction arithmetic in order to maximize accuracy.


Constructor Summary
Mapper()
          Constructs a rectangle mapper.
 
Method Summary
 void clear()
          Resets the rectangle mapper state.
 GRect getInput()
          Query the input rectangle.
 GRect getOutput()
          Query the output rectangle.
 void map(GRect rect)
          Maps a rectangle according to the affine transform.
 int mapX(int x, int y)
          Map a point and return the new x coordinate.
 int mapY(int x, int y)
          Map a point and return the new y coordinate.
 void mirrorx()
          Composes the affine transform with a symmetry with respect to the vertical line crossing the center of the output rectangle.
 void mirrory()
          Composes the affine transform with a symmetry with respect to the horizontal line crossing the center of the output rectangle.
 void rotate()
          Composes the affine transform with a rotation of count quarter turns counter-clockwise.
 void rotate(int count)
          Composes the affine transform with a rotation of count quarter turns counter-clockwise.
 void setInput(GRect rect)
          Sets the input rectangle.
 void setOutput(GRect rect)
          Sets the output rectangle.
 void unmap(GRect rect)
          Maps a rectangle according to the inverse of the affine transform.
 int unmap(int x, int y, boolean needX)
          Maps a point according to the inverse of the affine transform.
 int unmapX(int x, int y)
          Transform the specified point and return the x coordinate
 int unmapY(int x, int y)
          Transform the specified point and return the y coordinate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mapper

public Mapper()
Constructs a rectangle mapper.

Method Detail

clear

public void clear()
Resets the rectangle mapper state. Both the input rectangle and the output rectangle are marked as undefined.


getInput

public GRect getInput()
Query the input rectangle.

Returns:
the input rectangle

getOutput

public GRect getOutput()
Query the output rectangle.

Returns:
the output rectangle

map

public void map(GRect rect)
Maps a rectangle according to the affine transform. This operation consists in mapping the rectangle corners and reordering the corners in the canonical rectangle representation. Variable rect is overwritten with the new rectangle coordinates.

Parameters:
rect - the rectangle to transform

mapX

public int mapX(int x,
                int y)
Map a point and return the new x coordinate.

Parameters:
x - old x coordinate
y - old y coordinate
Returns:
new x coordinate

mapY

public int mapY(int x,
                int y)
Map a point and return the new y coordinate.

Parameters:
x - old x coordinate
y - old y coordinate
Returns:
new y coordinate

mirrorx

public void mirrorx()
Composes the affine transform with a symmetry with respect to the vertical line crossing the center of the output rectangle. This operation essentially is a modification of the match between the corners of the input rectangle and the corners of the output rectangle.


mirrory

public void mirrory()
Composes the affine transform with a symmetry with respect to the horizontal line crossing the center of the output rectangle. This operation essentially is a modification of the match between the corners of the input rectangle and the corners of the output rectangle.


rotate

public void rotate(int count)
Composes the affine transform with a rotation of count quarter turns counter-clockwise. This operation essentially is a modification of the match between the corners of the input rectangle and the corners of the output rectangle.

Parameters:
count - angle to rotate divided by 90

rotate

public void rotate()
Composes the affine transform with a rotation of count quarter turns counter-clockwise. This operation essentially is a modification of the match between the corners of the input rectangle and the corners of the output rectangle.


setInput

public void setInput(GRect rect)
Sets the input rectangle.

Parameters:
rect - input rectangle
Throws:
java.lang.IllegalArgumentException - if the rectangle is empty

setOutput

public void setOutput(GRect rect)
Sets the output rectangle.

Parameters:
rect - output rectangle
Throws:
java.lang.IllegalArgumentException - if the rectangle is empty

unmap

public int unmap(int x,
                 int y,
                 boolean needX)
Maps a point according to the inverse of the affine transform. Variables x and y initially contain the coordinates of a point. This operation overwrites these variables with the coordinates of a second point located in the same position relative to the corners of input rectangle as the first point relative to the matching corners of the input rectangle. Coordinates are rounded to the nearest integer.

Parameters:
x - horizontal coordinate
y - vertical coordinate
needX - true if x should be returned
Returns:
the transformed x or y

unmap

public void unmap(GRect rect)
Maps a rectangle according to the inverse of the affine transform. This operation consists in mapping the rectangle corners and reordering the corners in the canonical rectangle representation. Variable rect is overwritten with the new rectangle coordinates.

Parameters:
rect - rectangle to unmap

unmapX

public int unmapX(int x,
                  int y)
Transform the specified point and return the x coordinate

Parameters:
x - horizontal coordinate
y - vertical coordinate
Returns:
transformed x coordinate

unmapY

public int unmapY(int x,
                  int y)
Transform the specified point and return the y coordinate

Parameters:
x - horizontal coordinate
y - vertical coordinate
Returns:
transformed y coordinate