API reference - Class Vector

Notation used in Ruby API documentation

Module: db

Description: A integer vector class

A vector is a distance in cartesian, 2 dimensional space. A vector is given by two coordinates (x and y) and represents the distance between two points. Being the distance, transformations act differently on vectors: the displacement is not applied. Vectors are not geometrical objects by itself. But they are frequently used in the database API for various purposes.

This class has been introduced in version 0.25.

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

Public constructors

new Vector ptrnew(const DVector dvector)Creates an integer coordinate vector from a floating-point coordinate vector
new Vector ptrnewDefault constructor: creates a null vector with coordinates (0,0)
new Vector ptrnew(const Point p)Default constructor: creates a vector from a point
new Vector ptrnew(int x,
int y)
Constructor for a vector from two coordinate values

Public methods

[const]bool!=(const Vector v)Inequality test operator
[const]Vector*(double f)Scaling by some factor
[const]long*(const Vector v)Computes the scalar product between self and the given vector
Vector*=(double f)Scaling by some factor
[const]Vector+(const Vector v)Adds two vectors
[const]Point+(const Point p)Adds a vector and a point
[const]Vector-(const Vector v)Subtract two vectors
[const]Vector-@Compute the negative of a vector
[const]Vector/(double d)Division by some divisor
Vector/=(double d)Division by some divisor
[const]bool<(const Vector v)"less" comparison operator
[const]bool==(const Vector v)Equality test operator
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]doubleabsReturns the length of the vector
voidassign(const Vector other)Assigns another object to self
[const]new Vector ptrdupCreates a copy of self
[const]unsigned longhashComputes a hash value
[const]doublelengthReturns the length of the vector
[const]longsprod(const Vector v)Computes the scalar product between self and the given vector
[const]intsprod_sign(const Vector v)Computes the scalar product between self and the given vector and returns a value indicating the sign of the product
[const]doublesq_absThe square length of the vector
[const]doublesq_lengthThe square length of the vector
[const]DVectorto_dtype(double dbu = 1)Converts the vector to a floating-point coordinate vector
[const]Pointto_pTurns the vector into a point
[const]stringto_s(double dbu = 0)String conversion
[const]longvprod(const Vector v)Computes the vector product between self and the given vector
[const]intvprod_sign(const Vector v)Computes the vector product between self and the given vector and returns a value indicating the sign of the product
[const]intxAccessor to the x coordinate
voidx=(int coord)Write accessor to the x coordinate
[const]intyAccessor to the y coordinate
voidy=(int coord)Write accessor to the y coordinate

Public static methods and constants

new Vector 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

Detailed description

!=

Signature: [const] bool != (const Vector v)

Description: Inequality test operator

*

(1) Signature: [const] Vector * (double f)

Description: Scaling by some factor

Returns the scaled object. All coordinates are multiplied with the given factor and if necessary rounded.

Python specific notes:
This method also implements '__rmul__'.

(2) Signature: [const] long * (const Vector v)

Description: Computes the scalar product between self and the given vector

The scalar product of a and b is defined as: vp = ax*bx+ay*by.

Python specific notes:
This method also implements '__rmul__'.

*=

Signature: Vector *= (double f)

Description: Scaling by some factor

Scales object in place. All coordinates are multiplied with the given factor and if necessary rounded.

+

(1) Signature: [const] Vector + (const Vector v)

Description: Adds two vectors

Adds vector v to self by adding the coordinates.

(2) Signature: [const] Point + (const Point p)

Description: Adds a vector and a point

Returns the point p shifted by the vector.

-

Signature: [const] Vector - (const Vector v)

Description: Subtract two vectors

Subtract vector v from self by subtracting the coordinates.

-@

Signature: [const] Vector -@

Description: Compute the negative of a vector

Returns a new vector with -x,-y.

/

Signature: [const] Vector / (double d)

Description: Division by some divisor

Returns the scaled object. All coordinates are divided with the given divisor and if necessary rounded.

/=

Signature: Vector /= (double d)

Description: Division by some divisor

Divides the object in place. All coordinates are divided with the given divisor and if necessary rounded.

<

Signature: [const] bool < (const Vector v)

Description: "less" comparison operator

This operator is provided to establish a sorting order

==

Signature: [const] bool == (const Vector v)

Description: Equality test operator

_create

Signature: 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.

_destroy

Signature: 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.

_destroyed?

Signature: [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.

_is_const_object?

Signature: [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.

_manage

Signature: 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.

_unmanage

Signature: 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.

abs

Signature: [const] double abs

Description: Returns the length of the vector

'abs' is an alias provided for compatibility with the former point type.

assign

Signature: void assign (const Vector other)

Description: Assigns another object to self

create

Signature: void create

Description: Ensures the C++ object is created

Use of this method is deprecated. Use _create instead

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.

destroy

Signature: void destroy

Description: Explicitly destroys the object

Use of this method is deprecated. Use _destroy instead

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.

destroyed?

Signature: [const] bool destroyed?

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

Use of this method is deprecated. Use _destroyed? instead

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.

dup

Signature: [const] new Vector ptr dup

Description: Creates a copy of self

Python specific notes:
This method also implements '__copy__' and '__deepcopy__'.

from_s

Signature: [static] new Vector ptr from_s (string s)

Description: Creates an object from a string

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

hash

Signature: [const] unsigned long hash

Description: Computes a hash value

Returns a hash value for the given vector. This method enables vectors as hash keys.

This method has been introduced in version 0.25.

Python specific notes:
This method is also available as 'hash(object)'.

is_const_object?

Signature: [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

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

length

Signature: [const] double length

Description: Returns the length of the vector

'abs' is an alias provided for compatibility with the former point type.

new

(1) Signature: [static] new Vector ptr new (const DVector dvector)

Description: Creates an integer coordinate vector from a floating-point coordinate vector

Python specific notes:
This method is the default initializer of the object.

(2) Signature: [static] new Vector ptr new

Description: Default constructor: creates a null vector with coordinates (0,0)

Python specific notes:
This method is the default initializer of the object.

(3) Signature: [static] new Vector ptr new (const Point p)

Description: Default constructor: creates a vector from a point

This constructor is equivalent to computing p-point(0,0). This method has been introduced in version 0.25.

Python specific notes:
This method is the default initializer of the object.

(4) Signature: [static] new Vector ptr new (int x, int y)

Description: Constructor for a vector from two coordinate values

Python specific notes:
This method is the default initializer of the object.

sprod

Signature: [const] long sprod (const Vector v)

Description: Computes the scalar product between self and the given vector

The scalar product of a and b is defined as: vp = ax*bx+ay*by.

sprod_sign

Signature: [const] int sprod_sign (const Vector v)

Description: Computes the scalar product between self and the given vector and returns a value indicating the sign of the product

Returns:1 if the scalar product is positive, 0 if it is zero and -1 if it is negative.

sq_abs

Signature: [const] double sq_abs

Description: The square length of the vector

'sq_abs' is an alias provided for compatibility with the former point type.

sq_length

Signature: [const] double sq_length

Description: The square length of the vector

'sq_abs' is an alias provided for compatibility with the former point type.

to_dtype

Signature: [const] DVector to_dtype (double dbu = 1)

Description: Converts the vector to a floating-point coordinate vector

The database unit can be specified to translate the integer-coordinate vector into a floating-point coordinate vector in micron units. The database unit is basically a scaling factor.

to_p

Signature: [const] Point to_p

Description: Turns the vector into a point

This method returns the point resulting from adding the vector to (0,0). This method has been introduced in version 0.25.

to_s

Signature: [const] string to_s (double dbu = 0)

Description: String conversion

If a DBU is given, the output units will be micrometers.

The DBU argument has been added in version 0.27.6.

Python specific notes:
This method is also available as 'str(object)'.

vprod

Signature: [const] long vprod (const Vector v)

Description: Computes the vector product between self and the given vector

The vector product of a and b is defined as: vp = ax*by-ay*bx.

vprod_sign

Signature: [const] int vprod_sign (const Vector v)

Description: Computes the vector product between self and the given vector and returns a value indicating the sign of the product

Returns:1 if the vector product is positive, 0 if it is zero and -1 if it is negative.

x

Signature: [const] int x

Description: Accessor to the x coordinate

Python specific notes:
The object exposes a readable attribute 'x'. This is the getter.

x=

Signature: void x= (int coord)

Description: Write accessor to the x coordinate

Python specific notes:
The object exposes a writable attribute 'x'. This is the setter.

y

Signature: [const] int y

Description: Accessor to the y coordinate

Python specific notes:
The object exposes a readable attribute 'y'. This is the getter.

y=

Signature: void y= (int coord)

Description: Write accessor to the y coordinate

Python specific notes:
The object exposes a writable attribute 'y'. This is the setter.