Difference between revisions of "User:Cron Stardust/LLVector Spec"

From Second Life Wiki
Jump to navigation Jump to search
(→‎Public Methods: const returns..)
(→‎Operators: const returned references)
Line 83: Line 83:
* BOOL operator== (const LLVector&, const LLVector&) const // equality
* BOOL operator== (const LLVector&, const LLVector&) const // equality
* BOOL operator!= (const LLVector&, const LLVector&) const // non-equality
* BOOL operator!= (const LLVector&, const LLVector&) const // non-equality
* LLVector& operator+= (const LLVector&, const LLVector&) // addition-assignment
* const LLVector& operator+= (const LLVector&, const LLVector&) // addition-assignment
* LLVector& operator-= (const LLVector&, const LLVector&) // subtraction-assignment
* const LLVector& operator-= (const LLVector&, const LLVector&) // subtraction-assignment
* LLVector& operator*= (const LLVector&, NUM) // scaling-assignment
* const LLVector& operator*= (const LLVector&, NUM) // scaling-assignment
* LLVector& operator/= (const LLVector&, NUM) // scaling-assignment
* const LLVector& operator/= (const LLVector&, NUM) // scaling-assignment
* std::ostream& operator<<(std::ostream&, const LLVector3 &) const
* std::ostream& operator<<(std::ostream&, const LLVector3 &) const


These only make sense when the number of axis is greater than or equal to 3.
These only make sense when the number of axis is greater than or equal to 3.
* LLVector operator% (const LLVector&, const LLVector&) const // cross product
* LLVector operator% (const LLVector&, const LLVector&) const // cross product
* LLVector& operator%= (const LLVector&, const LLVector&) // cross-product-assignment
* const LLVector& operator%= (const LLVector&, const LLVector&) // cross-product-assignment
* LLVector operator* (const LLVector&, const LLQuaternion&) const // quat rotation
* LLVector operator* (const LLVector&, const LLQuaternion&) const // quat rotation
* LLVector& operator*= (const LLVector&, const LLQuaternion&) // quat rotation
* const LLVector& operator*= (const LLVector&, const LLQuaternion&) // quat rotation
* LLVector operator* (const LLVector&, const LLMatrix&) const // matrix transformation
* LLVector operator* (const LLVector&, const LLMatrix&) const // matrix transformation
* LLVector& operator*= (const LLVector&, const LLMatrix&) // matrix transformation
* const LLVector& operator*= (const LLVector&, const LLMatrix&) // matrix transformation

Revision as of 18:25, 4 April 2014

This is a simple specification for all LLVector formats. This does NOT include the LLColor formats.

Everything below is to be considered a minimum compatibility specification. Specific type implementations are free to add extra items as their own use cases dictate.

Every type that is only differentiated from another type by the precision, or number of bits, in its components shall be directly compatible: all such related types are to implement the same public interface.

It is recommended that types be freely convertible between themselves, but this is not a requirement.


In the below please replace LLVector with the name of your specific type. Also replace any instants of NUM with your specific class's base type; eg. F32, F64, &c. Likewise with LLMatrix, replace with the corresponding matrix type.

Public Static Properties

  • zero
  • [xyzw]_axis
  • [xyzw]_axis_neg

Where you see [xyzw] create one property for each applicable character - a 2D type will only need X and Y for instance.

Public Constructors

  • Basic Constructor: ()
  • Direct-value Constructor: (NUM x, NUM y, ...)
  • Array Constructor: (const NUM* vec, U32 len = C) // where C is the expected count of elements in X, Y, Z, W order.

Public Properties

  • Array of values: mV or mdV
    • Each element in the array represents the, if applicable, X, Y, Z, and W values of the vector.

Public Methods

Inlining or not shall be determined on a case-by-case basis.

All methods that have a return type of LLVector& shall return a reference to the current instance.

Serialization

  • LLSD getValue() const
  • const LLVector& setValue(const LLSD& sd)

Setting

Methods in this category shall mimic the constructors.

  • const LLVector& setZero() // Same as set(0, 0, ...)
  • const LLVector& set(NUM x, NUM y, ...) // However many axis are needed to fully define the current type. Defaulting some values is acceptable.
  • const LLVector& set(const NUM* vec, U32 len = C) // where C is the expected count of elements in X, Y, Z, W order.

Reading

  • BOOL isExactlyZero() const
  • BOOL isFinite() const
  • BOOL isNull() const
  • NUM length() const
  • LLVector scaled(const LLVector& vec) const

Modifying

  • NUM normalize()
  • const LLVector& scale(const LLVector& vec)
  • BOOL clampAndWasChanged(NUM min, NUM max)
  • const LLVector& clamp(NUM min, NUM max)
  • BOOL clampAndWasChanged(const LLVector& min, const LLVector& max)
  • const LLVector& clamp(const LLVector& min, const LLVector& max)
  • BOOL clampLengthAndWasChanged(NUM min, NUM max)
  • const LLVector& clampLength(NUM limit)
  • const LLVector& transform(const LLMatrix)

The following only make sense in 2 dimensional vectors:

  • const LLVector& rotate(NUM angle)

The following only make sense in 3 or more dimensional vectors:

  • const LLVector& rotate(NUM angle, const LLVector& axis)
  • const LLVector& rotate(NUM angle, NUM axis_x_component, NUM axis_y_component, NUM axis_z_component, ...)
  • const LLVector& rotate(const LLQuaternion& q)

Operators

  • NUM operator[] (int idx) const
  • NUM& operator[] (int idx)

The following all are typically implemented as "friend" methods.

  • BOOL operator< (const LLVector&, const LLVector&) const // less-than
  • LLVector operator+ (const LLVector&, const LLVector&) const // addition
  • LLVector operator- (const LLVector&, const LLVector&) const // subtraction
  • LLVector operator- (const LLVector&) const // negation
  • LLVector operator* (const LLVector&, const LLVector&) const // dot product
  • LLVector operator* (const LLVector&, NUM) const // scaling
  • LLVector operator* (NUM, const LLVector&) const // scaling
  • LLVector operator/ (const LLVector&, NUM) const // scaling
  • BOOL operator== (const LLVector&, const LLVector&) const // equality
  • BOOL operator!= (const LLVector&, const LLVector&) const // non-equality
  • const LLVector& operator+= (const LLVector&, const LLVector&) // addition-assignment
  • const LLVector& operator-= (const LLVector&, const LLVector&) // subtraction-assignment
  • const LLVector& operator*= (const LLVector&, NUM) // scaling-assignment
  • const LLVector& operator/= (const LLVector&, NUM) // scaling-assignment
  • std::ostream& operator<<(std::ostream&, const LLVector3 &) const

These only make sense when the number of axis is greater than or equal to 3.

  • LLVector operator% (const LLVector&, const LLVector&) const // cross product
  • const LLVector& operator%= (const LLVector&, const LLVector&) // cross-product-assignment
  • LLVector operator* (const LLVector&, const LLQuaternion&) const // quat rotation
  • const LLVector& operator*= (const LLVector&, const LLQuaternion&) // quat rotation
  • LLVector operator* (const LLVector&, const LLMatrix&) const // matrix transformation
  • const LLVector& operator*= (const LLVector&, const LLMatrix&) // matrix transformation