|
GeoSoft API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object Region
A Region is simply an area, as the name implies, and is implemented as a so called "y-x-banded" array of rectangles; Each Region is made up of a certain number of rectangles sorted by y coordinate first, and then by x coordinate.
Furthermore, the rectangles are banded such that every rectangle with a given upper-left y coordinate (y1) will have the same lower-right y coordinate (y2) and vice versa. If a rectangle has scanlines in a band, it will span the entire vertical distance of the band. This means that some areas that could be merged into a taller rectangle will be represented as several shorter rectangles to account for shorter rectangles to its left or right but within its "vertical scope".
An added constraint on the rectangles is that they must cover as much horizontal area as possible. E.g. no two rectangles in a band are allowed to touch. Whenever possible, bands will be merged together to cover a greater vertical distance (and thus reduce the number of rectangles). Two bands can be merged only if the bottom of one touches the top of the other and they have rectangles in the same places (of the same width, of course). This maintains the y-x-banding.
Region operations includes add (union), subtract, intersect, and exclusive-or.
This class corresponds to Region.c of the X11 distribution and the implemntation is based on it.
The Region is essentially equivalent to an AWT Area but with different back-end implementation. Becnhmarking proves it more than 100 times faster than AWT Area for binary CAG operations,
Thanks to:
Constructor Summary | |
Region()
Create an empty region. |
|
Region(Box box)
Create a region consisting of one rectangle as specified. |
|
Region(int[] x,
int[] y)
Create the region covering the (possibly complex) polygon specified by the x and y parameters. |
|
Region(int x,
int y,
int width,
int height)
Create a region consisting of one rectangle as specified. |
|
Region(Rect rectangle)
Create a region constituting of a single rectangle as specified. |
|
Region(Region region)
Create a region as a copy of the specified region. |
Method Summary | |
void |
clear()
Clear the region. |
Object |
clone()
Clone this region. |
void |
collapse()
Collapse the region into its extent box. |
Area |
createArea()
Convert this region to an AWT Area. |
boolean |
equals(Object object)
Return true if this region equals the specified object. |
Rect |
getExtent()
Return the extent of the region. |
int |
getNRectangles()
Return the number of rectangles in the region. |
void |
intersect(Rect rectangle)
Leave this region as the intersection between this region and the specified rectangle. |
void |
intersect(Region region)
Leave this region as the intersection between this region and the specified region. |
static Region |
intersect(Region region,
Rect rectangle)
Create a new region as the intersection between a region and a rectangle. |
static Region |
intersect(Region r1,
Region r2)
Create a new region as the intersection between two specified regions. |
boolean |
isEmpty()
Return true if the region is empty. |
boolean |
isInside(int x,
int y)
Return true if the specified point is inside this region. |
boolean |
isInside(Rect rectangle)
Return true if the specified rectangle is inside this region. |
boolean |
isInsideOf(Rect rectangle)
Return true if this region is inside of the specified rectangle. |
boolean |
isIntersecting(Rect rectangle)
Return true if the specified rectangle intersect this region. |
boolean |
isIntersecting(Region region)
Return true if the specified region intersect this region. |
void |
offset(int dx,
int dy)
Offset the entire region a specified distance. |
void |
set(Rect rectangle)
Set the content of this region according to the specified rectangle. |
void |
set(Region region)
Set the content of this region according to the specified region. |
void |
subtract(Rect rectangle)
Subtract the specified rectangle from this region. |
void |
subtract(Region region)
Subtract the specified region from this region. |
static Region |
subtract(Region region,
Rect rectangle)
Create a new region as the subtraction of a rectangle from a region. |
static Region |
subtract(Region r1,
Region r2)
Create a new region as the subtraction of one region from another. |
void |
union(Rect rectangle)
Union this region with the specified rectangle. |
void |
union(Region region)
Union this region with the specified region. |
static Region |
union(Region region,
Rect rectangle)
Create a new region as the union between a region and a rectangle. |
static Region |
union(Region r1,
Region r2)
Create a new region as the union between two specified regions. |
void |
xor(Rect rectangle)
Leave the exclusive-or between this and the specified rectangle in this region. |
void |
xor(Region region)
Leave the exclusive-or between this and the specified region in this region. |
static Region |
xor(Region region,
Rect rectangle)
Do an exlusive-or operation between a regions and a rectangle and return the result. |
static Region |
xor(Region r1,
Region r2)
Do an exlusive-or operation between two regions and return the result. |
Methods inherited from class Object |
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Region()
public Region(int[] x, int[] y)
x
- X values of polygon vertices.y
- Y values of polygon vertices.public Region(Rect rectangle)
rectangle
- Rectangle to create region from.public Region(int x, int y, int width, int height)
x
- X position of upper left corner of rectangle.y
- Y position of upper left corner of rectangle.width
- Width of rectangle.height
- Height of rectangle.public Region(Box box)
box
- Box specification of rectangle to create region from.public Region(Region region)
region
- Region to copy.Method Detail |
public Object clone()
public Area createArea()
Note: The AWT classes are referenced explicitly here rather tham importing them to indicate that the Region implementation does not dependent on the AWT.
public void set(Region region)
region
- Region to copy.public void set(Rect rectangle)
rectangle
- Rectangle to set region according to.public void clear()
public boolean equals(Object object)
object
- Object to check against.
ClassCastException
- if object is not of type Region.public boolean isEmpty()
public void offset(int dx, int dy)
dx
- Offset in x direction.dy
- Offset in y direction.public boolean isIntersecting(Region region)
region
- Region to check against.
public boolean isIntersecting(Rect rectangle)
rectangle
- Rectangle to check against.
public boolean isInside(int x, int y)
x
- X part of point to check.y
- Y part of point to check.
public boolean isInside(Rect rectangle)
rectangle
- Rectangle to check.
public boolean isInsideOf(Rect rectangle)
rectangle
- Rectangle to check if this is inside of.
public Rect getExtent()
public int getNRectangles()
public void collapse()
public void union(Region region)
region
- Region to union this with.public void union(Rect rectangle)
rectangle
- Rectangle to union this with.public static Region union(Region r1, Region r2)
r1
- First region to union.r2
- Second region to union.
public static Region union(Region region, Rect rectangle)
region
- Region to union.rectangle
- Rectangle to intersect with.
public void intersect(Region region)
region
- Region to intersect this with.public void intersect(Rect rectangle)
rectangle
- Rectangle to intersect this with.public static Region intersect(Region r1, Region r2)
r1
- First region to intersect.r2
- Second region to intersect.
public static Region intersect(Region region, Rect rectangle)
region
- Region to intersect.rectangle
- Rectangle to intersect with.
public void subtract(Region region)
region
- Region to subtract from this region.public void subtract(Rect rectangle)
rectangle
- Rectangle to subtract from this region.public static Region subtract(Region r1, Region r2)
r1
- Region to subtract from.r2
- Region to subtract.
public static Region subtract(Region region, Rect rectangle)
region
- Region to subtract from.rectangle
- Ractangle to subtract.
public void xor(Region region)
region
- Region to xor this region with.public void xor(Rect rectangle)
rectangle
- Rectangle to xor this region with.public static Region xor(Region r1, Region r2)
r1
- First region to xor.r2
- Second region to xor.
public static Region xor(Region region, Rect rectangle)
region
- Region to xor.rectangle
- Rectangle to xor with.
|
GeoSoft API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |