Into

Modules

Documentation

classPiiVector

#include <PiiVector.h>

A D -dimensional vector.

Inherits PiiArithmeticBase< PiiVector< T, D >, PiiVectorTraits< T, D > >

Description

PiiVector can be used to represent points and vectors in multidimensional spaces. The size of a vector is fixed, and all of its data is within the class itself. That is, there is no heap-allocated data, and sizeof(PiiVector<T,D>) == sizeof(T) * D.

Matrices and vectors are distinct entities, but a row of a matrix can be treated as a vector:

 typedef PiiVector<int,3> Vec3;
 PiiMatrix<int> matData(1,3, 1,2,3);
 Vec3& vec = *reinterpret_cast<Vec3*>(matData[0]);
 // Better yet: vec = *matData.rowAs<Vec3>();
 QCOMPARE(vec[0], 1);
 QCOMPARE(vec[1], 2);
 QCOMPARE(vec[2], 3);

Public types

typedef PiiArithmeticBase< PiiVector< T, D >, PiiVectorTraits< T, D > >

Shorthand for the base class type.

typedef Pii::VaArg< T >::Type

Shorthand for variable argument type.

Constructors and destructor

( )

Create a new measumerent point.

(
  • const T * ptr
)

Create a new vector by copying values from a preallocated array.

( )

Create a new vector with all values initialized to zero.

Public member functions

( )

Returns an stl-style const iterator to the beginning of data.

( )

Returns an stl-style iterator to the beginning of data.

end
( )

Returns an stl-style iterator to the end of data.

end
( )

Returns an stl-style const iterator to the end of data.

double
( )
void
( )

Change vector to a unit vector with the original orientation.

Get a unit vector that has the same orientation as this vector.

T
(
  • int index
)

Analogous to operator[].

T &
(
  • int index
)

Analogous to operator[], non-const version.

( )

Copy another vector.

T
(
  • int index
)

Get the value of the vector at index as a copy.

T &
(
  • int index
)

Get a reference to the value of the vector at index.

double
( )

Calculate squared geometric distance to another vector.

double

Get the squared length of this vector.

Function details

  • PiiVector

    ( )
    [inline]

    Create a new measumerent point.

     PiiVector<int,3>* p = new PiiVector<int,3>(1, 2, 3);
     PiiVector<double,4>* d = new PiiVector<double,4>(1.0, 2.0, 3.0, 4.0);
    
     PiiVector<double,4> pt(1, 2, 3, 4); // WRONG! Arguments are ints
    

    Using this constructor is dangerous. Make sure that all arguments are passed correctly.

  • PiiVector

    (
    • const T * ptr
    )
    [inline]

    Create a new vector by copying values from a preallocated array.

    Parameters
    ptr

    a pointer to the first value. This array must hold at leasts D elements.

  • PiiVector

    ()
    [inline]

    Create a new vector with all values initialized to zero.

  • BaseType::ConstIterator begin

    ()
    [inline]

    Returns an stl-style const iterator to the beginning of data.

  • BaseType::Iterator begin

    ()
    [inline]

    Returns an stl-style iterator to the beginning of data.

  • BaseType::Iterator end

    ()
    [inline]

    Returns an stl-style iterator to the end of data.

  • BaseType::ConstIterator end

    ()
    [inline]

    Returns an stl-style const iterator to the end of data.

  • double length

    ()
    [inline]
  • void normalize

    ()
    [inline]

    Change vector to a unit vector with the original orientation.

    If the length of the vector is zero, no changes will be made.

  • PiiVector normalized

    ()
    [inline]

    Get a unit vector that has the same orientation as this vector.

    If the length of the vector is zero, the result will be equal to this vector.

  • T operator()

    (
    • int index
    )
    [inline]

    Analogous to operator[].

    This operator is useful for template functions that work with both PiiMatrix and PiiVector.

  • T & operator()

    (
    • int index
    )
    [inline]

    Analogous to operator[], non-const version.

    This operator is useful for template functions that work with both PiiMatrix and PiiVector.

  • PiiVector & operator=

    ( )
    [inline]

    Copy another vector.

  • T operator[]

    (
    • int index
    )
    [inline]

    Get the value of the vector at index as a copy.

  • T & operator[]

    (
    • int index
    )
    [inline]

    Get a reference to the value of the vector at index.

  • double squaredDistance

    ( )
    [inline]

    Calculate squared geometric distance to another vector.

  • double squaredLength

    ()
    [inline]

    Get the squared length of this vector.

Notes (0)

Add a note

Not a single note added yet. Be the first, add yours.