cz.cuni.utils.math.vertexSpace.vertex2Dspace
Class Vertex2DSpace

java.lang.Object
  extended by cz.cuni.utils.math.vertexSpace.vertex2Dspace.Vertex2DSpace
All Implemented Interfaces:
Vertex2DSpaceInterface

public class Vertex2DSpace
extends java.lang.Object
implements Vertex2DSpaceInterface

We're counting with a certain precision epsilon, that means ... 2 vertices which are closer then epsilon are counted as 1 ... what if distance of 2 vertices is 1,5 epsilon and there is third vertex in the middle? Basicly this structure takes care of creating new vertices and reporting those errors. Create VertexSpace with a certain precision and use it as a Vertex factory. You tell the instance the x, y of the vertex and then it will a) return you new Vertex b) return you an existing Vertex c) return null == error So ... this VertexSpace consists of VertexSpaceSquares which overlaps each other by epsilon, in those squares we stores actual vertexes (for additional info see VertexSpaceCube) VertexSpace should be used as a factory ... you have in input of some Tuple2D == (x, y) and this will return you the objects you want to play with (note that when you create the instance you have to specify VertexFactoryInterface) You know ... to have errors reported is nice, but if you want to do things fast - use SimpleVertexSpace (doesn't test for collisions, but is 25x faster, using only HashMap) ... but you can't specify the EPSILON This class should be used when you need to transfer from one PRECISION to another. Example - UT in T3D file saves vertexes with 6 digits precision - we want to count with higher precision, so Vertices need to be created with higher precision thus we can't use SimpleVertexSpace because of Vertex.equals using higher precision then UT. ... those kind of problems should be solved like this a) use VertexSpace too obtain new vertices b) put those vertices in SimpleVertexSpace ... loop for all vertices c) after processing all vertices, drop VertexSpace instance and use only SimpleVertexSpace (because it's faster) from now on


Field Summary
static int MAX_PRECISION
          Beware ... maximal MAX_PRECISION should be double precision - 1
static int MIN_PRECISION
          Don't change this one...
private  int number
           
 double precision
          == 10^(-precisionInt)
 int precisionInt
          precision = 10^(-precisionInt)
static int SQUARE_SIZE_MULTI
          How big the squares will be ... squareSize = SQUARE_SIZE_MULTI*precision Can't be less then 3!
static int[] SQUARE_TRANSLATION
           
protected  java.util.HashMap squares
           
 double squareSize
          cubeSize = CUBE_SIZE_MULTI * precision;
 double[] squareTranslation
          Contains X, Y, Z, random numbers - cubes are translated relatively to this, it's because - you usualy have nice coordinates like (0, 0, 1) etc.
 Vertex2DFactoryInterface vertexFactory
           
 
Constructor Summary
Vertex2DSpace(Vertex2DFactoryInterface vf, int iPrecision)
           
 
Method Summary
 void clear()
          Clears information about vertices, which have been created.
static Vertex2D[] convert(Vertex2DSpace vs, Tuple2D[] array)
          For testing the class only.
 Vertex2D get(double[] xy)
           
 Vertex2D get(double x, double y)
          Should return existing or new vertex which has "equal" coordinates.
 Vertex2D get(Tuple2D t)
          May return null == collision with more then one vertex.
 java.util.ArrayList getCubes(double[] xy)
           
 java.util.ArrayList getCubes(double x, double y)
           
protected  Vertex2DSpaceSquare getSquare(double x, double y)
           
 java.util.ArrayList getSquares(Tuple2D t)
          Returns list of cubes into which the Tuple3D belongs.
 java.util.ArrayList checkVertices(double[] xy)
           
 java.util.ArrayList checkVertices(double x, double y)
           
 java.util.ArrayList checkVertices(Tuple2D t)
          Returns list of vertices in which surroundings the tuple lies.
 java.util.ArrayList checkVertices(Tuple2D t, java.util.ArrayList vertexSpaceCubes)
          Returns list of vertices in which surroundings the tuple lies.
static void main(java.lang.String[] args)
          This method is meant for testing the functionality of Vertex3DSpace class.
 void remove(Vertex2D v)
          Vertex must be removed from the space
 void set(Vertex2D v)
          You have to insert this vertex into space, possibly overwriting the existing one.
static void testArrays(Tuple2D[] first, Tuple2D[] same)
          For testing the class only.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_PRECISION

public static final int MAX_PRECISION
Beware ... maximal MAX_PRECISION should be double precision - 1

See Also:
Constant Field Values

MIN_PRECISION

public static final int MIN_PRECISION
Don't change this one...

See Also:
Constant Field Values

SQUARE_SIZE_MULTI

public static final int SQUARE_SIZE_MULTI
How big the squares will be ... squareSize = SQUARE_SIZE_MULTI*precision Can't be less then 3! ... well I think it shouldn't ;)

See Also:
Constant Field Values

squareTranslation

public final double[] squareTranslation
Contains X, Y, Z, random numbers - cubes are translated relatively to this, it's because - you usualy have nice coordinates like (0, 0, 1) etc. See? 0, 0, 1 are numbers on borders of the cubes ... nasty ;)


SQUARE_TRANSLATION

public static final int[] SQUARE_TRANSLATION

vertexFactory

public final Vertex2DFactoryInterface vertexFactory

precision

public final double precision
== 10^(-precisionInt)


precisionInt

public final int precisionInt
precision = 10^(-precisionInt)


squareSize

public final double squareSize
cubeSize = CUBE_SIZE_MULTI * precision;


squares

protected java.util.HashMap squares

number

private int number
Constructor Detail

Vertex2DSpace

public Vertex2DSpace(Vertex2DFactoryInterface vf,
                     int iPrecision)
Method Detail

getSquare

protected Vertex2DSpaceSquare getSquare(double x,
                                        double y)

getSquares

public java.util.ArrayList getSquares(Tuple2D t)
Returns list of cubes into which the Tuple3D belongs. Sort of cruel one ... if you look at code, you have to check for many possibilities regarding where the tuple is (26 possibilities)

Parameters:
t -
Returns:
ArrayList of squares

getCubes

public java.util.ArrayList getCubes(double x,
                                    double y)

getCubes

public java.util.ArrayList getCubes(double[] xy)

checkVertices

public java.util.ArrayList checkVertices(Tuple2D t)
Returns list of vertices in which surroundings the tuple lies.

Parameters:
t -
Returns:
ArrayList

checkVertices

public java.util.ArrayList checkVertices(double x,
                                         double y)

checkVertices

public java.util.ArrayList checkVertices(double[] xy)

checkVertices

public java.util.ArrayList checkVertices(Tuple2D t,
                                         java.util.ArrayList vertexSpaceCubes)
Returns list of vertices in which surroundings the tuple lies. Note that it isn't "cool" ... same vertex may be returned from different cubes (because they overlap) so we have to be sure that result will be unique. vertexSpaceCubes - which cubes should be checked

Parameters:
t -
vertexSpaceCubes -
Returns:
ArrayList

get

public Vertex2D get(Tuple2D t)
May return null == collision with more then one vertex.

Specified by:
get in interface Vertex2DSpaceInterface
Parameters:
t -
Returns:
Vertex2D which belongs to 't'

get

public Vertex2D get(double x,
                    double y)
Description copied from interface: Vertex2DSpaceInterface
Should return existing or new vertex which has "equal" coordinates.

Specified by:
get in interface Vertex2DSpaceInterface
Parameters:
x - coordinate
y - coordinate
Returns:
Vertex2D

get

public Vertex2D get(double[] xy)

set

public void set(Vertex2D v)
Description copied from interface: Vertex2DSpaceInterface
You have to insert this vertex into space, possibly overwriting the existing one.

Specified by:
set in interface Vertex2DSpaceInterface

remove

public void remove(Vertex2D v)
Description copied from interface: Vertex2DSpaceInterface
Vertex must be removed from the space

Specified by:
remove in interface Vertex2DSpaceInterface

clear

public void clear()
Description copied from interface: Vertex2DSpaceInterface
Clears information about vertices, which have been created.

Specified by:
clear in interface Vertex2DSpaceInterface

convert

public static Vertex2D[] convert(Vertex2DSpace vs,
                                 Tuple2D[] array)
For testing the class only.


testArrays

public static void testArrays(Tuple2D[] first,
                              Tuple2D[] same)
For testing the class only.


main

public static void main(java.lang.String[] args)
This method is meant for testing the functionality of Vertex3DSpace class.