tensorbay.geometry.vector#

The implementation of the TensorBay vector.

class tensorbay.geometry.vector.Vector(x, y, z=None)[source]#

Bases: tensorbay.utility.user.UserSequence[float]

This class defines the basic concept of Vector.

Vector contains the coordinates of a 2D vector or a 3D vector.

Parameters
  • x (float) – The x coordinate of the vector.

  • y (float) – The y coordinate of the vector.

  • z (Optional[float]) – The z coordinate of the vector.

Return type

Union[Vector2D, Vector3D]

Examples

>>> Vector(1, 2)
Vector2D(1, 2)
>>> Vector(1, 2, 3)
Vector3D(1, 2, 3)
static loads(contents)[source]#

Loads a Vector from a dict containing coordinates of the vector.

Parameters

contents (Mapping[str, float]) – A dict containing coordinates of the vector.

Returns

The loaded Vector2D or Vector3D object.

Return type

Union[tensorbay.geometry.vector.Vector2D, tensorbay.geometry.vector.Vector3D]

Examples

>>> contents = {"x": 1.0, "y": 2.0}
>>> Vector.loads(contents)
Vector2D(1.0, 2.0)
>>> contents = {"x": 1.0, "y": 2.0, "z": 3.0}
>>> Vector.loads(contents)
Vector3D(1.0, 2.0, 3.0)
class tensorbay.geometry.vector.Vector2D(*args, **kwargs)[source]#

Bases: tensorbay.utility.user.UserSequence[float]

This class defines the concept of Vector2D.

Vector2D contains the coordinates of a 2D vector.

Parameters
  • x – The x coordinate of the 2D vector.

  • y – The y coordinate of the 2D vector.

  • args (float) –

  • kwargs (float) –

Return type

tensorbay.geometry.vector._V2

Examples

>>> Vector2D(1, 2)
Vector2D(1, 2)
classmethod loads(contents)[source]#

Load a Vector2D object from a dict containing coordinates of a 2D vector.

Parameters

contents (Mapping[str, float]) – A dict containing coordinates of a 2D vector.

Returns

The loaded Vector2D object.

Return type

tensorbay.geometry.vector._V2

Examples

>>> contents = {"x": 1.0, "y": 2.0}
>>> Vector2D.loads(contents)
Vector2D(1.0, 2.0)
property x: float#

Return the x coordinate of the vector.

Returns

X coordinate in float type.

Examples

>>> vector_2d = Vector2D(1, 2)
>>> vector_2d.x
1
property y: float#

Return the y coordinate of the vector.

Returns

Y coordinate in float type.

Examples

>>> vector_2d = Vector2D(1, 2)
>>> vector_2d.y
2
dumps()[source]#

Dumps the vector into a dict.

Returns

A dict containing the vector coordinate.

Return type

Dict[str, float]

Examples

>>> vector_2d = Vector2D(1, 2)
>>> vector_2d.dumps()
{'x': 1, 'y': 2}
class tensorbay.geometry.vector.Vector3D(*args, **kwargs)[source]#

Bases: tensorbay.utility.user.UserSequence[float]

This class defines the concept of Vector3D.

Vector3D contains the coordinates of a 3D Vector.

Parameters
  • x – The x coordinate of the 3D vector.

  • y – The y coordinate of the 3D vector.

  • z – The z coordinate of the 3D vector.

  • args (float) –

  • kwargs (float) –

Return type

tensorbay.geometry.vector._V3

Examples

>>> Vector3D(1, 2, 3)
Vector3D(1, 2, 3)
classmethod loads(contents)[source]#

Load a Vector3D object from a dict containing coordinates of a 3D vector.

Parameters

contents (Mapping[str, float]) – A dict contains coordinates of a 3D vector.

Returns

The loaded Vector3D object.

Return type

tensorbay.geometry.vector._V3

Examples

>>> contents = {"x": 1.0, "y": 2.0, "z": 3.0}
>>> Vector3D.loads(contents)
Vector3D(1.0, 2.0, 3.0)
property x: float#

Return the x coordinate of the vector.

Returns

X coordinate in float type.

Examples

>>> vector_3d = Vector3D(1, 2, 3)
>>> vector_3d.x
1
property y: float#

Return the y coordinate of the vector.

Returns

Y coordinate in float type.

Examples

>>> vector_3d = Vector3D(1, 2, 3)
>>> vector_3d.y
2
property z: float#

Return the z coordinate of the vector.

Returns

Z coordinate in float type.

Examples

>>> vector_3d = Vector3D(1, 2, 3)
>>> vector_3d.z
3
dumps()[source]#

Dumps the vector into a dict.

Returns

A dict containing the vector coordinates.

Return type

Dict[str, float]

Examples

>>> vector_3d = Vector3D(1, 2, 3)
>>> vector_3d.dumps()
{'x': 1, 'y': 2, 'z': 3}