API reference - Class DBox

Notation used in Ruby API documentation

Description: A box class

This object represents a box (a rectangular shape).

The definition of the attributes is: p1 is the lower left point, p2 the upper right one. If a box is constructed from two points (or four coordinates), the coordinates are sorted accordingly.

A box can be empty. An empty box represents no area (not even a point). Empty boxes behave neutral with respect to most operations. Empty boxes return true on empty?.

A box can be a point or a single line. In this case, the area is zero but the box still can overlap other boxes for example and it is not empty.

See The Database API for more details about the database objects.

Public constructors

new DBox ptrnewDefault constructor: creates an empty (invalid) box
new DBox ptrnew(double left,
double bottom,
double right,
double top)
Constructor with four coordinates
new DBox ptrnew(const DPoint lower_left,
const DPoint upper_right)
Constructor with two points

Public methods

[const]bool!=(const DBox box)Inequality
[const]DBox&(const DBox box)Intersection of boxes
[const]DBox*(const DBox box)Convolve boxes
[const]DBox*(double scale_factor)Scale box
[const]DBox+(const DPoint point)Join box with a point
[const]DBox+(const DBox box)Joining of boxes
[const]bool<(const DBox box)Less operator
[const]bool==(const DBox box)Equality
void_createEnsures the C++ object is created
void_destroyExplicitly destroys the object
[const]bool_destroyed?Returns a value indicating whether the object was already destroyed
[const]bool_is_const_object?Returns a value indicating whether the reference is a const reference
void_manageMarks the object as managed by the script side.
void_unmanageMarks the object as no longer owned by the script side.
[const]doubleareaCompute the box area
voidassign(const DBox other)Assigns another object to self
[const]doublebottomThe bottom coordinate of the box
voidbottom=(double c)Set the bottom coordinate of the box
[const]DPointcenterThe center of the box
[const]boolcontains?(double x,
double y)
Returns true if the box contains the given point
[const]boolcontains?(const DPoint point)Returns true if the box contains the given point
[const]new DBox ptrdupCreates a copy of self
[const]boolempty?Empty predicate
DBoxenlarge(double dx,
double dy)
Enlarges the box by a certain amount.
DBoxenlarge(const DPoint enlargement)Enlarges the box by a certain amount.
[const]DBoxenlarged(double dx,
double dy)
Enlarges the box by a certain amount.
[const]DBoxenlarged(const DPoint enlargement)Enlarges the box by a certain amount.
[const]doubleheightThe height of the box
[const]boolinside?(const DBox box)Test if this box is inside the argument box
[const]boolis_point?Return true, if the box is a single point
[const]doubleleftThe left coordinate of the box
voidleft=(double c)Set the left coordinate of the box
DBoxmove(double dx,
double dy)
Moves the box by a certain distance
DBoxmove(const DPoint distance)Moves the box by a certain distance
[const]DBoxmoved(double dx,
double dy)
Moves the box by a certain distance
[const]DBoxmoved(const DPoint distance)Returns the box moved by a certain distance
[const]booloverlaps?(const DBox box)Test if this box overlaps the argument box
[const]DPointp1The lower left point of the box
voidp1=(const DPoint p)Set the lower left point of the box
[const]DPointp2The upper right point of the box
voidp2=(const DPoint p)Set the upper right point of the box
[const]doubleperimeterReturns the perimeter of the box
[const]doublerightThe right coordinate of the box
voidright=(double c)Set the right coordinate of the box
[const]stringto_sConvert to a string
[const]doubletopThe top coordinate of the box
voidtop=(double c)Set the top coordinate of the box
[const]booltouches?(const DBox box)Test if this box touches the argument box
[const]DBoxtransformed(const DTrans t)Transform the box with the given simple transformation
[const]DBoxtransformed(const DCplxTrans t)Transform the box with the given complex transformation
[const]doublewidthThe width of the box

Public static methods and constants

DBoxfrom_ibox(const Box int_box)Construct a floating-point coordinate box from an integer coordinate box
new DBox ptrfrom_s(string s)Creates an object from a string

Deprecated methods (protected, public, static, non-static and constructors)

voidcreateUse of this method is deprecated. Use _create instead
voiddestroyUse of this method is deprecated. Use _destroy instead
[const]booldestroyed?Use of this method is deprecated. Use _destroyed? instead
[const]boolis_const_object?Use of this method is deprecated. Use _is_const_object? instead
[static]new DBox ptrnew_lbrt(double left,
double bottom,
double right,
double top)
Use of this method is deprecated. Use new instead
[static]new DBox ptrnew_pp(const DPoint lower_left,
const DPoint upper_right)
Use of this method is deprecated. Use new instead
[const]DBoxtransformed_cplx(const DCplxTrans t)Use of this method is deprecated. Use transformed instead

Detailed description

[const] bool !=(const DBox box)

Description: Inequality

Return true, if this box and the given box are not equal

[const] DBox &(const DBox box)

Description: Intersection of boxes

box:The box to take the intersection with
Returns:The intersection box

The intersection of two boxes is the largest box common to both boxes. The intersection may be empty if both boxes to not touch. If the boxes do not overlap but touch the result may be a single line or point with an area of zero. Overwrites this box with the result.

[const] DBox *(const DBox box)

Description: Convolve boxes

box:The box to convolve with this box.
Returns:The convolved box

The * operator convolves the firstbox with the one given as the second argument. The box resulting from "convolution" is the outer boundary of the union set formed by placing the second box at every point of the first. In other words, the returned box of (p1,p2)*(q1,q2) is (p1+q1,p2+q2).

[const] DBox *(double scale_factor)

Description: Scale box

scale_factor:The scaling factor
Returns:The scaled box

The * operator scales the box with the given factor and returns the result.

This method has been introduced in version 0.22.

[const] DBox +(const DPoint point)

Description: Join box with a point

point:The point to join with this box.
Returns:The box joined with the point

The + operator joins a point with the box. The resulting box will enclose both the original box and the point.

[const] DBox +(const DBox box)

Description: Joining of boxes

box:The box to join with this box.
Returns:The joined box

The + operator joins the first box with the one given as the second argument. Joining constructs a box that encloses both boxes given. Empty boxes are neutral: they do not change another box when joining. Overwrites this box with the result.

[const] bool <(const DBox box)

Description: Less operator

Return true, if this box is 'less' with respect to first and second point (in this order)

[const] bool ==(const DBox box)

Description: Equality

Return true, if this box and the given box are equal

void _create

Description: Ensures the C++ object is created

Use this method to ensure the C++ object is created, for example to ensure that resources are allocated. Usually C++ objects are created on demand and not necessarily when the script object is created.

void _destroy

Description: Explicitly destroys the object

Explicitly destroys the object on C++ side if it was owned by the script interpreter. Subsequent access to this object will throw an exception. If the object is not owned by the script, this method will do nothing.

[const] bool _destroyed?

Description: Returns a value indicating whether the object was already destroyed

This method returns true, if the object was destroyed, either explicitly or by the C++ side. The latter may happen, if the object is owned by a C++ object which got destroyed itself.

[const] bool _is_const_object?

Description: Returns a value indicating whether the reference is a const reference

This method returns true, if self is a const reference. In that case, only const methods may be called on self.

void _manage

Description: Marks the object as managed by the script side.

After calling this method on an object, the script side will be responsible for the management of the object. This method may be called if an object is returned from a C++ function and the object is known not to be owned by any C++ instance. If necessary, the script side may delete the object if the script's reference is no longer required.

Usually it's not required to call this method. It has been introduced in version 0.24.

void _unmanage

Description: Marks the object as no longer owned by the script side.

Calling this method will make this object no longer owned by the script's memory management. Instead, the object must be managed in some other way. Usually this method may be called if it is known that some C++ object holds and manages this object. Technically speaking, this method will turn the script's reference into a weak reference. After the script engine decides to delete the reference, the object itself will still exist. If the object is not managed otherwise, memory leaks will occur.

Usually it's not required to call this method. It has been introduced in version 0.24.

[const] double area

Description: Compute the box area

Returns the box area or 0 if the box is empty

void assign(const DBox other)

Description: Assigns another object to self

[const] double bottom

Description: The bottom coordinate of the box

Python specific notes:

The object exposes a readable attribute 'bottom'. This is the getter.

void bottom=(double c)

Description: Set the bottom coordinate of the box

Python specific notes:

The object exposes a writable attribute 'bottom'. This is the setter.

[const] DPoint center

Description: The center of the box

[const] bool contains?(double x,double y)

Description: Returns true if the box contains the given point

Returns:true if the point is inside the box.

Tests whether a point (x, y) is inside the box. It also returns true if the point is exactly on the box contour.

[const] bool contains?(const DPoint point)

Description: Returns true if the box contains the given point

p:The point to test against.
Returns:true if the point is inside the box.

Tests whether a point is inside the box. It also returns true if the point is exactly on the box contour.

void create

Description: Ensures the C++ object is created

Use of this method is deprecated. Use _create instead

void destroy

Description: Explicitly destroys the object

Use of this method is deprecated. Use _destroy instead

[const] bool destroyed?

Description: Returns a value indicating whether the object was already destroyed

Use of this method is deprecated. Use _destroyed? instead

[const] new DBox ptr dup

Description: Creates a copy of self

[const] bool empty?

Description: Empty predicate

An empty box may be created with the default constructor for example. Such a box is neutral when combining it with other boxes and renders empty boxes if used in box intersections and false in geometrical relationship tests.

DBox enlarge(double dx,double dy)

Description: Enlarges the box by a certain amount.

Returns:A reference to this box.

This is a convenience method which takes two values instead of a Point object. This method has been introduced in version 0.23.

DBox enlarge(const DPoint enlargement)

Description: Enlarges the box by a certain amount.

enlargement:The grow or shrink amount in x and y direction
Returns:A reference to this box.

Enlarges the box by x and y value specified in the vector passed. Positive values with grow the box, negative ones will shrink the box. The result may be an empty box if the box disappears. The amount specifies the grow or shrink per edge. The width and height will change by twice the amount. Does not check for coordinate overflows.

[const] DBox enlarged(double dx,double dy)

Description: Enlarges the box by a certain amount.

Returns:The enlarged box.

This is a convenience method which takes two values instead of a Point object. This method has been introduced in version 0.23.

[const] DBox enlarged(const DPoint enlargement)

Description: Enlarges the box by a certain amount.

enlargement:The grow or shrink amount in x and y direction
Returns:The enlarged box.

Enlarges the box by x and y value specified in the vector passed. Positive values with grow the box, negative ones will shrink the box. The result may be an empty box if the box disappears. The amount specifies the grow or shrink per edge. The width and height will change by twice the amount. Does not modify this box. Does not check for coordinate overflows.

[static] DBox from_ibox(const Box int_box)

Description: Construct a floating-point coordinate box from an integer coordinate box

Create a floating-point coordinate box from an integer coordinate box

[static] new DBox ptr from_s(string s)

Description: Creates an object from a string

Creates the object from a string representation (as returned by to_s)

This method has been added in version 0.23.

[const] double height

Description: The height of the box

[const] bool inside?(const DBox box)

Description: Test if this box is inside the argument box

Returns true, if this box is inside the given box, i.e. the box intersection renders this box

[const] bool is_const_object?

Description: Returns a value indicating whether the reference is a const reference

Use of this method is deprecated. Use _is_const_object? instead

[const] bool is_point?

Description: Return true, if the box is a single point

[const] double left

Description: The left coordinate of the box

Python specific notes:

The object exposes a readable attribute 'left'. This is the getter.

void left=(double c)

Description: Set the left coordinate of the box

Python specific notes:

The object exposes a writable attribute 'left'. This is the setter.

DBox move(double dx,double dy)

Description: Moves the box by a certain distance

Returns:A reference to this box.

This is a convenience method which takes two values instead of a Point object. This method has been introduced in version 0.23.

DBox move(const DPoint distance)

Description: Moves the box by a certain distance

distance:The offset to move the box.
Returns:A reference to this box.

Moves the box by a given offset and returns the moved box. Does not check for coordinate overflows.

[const] DBox moved(double dx,double dy)

Description: Moves the box by a certain distance

Returns:The enlarged box.

This is a convenience method which takes two values instead of a Point object. This method has been introduced in version 0.23.

[const] DBox moved(const DPoint distance)

Description: Returns the box moved by a certain distance

distance:The offset to move the box.
Returns:The moved box.

Moves the box by a given offset and returns the moved box. Does not modify this box. Does not check for coordinate overflows.

[static] new DBox ptr new

Description: Default constructor: creates an empty (invalid) box

Python specific notes:

This method is the default initializer of the object

[static] new DBox ptr new(double left,double bottom,double right,double top)

Description: Constructor with four coordinates

Four coordinates are given to create a new box. If the coordinates are not provided in the correct order (i.e. right < left), these are swapped.

Python specific notes:

This method is the default initializer of the object

[static] new DBox ptr new(const DPoint lower_left,const DPoint upper_right)

Description: Constructor with two points

Two points are given to create a new box. If the coordinates are not provided in the correct order (i.e. right < left), these are swapped.

Python specific notes:

This method is the default initializer of the object

[static] new DBox ptr new_lbrt(double left,double bottom,double right,double top)

Description: Constructor with four coordinates

Use of this method is deprecated. Use new instead

[static] new DBox ptr new_pp(const DPoint lower_left,const DPoint upper_right)

Description: Constructor with two points

Use of this method is deprecated. Use new instead

[const] bool overlaps?(const DBox box)

Description: Test if this box overlaps the argument box

Returns true, if the intersection box of this box with the argument box exists and has a non-vanishing area

[const] DPoint p1

Description: The lower left point of the box

Python specific notes:

The object exposes a readable attribute 'p1'. This is the getter.

void p1=(const DPoint p)

Description: Set the lower left point of the box

Python specific notes:

The object exposes a writable attribute 'p1'. This is the setter.

[const] DPoint p2

Description: The upper right point of the box

Python specific notes:

The object exposes a readable attribute 'p2'. This is the getter.

void p2=(const DPoint p)

Description: Set the upper right point of the box

Python specific notes:

The object exposes a writable attribute 'p2'. This is the setter.

[const] double perimeter

Description: Returns the perimeter of the box

This method is equivalent to 2*(width+height). For empty boxes, this method returns 0.

This method has been introduced in version 0.23.

[const] double right

Description: The right coordinate of the box

Python specific notes:

The object exposes a readable attribute 'right'. This is the getter.

void right=(double c)

Description: Set the right coordinate of the box

Python specific notes:

The object exposes a writable attribute 'right'. This is the setter.

[const] string to_s

Description: Convert to a string

Python specific notes:

This method is also available as 'str(object)'

[const] double top

Description: The top coordinate of the box

Python specific notes:

The object exposes a readable attribute 'top'. This is the getter.

void top=(double c)

Description: Set the top coordinate of the box

Python specific notes:

The object exposes a writable attribute 'top'. This is the setter.

[const] bool touches?(const DBox box)

Description: Test if this box touches the argument box

Returns true, if this box has at least one point common with the argument box

[const] DBox transformed(const DTrans t)

Description: Transform the box with the given simple transformation

t:The transformation to apply
Returns:The transformed box

[const] DBox transformed(const DCplxTrans t)

Description: Transform the box with the given complex transformation

t:The magnifying transformation to apply
Returns:The transformed box (a DBox now)

[const] DBox transformed_cplx(const DCplxTrans t)

Description: Transform the box with the given complex transformation

t:The magnifying transformation to apply
Returns:The transformed box (a DBox now)

Use of this method is deprecated. Use transformed instead

[const] double width

Description: The width of the box