Package org.jacop.constraints.geost
Class DBox
java.lang.Object
org.jacop.constraints.geost.DBox
- Version:
- 4.9
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SimpleArrayList<SimpleArrayList<DBox>>
static store of available boxes, accessible by dimension.final int[]
It specifies for each dimension the length of dbox in that dimension.final int[]
It specifies point in n-dimensional space where the dbox originates from. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
area()
It computes the area in 2D case or volume in 3D case.static DBox
boundingBox
(Collection<DBox> boxes) computes the bounding box of the given collection of boxesIt checks whether the DBox is consistent.boolean
containsPoint
(int[] pointCoordinates) It checks if this DBox contains the point as specified by an array of coordinates.final DBox
It copies this DBox into given DBox.static final void
dispatchBox
(DBox unusedBox) It allows the system to reuse the given box by placing it into the pool of allocated boxes.boolean
static final DBox
getAllocatedInstance
(int dimension) It returns an instance of DBox of the corresponding dimension, using a previously allocated one if possibleint
hashCode()
intersectWith
(int[] offset, DBox other, int[] otherOffset) It intersects this DBox with a view of the given DBox that was shifted according to the given offset.intersectWith
(DBox other) It intersects this DBox with the given DBox.intersectWith
(DBox other, int[] otherOffset) It intersects this DBox with the given DBox, but the other DBox is shifted by the specified offset.static final DBox
newBox
(int dimension) It returns an usable box, reusing a box from the pool if possible.static String
It provides a string representation of the DBoxes which are present in the DBox pool.subtract
(DBox hole, Collection<DBox> difference) computes the difference between this box and the given box.subtractAll
(Collection<DBox> others, Collection<DBox> result) It computes the result of a subtraction from this box of all the boxes given.static Collection<DBox>
subtractAll
(Collection<DBox> source, Collection<DBox> holes, Collection<DBox> result) It computes the result of a subtraction from the given collection of boxes of all the boxes given in the subtracting collection.static final void
supportDimension
(int dimension) It makes sure that there is a slot of the given dimension in the slot.toString()
-
Field Details
-
freeBoxes
static store of available boxes, accessible by dimension. This makes it possible to reuse previously used boxes that are not used anymore. The user should use dispatchBox() to get rid of a box that is not needed anymore, and newBox(dimension) to get a new one. -
origin
public final int[] originIt specifies point in n-dimensional space where the dbox originates from. -
length
public final int[] lengthIt specifies for each dimension the length of dbox in that dimension.
-
-
Constructor Details
-
DBox
public DBox(int[] origin, int[] length) constructs a new Box. The parameter arrays are not copied.- Parameters:
origin
- it specifies the origin of the DBox in the n-dimensional space.length
- it specifies the length of the Dbox in the n-dimensional space.
-
DBox
public DBox(int dimension) constructs a new Box. The parameter arrays are not copied.- Parameters:
dimension
- it specifies the dimension of the createed DBox.
-
-
Method Details
-
supportDimension
public static final void supportDimension(int dimension) It makes sure that there is a slot of the given dimension in the slot.It has to be called at least once before using newBox() and dispatchBox().
- Parameters:
dimension
- the number of dimensions
-
checkInvariants
It checks whether the DBox is consistent.- Returns:
- It returns the string description of the problem, or null if no problem with data structure consistency encountered.
-
dispatchBox
It allows the system to reuse the given box by placing it into the pool of allocated boxes. After calling this function, the caller must not keep any reference to the box, as the box may be arbitrary changed by any future owner.- Parameters:
unusedBox
- the not used DBox which is being recycled.
-
newBox
It returns an usable box, reusing a box from the pool if possible. A DBox that is not used anymore should be put back into the pool using dispatchBox.- Parameters:
dimension
- it specifies number of dimensions of a requested box- Returns:
- It returns DBox with the specified dimension. Later on, when box is no longer needed it should be dispatched back.
-
getAllocatedInstance
It returns an instance of DBox of the corresponding dimension, using a previously allocated one if possible- Parameters:
dimension
- the number of dimensions- Returns:
- it returns a preallocated DBox of a given dimensions.
-
poolStatus
It provides a string representation of the DBoxes which are present in the DBox pool.- Returns:
- string representation of the pool of DBoxes.
-
containsPoint
public boolean containsPoint(int[] pointCoordinates) It checks if this DBox contains the point as specified by an array of coordinates.- Parameters:
pointCoordinates
- it specifies the point coordinates.- Returns:
- true if the point is inside DBox.
-
intersectWith
It intersects this DBox with the given DBox.For efficiency reasons, the DBox returned is the static instance; if it needs to be stored, a copy has to be made using clone().
- Parameters:
other
- the DBox to intersect this one with- Returns:
- null if the intersection is empty, or a reference to a static DBox corresponding to the intersection. The result must be cloned if its scope is not local.
-
intersectWith
It intersects this DBox with the given DBox, but the other DBox is shifted by the specified offset.For efficiency reasons, the DBox returned is the static instance; if it needs to be stored, a copy has to be made using clone().
- Parameters:
other
- DBox with which the intersection is computed.otherOffset
- the offset- Returns:
- null if the intersection is empty, or a reference to a static DBox corresponding to the intersection. The result must be cloned if its scope is not local.
-
intersectWith
It intersects this DBox with a view of the given DBox that was shifted according to the given offset. If the intersection is empty, returns null.For efficiency reasons, the DBox returned is the static instance; if it needs to be stored, a copy has to be made using clone().
- Parameters:
offset
- the offset to apply to this box before intersectingother
- the DBox to intersect this one withotherOffset
- the offset to apply to the other DBox before intersecting- Returns:
- null if the intersection is empty, or a reference to a static DBox corresponding to the intersection. Clone if its scope is not local.
-
subtract
computes the difference between this box and the given box. The difference is returned under the form of a collection of boxes.NOTE: the collection of DBoxes returned is not minimal (in some cases, some boxes can be merged)
if needed, implement a version that can take a lexical order as argument, to allow brute force search or learning of the best decomposition
- Parameters:
hole
- the box to subtract this box withdifference
- the collection of boxes corresponding to the remaining area- Returns:
- the computed difference, which is the difference paramter after the call (this is for ease of use only)
-
boundingBox
computes the bounding box of the given collection of boxes- Parameters:
boxes
- collection of boxes- Returns:
- a temporary DBox that represents the bounding box of the given boxes. clone it if you need to reuse it.
-
subtractAll
public static Collection<DBox> subtractAll(Collection<DBox> source, Collection<DBox> holes, Collection<DBox> result) It computes the result of a subtraction from the given collection of boxes of all the boxes given in the subtracting collection. The collection used to store the result is given to avoid allocating a new set of boxes each time the function is called. However, for ease of use, it is also returned (after the call, the result argument is equal to the returned value).- Parameters:
source
- the collection of boxes to subtract fromholes
- the boxes to subtract from the source boxesresult
- the collection to store the resulting boxes into- Returns:
- the result argument, for ease of use
-
subtractAll
It computes the result of a subtraction from this box of all the boxes given. The collection used to store the result is given to avoid allocating a new set of boxes each time the function is called. However, for ease of use, it is also returned (after the call, the result argument is equal to the returned value)- Parameters:
others
- the boxes to subtract from this boxresult
- the collection to store the resulting boxes into- Returns:
- the result argument, for ease of use
-
area
public int area()It computes the area in 2D case or volume in 3D case.- Returns:
- the area/volume of the DBox.
-
copyInto
It copies this DBox into given DBox.- Parameters:
box
- the DBox to copy this DBox into- Returns:
- for convenience reasons, returns the copied DBox (same as the argument)
-
toString
-
hashCode
public int hashCode() -
equals
-