User:Cron Stardust/LLVector Spec

From Second Life Wiki
< User:Cron Stardust
Revision as of 20:53, 5 April 2014 by Cron Stardust (talk | contribs) (→‎Public Constructors: Added note about conversion constructors.)
Jump to navigation Jump to search

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: <cpp>LLVector2()</cpp>
  • Direct-value Constructor: <cpp>LLVector2(NUM x, NUM y, ...)</cpp>
  • Array Constructor: <cpp>LLVector2(const NUM* vec, U32 len = C)</cpp> where C is the expected count of elements in X, Y, Z, W order.


Conversion constructors are to be marked explicit, and are optional: they are not required by this specification, but are a good idea - it's nice to the programmers to provide that extra bit of fluff that makes things easy to use. After all that why there's so many operators, right? Example: <cpp> explicit LLVector2(const LLVector3& vec); </cpp>

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