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

Variable Index

 o PERCENT_MARGIN
The default value for recessing the bounding box of the drawing from the edges of the drawing canvas.

Constructor Index

 o LinearMap()
Create an empty LinearMap instantiation.
 o LinearMap(DoublePoint, DoubleDimension, Rectangle)
Create a LinearMap instantiation.
 o LinearMap(DoublePoint, DoubleDimension, Rectangle, int)
Create a LinearMap instantiation.
 o LinearMap(int)
Create an empty LinearMap instantiation.

Method Index

 o copy()
Make a copy of this linear map.
 o equals(Object)
Determines whether two mappings are equal.
 o getAreaOrigin()
Get the source area origin
 o getAreaSize()
Get the source area dimension
 o getBoundRect()
Gets the bounding rectangle for the mapping.
 o getDrawRectangle()
Get the target area rectangle
 o getEdgeFactor()
Get the mapping edge factor.
 o getIntersect()
Get the intersection of the mapping.
 o getMagnifyOK()
Indicates if it is OK for the mapping to cause the result to be magnified.
 o getSlope()
Get the slope of the mapping.
 o map(double, double)
Apply the mapping on the co-ordinates.
 o map(double, double, double, double)
Apply the mapping on the rectangle co-ordinates.
 o map(DoublePoint)
Apply the mapping on the supplied point.
 o map(DoubleRectangle)
Apply the mapping on the rectangle.
 o map(int, int)
Apply the mapping on the co-ordinates.
 o map(Point)
Apply the mapping on the supplied point.
 o revMap(double, double)
Perform the reverse mapping on the co-ordinates.
 o revMap(double, double, double, double)
Perform the reverse mapping to a described rectangle.
 o revMap(DoublePoint)
Perform the reverse mapping on the supplied point.
 o revMap(int, int)
Perform the reverse mapping on the co-ordinates.
 o revMap(Point)
Perform the reverse mapping on the supplied point.
 o scale(double, double)
Scale the supplied width and height using the mapping.
 o scaleX(double)
Scale the given x dimension.
 o scaleY(double)
Scale the given y dimension.
 o setMagnifyOK(boolean)
Sets the magnification rule.
 o setMap()
Set-up the mapping.
 o setMap(DoublePoint, DoubleDimension, Rectangle)
Set-up the mapping.
 o setMap(Rectangle, Dimension)
Set-up the mapping.
 o setPercentMargin(int)
Sets the size of the area reserved for the edge margin.
 o toString()
Returns a representation of this mapping as a string.

Variables

 o 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.

Constructors

 o LinearMap
 public LinearMap()
Create an empty LinearMap instantiation. The object is created with a default mapping defined.

See Also:
setMap
 o 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
 o 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
 o 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

Methods

 o 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
 o 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.
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o getAreaOrigin
 public DoublePoint getAreaOrigin()
Get the source area origin

Returns:
the source area origin
 o getAreaSize
 public DoubleDimension getAreaSize()
Get the source area dimension

Returns:
the source area dimension
 o getDrawRectangle
 public Rectangle getDrawRectangle()
Get the target area rectangle

Returns:
the target area rectangle
 o 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
 o getSlope
 public DoublePoint getSlope()
Get the slope of the mapping. Namely, return the m of p' = m * p + b.

Returns:
the mapping slope
 o getIntersect
 public DoublePoint getIntersect()
Get the intersection of the mapping. Namely, return the b of p' = m * p + b.

Returns:
the mapping intersection
 o copy
 public LinearMap copy()
Make a copy of this linear map.

Returns:
a copy of this linear map
 o 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.
 o 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
 o 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