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

From Second Life Wiki
Jump to navigation Jump to search
(Added operators section)
Line 67: Line 67:


== Operators ==
== Operators ==
* NUM [] (int idx) const
* NUM &[] (int idx)
The following all are typically implemented as "friend" methods.
* BOOL < (const LLVector&, const LLVector&) // less-than
* LLVector + (const LLVector&, const LLVector&) // addition
* LLVector - (const LLVector&, const LLVector&) // subtraction
* LLVector - (const LLVector&) // negation
* LLVector * (const LLVector&, const LLVector&) // dot product
* LLVector * (const LLVector&, NUM) // scaling
* LLVector * (NUM, const LLVector&) // scaling
* LLVector / (const LLVector&, NUM) // scaling
* BOOL == (const LLVector&, const LLVector&) // equality
* BOOL != (const LLVector&, const LLVector&) // non-equality
* LLVector& += (const LLVector&, const LLVector&) // addition-assignment
* LLVector& -= (const LLVector&, const LLVector&) // subtraction-assignment
* LLVector& *= (const LLVector&, NUM) // scaling-assignment
* LLVector& /= (const LLVector&, NUM) // scaling-assignment
* std::ostream& <<(std::ostream&, const LLVector3 &)
These only make sense when the number of axis is greater than or equal to 3.
* LLVector % (const LLVector&, const LLVector&) // cross product
* LLVector& %= (const LLVector&, const LLVector&) // cross-product-assignment

Revision as of 22:21, 3 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.

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: (x, y, ...)
  • Array Constructor: (*vec, 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

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.

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
  • LLVector& setValue(const LLSD& sd)

Setting

Methods in this category shall mimic the constructors.

  • LLVector& setZero()
  • LLVector& set(NUM x, NUM y, ...) // However many axis are needed to fully define the current type. Defaulting some values is acceptable.

Reading

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

Modifying

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

The following only make sense in 2 dimensional vectors:

  • LLVector& rotate(NUM angle)

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

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

Operators

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

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

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

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

  • LLVector % (const LLVector&, const LLVector&) // cross product
  • LLVector& %= (const LLVector&, const LLVector&) // cross-product-assignment