crystalspace.jbind.impl.csgeom.csrect
Class csRect

java.lang.Object
  extended bycrystalspace.jbind.impl.csNativeObject
      extended bycrystalspace.jbind.impl.csgeom.csrect.csRect
All Implemented Interfaces:
iPointer

public class csRect
extends csNativeObject

Rectangle class: simple class for manipulating 2D rectangles. This class is somewhat similar to Box, but uses integer coordinates.

Author:
Java wrapper - Quentin Anciaux, c++ version - http://crystal.sourceforge.net/docs/online/pubapi/classcsRect.php

Field Summary
 
Fields inherited from class crystalspace.jbind.impl.csNativeObject
ImplFactory, nPointer
 
Constructor Summary
csRect()
          Create a empty rectangle.
csRect(csRect copy)
          Copy constructor.
csRect(int ixmin, int iymin, int ixmax, int iymax)
          Create a new rectangle.
csRect(iPointer nPointer)
          Create a java csRect object which points to the native csRect nPointer.
 
Method Summary
 void addAdjanced(csRect rect)
          Add an adjanced rectangle if resulting rectangle will have larger area.
 int area()
          Return area of this rectangle.
 boolean clipLine(int x1, int y1, int x2, int y2)
          Clip a line to make it fit to this rectangle.
 boolean clipLineGeneral(int x1, int y1, int x2, int y2)
          This function is the same as ClipLine() except that it doesn't check for two trivial cases (horizontal and vertical lines).
 boolean clipLineSafe(int x1, int y1, int x2, int y2)
          Clip a line to make it fit to this rectangle.
 boolean contains(int x, int y)
          Return true if a point lies within rectangle bounds.
 boolean containsRel(int x, int y)
          Return true if a relative point lies within rectangle bounds.
 boolean equal(int ixmin, int iymin, int ixmax, int iymax)
          Return true if rectangle is the same.
 boolean equals(csRect other)
          Same but compare with another csRect.
 boolean equals(java.lang.Object rect)
          Test equality of two rectangles.
 void exclude(csRect other)
          Same but works on a csRect argument.
 void exclude(int ixmin, int iymin, int ixmax, int iymax)
          Subtract rectangle: find the minimal rectangle which embeds all parts of this rectangle which are not covered by given rectangle.
 void extend(int x, int y)
          Extend rectangle so that it will include given point.
 int height()
          Return the height of rectangle.
 void inset(int n)
          Contracts the whole rect by n units.
 void intersect(csRect other)
          Intersect with another rectangle.
 void intersect(int ixmin, int iymin, int ixmax, int iymax)
          Intersect with another rectangle.
 boolean intersects(csRect target)
          Return true if rectangle intersects with target.
 boolean isEmpty()
          Return true if rectangle is empty.
protected  boolean isNativePointerValidSafe(long nPointer)
           
 void join(csRect rect)
          Joins two rects by their minimum and maximum bounds.
 void makeEmpty()
          Make rectangle empty.
 void move(int dX, int dY)
          Move rectangle by deltaX, deltaY.
protected  void nDelete(long pointer)
           
 boolean nEquals(csRect rect)
          Test inequality of two rectangles.
 void normalize()
          Normalize a rectangle such that xmin <= xmax and ymin <= ymax.
 void outset(int n)
          Expands the whole rect by n units.
 void set(csRect target)
          Copy rectangle.
 void set(int ixmin, int iymin, int ixmax, int iymax)
          Set rectangle to given ixmin,iymin,ixmax,iymax position.
 void setPos(int x, int y)
          Set rectangle xmin,ymin position.
 void setSize(int w, int h)
          Set rectangle size.
 void setXmax(int xmax)
          Rectangle bounds.
 void setXmin(int xmin)
          Rectangle bounds.
 void setYmax(int ymax)
          Rectangle bounds.
 void setYmin(int ymin)
          Rectangle bounds.
 void subtract(csRect rect)
          Alternative subtraction: find maximal area of this rectangle that is not covered by argument.
 void union(csRect other)
          Add a rectangle: find minimal rectangle that embeds both given rectangles.
 void union(int ixmin, int iymin, int ixmax, int iymax)
          Add a rectangle: find minimal rectangle that embeds both given rectangles.
 int width()
          Return the width of rectangle.
 int xmax()
          Rectangle bounds.
 int xmin()
          Rectangle bounds.
 int ymax()
          Rectangle bounds.
 int ymin()
          Rectangle bounds.
 
Methods inherited from class crystalspace.jbind.impl.csNativeObject
changePointer, finalize, getPointer, getPointer, getPointerArray, hashCode, isMemoryOwner, isNativePointerValid, newNativeObject, setMemoryOwner, toString
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

csRect

public csRect(iPointer nPointer)
Create a java csRect object which points to the native csRect nPointer.

Parameters:
nPointer -

csRect

public csRect()
Create a empty rectangle.


csRect

public csRect(int ixmin,
              int iymin,
              int ixmax,
              int iymax)
Create a new rectangle.

Parameters:
ixmin -
iymin -
ixmax -
iymax -

csRect

public csRect(csRect copy)
Copy constructor.

Parameters:
copy -
Method Detail

nDelete

protected void nDelete(long pointer)
Specified by:
nDelete in class csNativeObject
See Also:
csNativeObject.nDelete(long)

isNativePointerValidSafe

protected boolean isNativePointerValidSafe(long nPointer)
Specified by:
isNativePointerValidSafe in class csNativeObject
See Also:
crystalspace.jbind.impl.csNativeObject#isNativePointerValidSafe()

intersect

public final void intersect(int ixmin,
                            int iymin,
                            int ixmax,
                            int iymax)
Intersect with another rectangle.

Parameters:
ixmin -
iymin -
ixmax -
iymax -

intersect

public final void intersect(csRect other)
Intersect with another rectangle.

Parameters:
other -

intersects

public final boolean intersects(csRect target)
Return true if rectangle intersects with target.

Parameters:
target -
Returns:

union

public final void union(int ixmin,
                        int iymin,
                        int ixmax,
                        int iymax)
Add a rectangle: find minimal rectangle that embeds both given rectangles.

Parameters:
ixmin -
iymin -
ixmax -
iymax -

union

public final void union(csRect other)
Add a rectangle: find minimal rectangle that embeds both given rectangles.

Parameters:
other -

exclude

public final void exclude(int ixmin,
                          int iymin,
                          int ixmax,
                          int iymax)
Subtract rectangle: find the minimal rectangle which embeds all parts of this rectangle which are not covered by given rectangle.

Parameters:
ixmin -
iymin -
ixmax -
iymax -

exclude

public final void exclude(csRect other)
Same but works on a csRect argument.

Parameters:
other -

subtract

public final void subtract(csRect rect)
Alternative subtraction: find maximal area of this rectangle that is not covered by argument.

Parameters:
rect -

isEmpty

public final boolean isEmpty()
Return true if rectangle is empty.

Returns:

makeEmpty

public final void makeEmpty()
Make rectangle empty.


set

public final void set(int ixmin,
                      int iymin,
                      int ixmax,
                      int iymax)
Set rectangle to given ixmin,iymin,ixmax,iymax position.

Parameters:
ixmin -
iymin -
ixmax -
iymax -

set

public final void set(csRect target)
Copy rectangle.

Parameters:
target -

setPos

public final void setPos(int x,
                         int y)
Set rectangle xmin,ymin position.

Parameters:
x -
y -

setSize

public final void setSize(int w,
                          int h)
Set rectangle size.

Parameters:
w -
h -

move

public final void move(int dX,
                       int dY)
Move rectangle by deltaX, deltaY.

Parameters:
dX -
dY -

width

public final int width()
Return the width of rectangle.

Returns:

height

public final int height()
Return the height of rectangle.

Returns:

contains

public final boolean contains(int x,
                              int y)
Return true if a point lies within rectangle bounds.

Parameters:
x -
y -
Returns:

containsRel

public final boolean containsRel(int x,
                                 int y)
Return true if a relative point lies within rectangle bounds.

Parameters:
x -
y -
Returns:

equal

public final boolean equal(int ixmin,
                           int iymin,
                           int ixmax,
                           int iymax)
Return true if rectangle is the same.

Parameters:
ixmin -
iymin -
ixmax -
iymax -
Returns:

equals

public final boolean equals(csRect other)
Same but compare with another csRect.

Parameters:
other -
Returns:

normalize

public final void normalize()
Normalize a rectangle such that xmin <= xmax and ymin <= ymax.


area

public final int area()
Return area of this rectangle.

Returns:

addAdjanced

public final void addAdjanced(csRect rect)
Add an adjanced rectangle if resulting rectangle will have larger area.

Parameters:
rect -

equals

public final boolean equals(java.lang.Object rect)
Test equality of two rectangles.

Overrides:
equals in class csNativeObject
Parameters:
rect -
Returns:
See Also:
Object.equals(java.lang.Object)

nEquals

public final boolean nEquals(csRect rect)
Test inequality of two rectangles.

Parameters:
rect -
Returns:

extend

public final void extend(int x,
                         int y)
Extend rectangle so that it will include given point.

Parameters:
x -
y -

join

public final void join(csRect rect)
Joins two rects by their minimum and maximum bounds.

Parameters:
rect -

outset

public final void outset(int n)
Expands the whole rect by n units.

Parameters:
n -

inset

public final void inset(int n)
Contracts the whole rect by n units.

Parameters:
n -

clipLineGeneral

public final boolean clipLineGeneral(int x1,
                                     int y1,
                                     int x2,
                                     int y2)
This function is the same as ClipLine() except that it doesn't check for two trivial cases (horizontal and vertical lines).

Parameters:
x1 -
y1 -
x2 -
y2 -
Returns:

clipLine

public final boolean clipLine(int x1,
                              int y1,
                              int x2,
                              int y2)
Clip a line to make it fit to this rectangle.

Parameters:
x1 -
y1 -
x2 -
y2 -
Returns:

clipLineSafe

public final boolean clipLineSafe(int x1,
                                  int y1,
                                  int x2,
                                  int y2)
Clip a line to make it fit to this rectangle.

Parameters:
x1 -
y1 -
x2 -
y2 -
Returns:

xmin

public final int xmin()
Rectangle bounds.

Returns:

setXmin

public final void setXmin(int xmin)
Rectangle bounds.

Parameters:
xmin -

ymin

public final int ymin()
Rectangle bounds.

Returns:

setYmin

public final void setYmin(int ymin)
Rectangle bounds.

Parameters:
ymin -

xmax

public final int xmax()
Rectangle bounds.

Returns:

setXmax

public final void setXmax(int xmax)
Rectangle bounds.

Parameters:
xmax -

ymax

public final int ymax()
Rectangle bounds.

Returns:

setYmax

public final void setYmax(int ymax)
Rectangle bounds.

Parameters:
ymax -