org.zaval.util
Class MathBox
java.lang.Object
|
+--org.zaval.util.MathBox
- public class MathBox
- extends java.lang.Object
This class provides set of useful math methods.
Method Summary |
static boolean |
checkBit(short bits,
short mask)
Checks if the specified bits set satisfies to the given mask. |
static short |
getBits(short bits,
short mask,
boolean b)
Sets specified by the mask bits in the given bits set to 1 or 0
value and returns the new bits set. |
static java.awt.Point |
index2point(int offset,
int cols)
Computes and returns the row and column for the specified offset and the given
number of columns. |
static int |
indexByPoint(int row,
int col,
int cols)
Converts the specified row and column to the offset. |
static java.awt.Rectangle |
intersection(int x1,
int y1,
int w1,
int h1,
int x2,
int y2,
int w2,
int h2)
Gets the intersection rectangle for the two specified rectnagles. |
static java.awt.Dimension |
max(java.awt.Dimension a,
java.awt.Dimension b)
Returns the dimension that has width , height ,
fields calculated as a maximal values of appropriate fields values for the
specified dimension objects. |
static java.awt.Insets |
max(java.awt.Insets a,
java.awt.Insets b)
Returns the insets that has top , left ,
bottom , right fields calculated as a maximal values
of appropriate fields values for the specified insets objects. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MathBox
public MathBox()
max
public static java.awt.Insets max(java.awt.Insets a,
java.awt.Insets b)
- Returns the insets that has
top
, left
,
bottom
, right
fields calculated as a maximal values
of appropriate fields values for the specified insets objects.
- Parameters:
a
- the specified insets object.b
- the specified insets object.- Returns:
- a maximal insets object.
max
public static java.awt.Dimension max(java.awt.Dimension a,
java.awt.Dimension b)
- Returns the dimension that has
width
, height
,
fields calculated as a maximal values of appropriate fields values for the
specified dimension objects.
- Parameters:
a
- the specified dimension object.b
- the specified dimension object.- Returns:
- a maximal dimension object.
index2point
public static java.awt.Point index2point(int offset,
int cols)
- Computes and returns the row and column for the specified offset and the given
number of columns. The sample below shows the offset
meaning:
row=0, column=0, offset=0 |
row=0, column=1, offset=1 |
row=0, column=2, offset=2 |
row=1, column=0, offset=3 |
row=1, column=1, offset=4 |
row=1, column=2, offset=5 |
row=2, column=0, offset=6 |
row=2, column=1, offset=7 |
row=2, column=2, offset=8 |
- Parameters:
offset
- the specified offset.cols
- the number of columns.- Returns:
- an row and column. The result is represented with java.awt.Point class
where the
x
field correspond to row and the y
field
correspond to column.
indexByPoint
public static int indexByPoint(int row,
int col,
int cols)
- Converts the specified row and column to the offset. The following formula is used to
calculate the offset: (row*columns) + column
- Parameters:
row
- the specified row.col
- the specified column.cols
- the number of columns.- Returns:
- an offset.
checkBit
public static boolean checkBit(short bits,
short mask)
- Checks if the specified bits set satisfies to the given mask.
- Parameters:
bits
- the specified bits set.mask
- the specified mask.- Returns:
true
if the specified bits set satisfies to the given mask;
otherwise false
.
getBits
public static short getBits(short bits,
short mask,
boolean b)
- Sets specified by the mask bits in the given bits set to
1
or 0
value and returns the new bits set.
- Parameters:
bits
- the specified bits set.mask
- the specified mask.b
- use true
to set the appropriate bits in the bits set to
1
; otherwise use false
.- Returns:
- a new bits set.
intersection
public static java.awt.Rectangle intersection(int x1,
int y1,
int w1,
int h1,
int x2,
int y2,
int w2,
int h2)
- Gets the intersection rectangle for the two specified rectnagles.
- Returns:
- an intersection rectangle.
Copyright © Zaval Creative Engineering Group, 2000-2005.
http://www.zaval.org