Difference between revisions of "User:Cron Stardust/LLVector Spec"
(Code blocking and clarifying) |
(→Public Static Properties: Demonstration.) |
||
Line 15: | Line 15: | ||
* <cpp>static LLVector [xyzw]_axis_neg;</cpp> set to NUM(0) on all but the relevant axis, which is set to NUM(-1). | * <cpp>static LLVector [xyzw]_axis_neg;</cpp> set to NUM(0) on all but the relevant axis, which is set to NUM(-1). | ||
Where you see [xyzw] create one property for each applicable character; e.g. a 2D type will only need X and Y | Where you see [xyzw] create one property for each applicable character; e.g. a 2D type will only need X and Y: | ||
<cpp> | |||
static LLVector2 x_axis; | |||
static LLVector2 y_axis; | |||
static LLVector2 x_axis_neg; | |||
static LLVector2 y_axis_neg; | |||
</cpp> | |||
== Public Constructors == | == Public Constructors == |
Revision as of 20:07, 5 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
- <cpp>static LLVector zero;</cpp> set to NUM(0) on all axis.
- <cpp>static LLVector [xyzw]_axis;</cpp> set to NUM(0) on all but the relevant axis, which is set to NUM(1).
- <cpp>static LLVector [xyzw]_axis_neg;</cpp> set to NUM(0) on all but the relevant axis, which is set to NUM(-1).
Where you see [xyzw] create one property for each applicable character; e.g. a 2D type will only need X and Y: <cpp> static LLVector2 x_axis; static LLVector2 y_axis; static LLVector2 x_axis_neg; static LLVector2 y_axis_neg; </cpp>
Public Constructors
- Basic Constructor: <cpp>LLVector()</cpp>
- Direct-value Constructor: <cpp>LLVector(NUM x, NUM y, ...)</cpp> be VERY sure to clarify your call by only passing floating point values - integers can cause ambiguity.
- Array Constructor: <cpp>LLVector(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
- Each element in the array represents the, if applicable, X, Y, Z, and W values of the vector.
Note that this is a significant departure from previous convention: there is to be NO differentiating the array-of-values property by its datatype. This is to make switching vector formats as painless as possible - there's already too much to watch for other than simple semantic changes.
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
- <cpp>LLSD getValue() const</cpp>
- <cpp>const LLVector& setValue(const LLSD& sd)</cpp>
Setting
Methods in this category shall mimic the constructors.
- <cpp>const LLVector& setZero()</cpp> Same as set(0, 0, ...)
- <cpp>const LLVector& set(NUM x, NUM y, ...)</cpp> However many axis are needed to fully define the current type. Defaulting some values is acceptable. Be VERY sure to clarify your call by only passing floating point values - integers can cause ambiguity.
- <cpp>const LLVector& set(const NUM* vec, U32 len = C)</cpp> where C is the expected count of elements in X, Y, Z, W order.
Reading
- <cpp>BOOL isExactlyZero() const</cpp>
- <cpp>BOOL isFinite() const</cpp>
- <cpp>BOOL isNull() const</cpp>
- <cpp>NUM length() const</cpp>
- <cpp>LLVector scaled(const LLVector& vec) const</cpp>
Modifying
- <cpp>NUM normalize()</cpp>
- <cpp>const LLVector& scale(const LLVector& vec)</cpp>
- <cpp>BOOL clampAndWasChanged(NUM min, NUM max)</cpp>
- <cpp>const LLVector& clamp(NUM min, NUM max)</cpp>
- <cpp>BOOL clampAndWasChanged(const LLVector& min, const LLVector& max)</cpp>
- <cpp>const LLVector& clamp(const LLVector& min, const LLVector& max)</cpp>
- <cpp>BOOL clampLengthAndWasChanged(NUM min, NUM max)</cpp>
- <cpp>const LLVector& clampLength(NUM limit)</cpp>
- <cpp>const LLVector& transform(const LLMatrix)</cpp>
The following only make sense in 2 dimensional vectors:
- <cpp>const LLVector& rotate(NUM angle)</cpp>
The following only make sense in 3 or more dimensional vectors:
- <cpp>const LLVector& rotate(NUM angle, const LLVector& axis)</cpp>
- <cpp>const LLVector& rotate(NUM angle, NUM axis_x_component, NUM axis_y_component, NUM axis_z_component, ...)</cpp>
- <cpp>const LLVector& rotate(const LLQuaternion& q)</cpp>
Operators
- <cpp>NUM operator[] (int idx) const</cpp>
- <cpp>NUM& operator[] (int idx)</cpp>
The following all are typically implemented as "friend" methods.
- <cpp>BOOL operator< (const LLVector&, const LLVector&) const</cpp> less-than
- <cpp>LLVector operator+ (const LLVector&, const LLVector&) cons</cpp> addition
- <cpp>LLVector operator- (const LLVector&, const LLVector&) const</cpp> subtraction
- <cpp>LLVector operator- (const LLVector&) const</cpp> negation
- <cpp>LLVector operator* (const LLVector&, const LLVector&) const</cpp> dot product
- <cpp>LLVector operator* (const LLVector&, NUM) const</cpp> scaling
- <cpp>LLVector operator* (NUM, const LLVector&) const</cpp> scaling
- <cpp>LLVector operator/ (const LLVector&, NUM) const</cpp> scaling
- <cpp>BOOL operator== (const LLVector&, const LLVector&) const</cpp> equality
- <cpp>BOOL operator!= (const LLVector&, const LLVector&) const</cpp> non-equality
- <cpp>const LLVector& operator+= (const LLVector&, const LLVector&)</cpp> addition-assignment
- <cpp>const LLVector& operator-= (const LLVector&, const LLVector&)</cpp> subtraction-assignment
- <cpp>const LLVector& operator*= (const LLVector&, NUM)</cpp> scaling-assignment
- <cpp>const LLVector& operator/= (const LLVector&, NUM)</cpp> scaling-assignment
- <cpp>std::ostream& operator<<(std::ostream&, const LLVector3 &) const</cpp>
These only make sense when the number of axis is greater than or equal to 3.
- <cpp>LLVector operator% (const LLVector&, const LLVector&) const</cpp> cross product
- <cpp>const LLVector& operator%= (const LLVector&, const LLVector&)</cpp> cross-product-assignment
- <cpp>LLVector operator* (const LLVector&, const LLQuaternion&) const </cpp> quat rotation
- <cpp>const LLVector& operator*= (const LLVector&, const LLQuaternion&)</cpp> quat rotation
- <cpp>LLVector operator* (const LLVector&, const LLMatrix&) const</cpp> matrix transformation
- <cpp>const LLVector& operator*= (const LLVector&, const LLMatrix&)</cpp> matrix transformation