All Packages Class Hierarchy This Package Previous Next Index
Class att.grappa.LinearMap
java.lang.Object
|
+----java.util.Observable
|
+----att.grappa.LinearMap
- public class LinearMap
- extends Observable
This class is for scaling co-ordinates to fit a drawing to a specific area.
It provides methods for calculating and applying a linear mapping of the
form:
p' = m * p + b
given a starting rectangular containing area and a target rectangular
drawing area.
- Version:
- 1.1, 30 Sep 1999; Copyright 1996 - 1999 by AT&T Corp.
- Author:
- John Mocenigo, Research @ AT&T Labs
-
PERCENT_MARGIN
- The default value for recessing the bounding box of the drawing from the
edges of the drawing canvas.
-
LinearMap()
- Create an empty
LinearMap
instantiation.
-
LinearMap(DoublePoint, DoubleDimension, Rectangle)
- Create a
LinearMap
instantiation.
-
LinearMap(DoublePoint, DoubleDimension, Rectangle, int)
- Create a
LinearMap
instantiation.
-
LinearMap(int)
- Create an empty
LinearMap
instantiation.
-
copy()
- Make a copy of this linear map.
-
equals(Object)
- Determines whether two mappings are equal.
-
getAreaOrigin()
- Get the source area origin
-
getAreaSize()
- Get the source area dimension
-
getBoundRect()
- Gets the bounding rectangle for the mapping.
-
getDrawRectangle()
- Get the target area rectangle
-
getEdgeFactor()
- Get the mapping edge factor.
-
getIntersect()
- Get the intersection of the mapping.
-
getMagnifyOK()
- Indicates if it is OK for the mapping to cause the result to be magnified.
-
getSlope()
- Get the slope of the mapping.
-
map(double, double)
- Apply the mapping on the co-ordinates.
-
map(double, double, double, double)
- Apply the mapping on the rectangle co-ordinates.
-
map(DoublePoint)
- Apply the mapping on the supplied point.
-
map(DoubleRectangle)
- Apply the mapping on the rectangle.
-
map(int, int)
- Apply the mapping on the co-ordinates.
-
map(Point)
- Apply the mapping on the supplied point.
-
revMap(double, double)
- Perform the reverse mapping on the co-ordinates.
-
revMap(double, double, double, double)
- Perform the reverse mapping to a described rectangle.
-
revMap(DoublePoint)
- Perform the reverse mapping on the supplied point.
-
revMap(int, int)
- Perform the reverse mapping on the co-ordinates.
-
revMap(Point)
- Perform the reverse mapping on the supplied point.
-
scale(double, double)
- Scale the supplied width and height using the mapping.
-
scaleX(double)
- Scale the given x dimension.
-
scaleY(double)
- Scale the given y dimension.
-
setMagnifyOK(boolean)
- Sets the magnification rule.
-
setMap()
- Set-up the mapping.
-
setMap(DoublePoint, DoubleDimension, Rectangle)
- Set-up the mapping.
-
setMap(Rectangle, Dimension)
- Set-up the mapping.
-
setPercentMargin(int)
- Sets the size of the area reserved for the edge margin.
-
toString()
- Returns a representation of this mapping as a string.
PERCENT_MARGIN
public static final int PERCENT_MARGIN
- The default value for recessing the bounding box of the drawing from the
edges of the drawing canvas. It represents a percentage of the total
canvas width (or height, whichever is controlling) that should be reserved,
in total, for a margin. The actual margin is half of that width
(or height) on each side of the canvas.
LinearMap
public LinearMap()
- Create an empty
LinearMap
instantiation.
The object is created with a default mapping defined.
- See Also:
- setMap
LinearMap
public LinearMap(int pct)
- Create an empty
LinearMap
instantiation.
The object is created with the specified edge margin and
a default mapping.
- Parameters:
- pct - the value to use for the edge margin, expressed as a percentage
- See Also:
- PERCENT_MARGIN, setMap
LinearMap
public LinearMap(DoublePoint areaOrigin,
DoubleDimension areaSize,
Rectangle drawRectangle)
- Create a
LinearMap
instantiation.
The object is created and the mapping requested is defined.
- Parameters:
- areaOrigin - the top-left point of the rectangle bounding the area to be mapped
- areaSize - the dimensions of the rectangle bounding the area to be mapped
- drawRectangle - the rectangle defining the drawing area which is the target of the mapping
LinearMap
public LinearMap(DoublePoint areaOrigin,
DoubleDimension areaSize,
Rectangle drawRectangle,
int pct)
- Create a
LinearMap
instantiation.
The object is created with the specified edge margin,
and the mapping requested is defined.
- Parameters:
- areaOrigin - the top-left point of the rectangle bounding the area to be mapped
- areaSize - the dimensions of the rectangle bounding the area to be mapped
- drawRectangle - the rectangle defining the drawing area which is the target of the mapping
- pct - the value to use for the edge margin, expressed as a percentage
- See Also:
- PERCENT_MARGIN
setMap
public LinearMap setMap()
- Set-up the mapping.
The mapping will be from a unit rectangle to a unit rectangle, with some
adjustment for the edge margin.
- Returns:
- the previous linear mapping in effect
getMagnifyOK
public boolean getMagnifyOK()
- Indicates if it is OK for the mapping to cause the result to be magnified.
- Returns:
- true if magnification is allowed, false otherwise.
setMagnifyOK
public boolean setMagnifyOK(boolean value)
- Sets the magnification rule.
When set true, the mapping is allowed to cause the result to be magnified
whenever the source rectangle is smaller than the target rectangle.
When false, the mapping remains 1-to-1 whenever possible.
- Parameters:
- value - the new value for the magnification rule
- Returns:
- the former value
setPercentMargin
public int setPercentMargin(int pct)
- Sets the size of the area reserved for the edge margin.
The value is expressed as a percentage of the controlling dimension
(width or height) that will be reserved for an edge margin in total
(i.e., both sides, so half of that is the actual minimum margin width
(or height).
- Parameters:
- pct - the new value of the edge margin percentage
- Returns:
- the former value
setMap
public LinearMap setMap(Rectangle box,
Dimension size)
- Set-up the mapping.
The mapping will be from the given rectangle to a rectangle
with the given dimension located at the origin, with some
adjustment for the edge margin.
- Parameters:
- box - the bounding box of the source area
- size - the size of the target area
- Returns:
- the previous linear mapping in effect
setMap
public LinearMap setMap(DoublePoint areaOrigin,
DoubleDimension areaSize,
Rectangle drawRectangle)
- Set-up the mapping.
The mapping will be from the rectangle described by the
given origin and dimension to the given rectangle, with some
adjustment for the edge margin.
- Parameters:
- areaOrigin - the origin of the source area (top-left corner)
- areaSize - the size of the source area
- drawRectangle - the target rectangle
- Returns:
- the previous linear mapping in effect
revMap
public Point revMap(Point p)
- Perform the reverse mapping on the supplied point.
The point in the target area will be mapped to the corresponding point
in the source area.
- Parameters:
- p - the point in the target area
- Returns:
- the point in the source area
revMap
public Point revMap(int x,
int y)
- Perform the reverse mapping on the co-ordinates.
The co-ordinates in the target area will be mapped to the
corresponding point in the source area.
- Parameters:
- x - the x co-ordinate in the target area
- y - the y co-ordinate in the target area
- Returns:
- the point in the source area
revMap
public DoublePoint revMap(DoublePoint p)
- Perform the reverse mapping on the supplied point.
The point in the target area will be mapped to the corresponding point
in the source area.
- Parameters:
- p - the point in the target area
- Returns:
- the point in the source area
revMap
public DoublePoint revMap(double x,
double y)
- Perform the reverse mapping on the co-ordinates.
The co-ordinates in the target area will be mapped to the
corresponding point in the source area.
- Parameters:
- x - the x co-ordinate in the target area
- y - the y co-ordinate in the target area
- Returns:
- the point in the source area
revMap
public DoubleRectangle revMap(double x,
double y,
double w,
double h)
- Perform the reverse mapping to a described rectangle.
The rectangle in the target area will be mapped to the
corresponding rectangle in the source area.
- Parameters:
- x - the top-left x co-ordinate of the rectangle in the target area
- y - the top-left y co-ordinate of the rectangle in the target area
- w - the width of the rectangle in the target area
- h - the height of the rectangle in the target area
- Returns:
- the rectangle in the source area
map
public DoublePoint map(DoublePoint p)
- Apply the mapping on the supplied point.
The point in the source area will be mapped to the corresponding point
in the target area.
- Parameters:
- p - the point in the source area
- Returns:
- the point in the target area
map
public DoublePoint map(double x,
double y)
- Apply the mapping on the co-ordinates.
The co-ordinates in the source area will be mapped to the
corresponding point in the target area.
- Parameters:
- x - the x co-ordinate in the source area
- y - the y co-ordinate in the source area
- Returns:
- the point in the target area
map
public Point map(Point p)
- Apply the mapping on the supplied point.
The point in the source area will be mapped to the corresponding point
in the target area.
- Parameters:
- p - the point in the source area
- Returns:
- the point in the target area
map
public Point map(int x,
int y)
- Apply the mapping on the co-ordinates.
The co-ordinates in the source area will be mapped to the
corresponding point in the target area.
- Parameters:
- x - the x co-ordinate in the source area
- y - the y co-ordinate in the source area
- Returns:
- the point in the target area
map
public DoubleRectangle map(DoubleRectangle r)
- Apply the mapping on the rectangle.
The rectangle in the source area will be mapped to the
corresponding rectangle in the target area.
- Parameters:
- r - the rectangle in the source area
- Returns:
- the rectangle in the target area
map
public DoubleRectangle map(double x,
double y,
double w,
double h)
- Apply the mapping on the rectangle co-ordinates.
The rectangle in the source area described by
the given co-ordinates will be mapped to the
corresponding rectangle in the target area.
- Parameters:
- x - the x co-ordinate in the source area of the top-left rectangle corner
- y - the y co-ordinate in the source area of the top-left rectangle corner
- w - the width in the source area of the rectangle
- h - the height in the source area of the rectangle
- Returns:
- the rectangle in the target area
scale
public DoubleDimension scale(double width,
double height)
- Scale the supplied width and height using the mapping.
- Parameters:
- width - the x-dimension in the source area
- height - the y-dimension in the source area
- Returns:
- the dimension in the target area
scaleX
public double scaleX(double x)
- Scale the given x dimension.
- Parameters:
- x - the x dimension in the source area
- Returns:
- the x dimension in the target area
scaleY
public double scaleY(double y)
- Scale the given y dimension.
- Parameters:
- y - the y dimension in the source area
- Returns:
- the y dimension in the target area
getAreaOrigin
public DoublePoint getAreaOrigin()
- Get the source area origin
- Returns:
- the source area origin
getAreaSize
public DoubleDimension getAreaSize()
- Get the source area dimension
- Returns:
- the source area dimension
getDrawRectangle
public Rectangle getDrawRectangle()
- Get the target area rectangle
- Returns:
- the target area rectangle
equals
public boolean equals(Object obj)
- Determines whether two mappings are equal. Two instances of
LinearMap
are equal if the values of their
slope and intersection are equal.
- Parameters:
- obj - an object to be compared with this point.
- Returns:
-
true
if the object to be compared is
an instance of LinearMap
and has
the same values; false
otherwise.
- Overrides:
- equals in class Object
- See Also:
- getSlope, getIntersect
getSlope
public DoublePoint getSlope()
- Get the slope of the mapping.
Namely, return the
m
of p' = m * p + b
.
- Returns:
- the mapping slope
getIntersect
public DoublePoint getIntersect()
- Get the intersection of the mapping.
Namely, return the
b
of p' = m * p + b
.
- Returns:
- the mapping intersection
copy
public LinearMap copy()
- Make a copy of this linear map.
- Returns:
- a copy of this linear map
getEdgeFactor
public double getEdgeFactor()
- Get the mapping edge factor.
The edge factor is the ratio of the dominant axis of the area recessed
by the margin percentage to the corresponding axis of the total area
available.
- Returns:
- the edge factor.
getBoundRect
public DoubleRectangle getBoundRect()
- Gets the bounding rectangle for the mapping. The bounding rectangle is
the reverse mapping of the drawing area into the original co-ordinates.
- Returns:
- the bounding rectangle
toString
public String toString()
- Returns a representation of this mapping as a string.
- Returns:
- a string representation of this mapping,
including the values of its slope and intersection.
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index