: Download: FAQ: Licensing: Support: Contact ME
LwVCL Home
Introduction
Overview
Screen Shots
On-line Demos
Requirements
Further Plans
Docs
Tutorial
How-to (PDF)
API
FAQ
Download
Latest version

Home > J2SE > API

Overview  Package   Class  Tree  Deprecated  Index  Help 

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.


Constructor Summary
MathBox()
           
 
Method Summary
static boolean checkBit(int bits, int mask)
          Tests if the specified bit mask has the given bit set.
static int getBits(int bits, int mask, boolean b)
          Sets the bits value for the specified bit mask and returns the new bit mask.
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 void intersection(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2, java.awt.Rectangle r)
          Gets the intersection rectangle for the two specified rectangular areas.
static java.awt.Dimension max(java.awt.Dimension a, java.awt.Dimension b)
          Returns the dimension that has width, height fields calculated as maximal values for the specified dimension objects.
static void unite(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2, java.awt.Rectangle r)
          Unites the two specified rectangular and returns the result.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MathBox

public MathBox()
Method Detail

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 maximal 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:
a row and column. The result is represented with java.awt.Point class where the x field corresponds to the row and the y field correspond to the 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(int bits,
                               int mask)
Tests if the specified bit mask has the given bit set.
Parameters:
bits - the specified bit mask.
mask - the specified bit to be test.
Returns:
true if the bit "ON" for the given bit mask; otherwise false.

getBits

public static int getBits(int bits,
                          int mask,
                          boolean b)
Sets the bits value for the specified bit mask and returns the new bit mask.
Parameters:
bits - the specified bit mask.
mask - the specified bits to be set.
b - use true to set the specified bits to 1; otherwise use false.
Returns:
a new bit mask.

intersection

public static void intersection(int x1,
                                int y1,
                                int w1,
                                int h1,
                                int x2,
                                int y2,
                                int w2,
                                int h2,
                                java.awt.Rectangle r)
Gets the intersection rectangle for the two specified rectangular areas.

unite

public static void unite(int x1,
                         int y1,
                         int w1,
                         int h1,
                         int x2,
                         int y2,
                         int w2,
                         int h2,
                         java.awt.Rectangle r)
Unites the two specified rectangular and returns the result.
Parameters:
x1 - the top-left x coordinate of the first rectangular area.
y1 - the top-left y coordinate of the first rectangular area.
w1 - the width of the first rectangular area.
h1 - the height of the first rectangular area.
x2 - the top-left x coordinate of the second rectangular area.
y2 - the top-left y coordinate of the second rectangular area.
w2 - the width of the second rectangular area.
h2 - the height of the second rectangular area.
r - the result.


: up