Vec2 (struct)¶
The Vec2 type represents a vector with 2 components. The Vec2 is also used as the row type for the Mat22.
/*
** Example: Vec2
*/
Vec2 v(0.0, 0.0);
Methods¶
Vec2 ( in Scalar value ) | |
Vec2 ( in Scalar x, in Scalar y ) | |
Vec2 ( in Vec2 other ) | |
Vec2 () | |
Vec2 | add ? ( in Vec2 other ) |
Boolean | almostEqual ? ( in Vec2 other ) |
Boolean | almostEqual ? ( in Vec2 other, in Scalar precision ) |
Scalar | angleTo ? ( in Vec2 other ) |
Vec2 | clamp ? ( in Vec2 min, in Vec2 max ) |
Vec2 | clone ? () |
Scalar | component ? ( in Size i ) |
Scalar | cross ? ( in Vec2 other ) |
Scalar | distanceTo ? ( in Vec2 other ) |
Scalar | distanceToLine ? ( in Vec2 lineP0, in Vec2 lineP1 ) |
Scalar | distanceToSegment ? ( in Vec2 segmentP0, in Vec2 segmentP1 ) |
Vec2 | divide ? ( in Vec2 other ) |
Vec2 | divideScalar ? ( in Scalar other ) |
Scalar | dot ? ( in Vec2 other ) |
Boolean | equal ? ( in Vec2 other ) |
get ? ( io Float32 v<> ) | |
get ? ( io Float32 v<>, in UInt32 o ) | |
get ? ( io Float32 v[] ) | |
get ? ( io Float32 v[], in UInt32 o ) | |
get ? ( io Float64 v<> ) | |
get ? ( io Float64 v<>, in UInt32 o ) | |
get ? ( io Float64 v[] ) | |
get ? ( io Float64 v[], in UInt32 o ) | |
Vec2 | getBarycentricCoords ? ( in Vec2 a, in Vec2 b, in Vec2 c ) |
UInt32 | hash ? () |
Vec2 | inverse ? () |
Boolean | isInsideTriangle ? ( in Vec2 a, in Vec2 b, in Vec2 c ) |
Boolean | isInsideTriangle ? ( in Vec2 a, in Vec2 b, in Vec2 c, in Scalar tolerance ) |
Scalar | length ? () |
Scalar | lengthSquared ? () |
Vec2 | linearInterpolate ? ( in Vec2 other, in Scalar t ) |
Vec2 | multiply ? ( in Vec2 other ) |
Vec2 | multiplyScalar ? ( in Scalar other ) |
Vec2 | negate ? () |
normalize ! () | |
Vec2 | rotate ? ( in Scalar radians ) |
set ! ( in Float32 v<> ) | |
set ! ( in Float32 v<>, in UInt32 o ) | |
set ! ( in Float64 v<> ) | |
set ! ( in Float64 v<>, in UInt32 o ) | |
set ! ( in Scalar value ) | |
set ! ( in Scalar x, in Scalar y ) | |
setComponent ! ( in Size i, in Scalar v ) | |
setNull ! () | |
Scalar | setUnit ! () |
Vec2 | subtract ? ( in Vec2 other ) |
Vec2 | unit ? () |
Vec2 | unit_safe ? () |
Scalar | unitsAngleTo ? ( in Vec2 other ) |
Methods in detail¶
Constructor with same scalar for all components
Vec2 ( in Scalar x, in Scalar y )
Constructor from scalar components
copy constructor
Vec2 ()
Default constructor
Vec2 Vec2.add? ( in Vec2 other )
Overload method for the add operator
Boolean Vec2.almostEqual? ( in Vec2 other )
Returns true if this vector is the same as another one (using a default precision)
Boolean Vec2.almostEqual? ( in Vec2 other, in Scalar precision )
Returns true if this vector is the same as another one (given a precision)
Scalar Vec2.angleTo? ( in Vec2 other )
Returns the angle (in radians) of this vector to another one
Vec2 Vec2.clamp? ( in Vec2 min, in Vec2 max )
clamps this vector per component by a min and max vector
clone method
Scalar Vec2.component? ( in Size i )
Returns the component of this vector by index
Scalar Vec2.cross? ( in Vec2 other )
Returns the cross product of this vector and another one
Scalar Vec2.distanceTo? ( in Vec2 other )
Returns the distance of this vector to another one
Scalar Vec2.distanceToLine? ( in Vec2 lineP0, in Vec2 lineP1 )
Returns the distance of this vector to a line defined by two points on the line
Scalar Vec2.distanceToSegment? ( in Vec2 segmentP0, in Vec2 segmentP1 )
Returns the distance of this vector to a line segment defined by the start and end points of the line segment
Vec2 Vec2.divide? ( in Vec2 other )
Overload method for the divide operator
Vec2 Vec2.divideScalar? ( in Scalar other )
Returns the division of this vector and a scalar
Scalar Vec2.dot? ( in Vec2 other )
Returns the dot product of this vector and another one
Boolean Vec2.equal? ( in Vec2 other )
Returns true if this vector is the same as another one
Getter as external float32 array
Vec2.get? ( io Float32 v<>, in UInt32 o )
Getter as external float32 array and an offset
Getter as float32 array
Vec2.get? ( io Float32 v[], in UInt32 o )
Getter as float32 array and an offset
Getter as external float64 array
Vec2.get? ( io Float64 v<>, in UInt32 o )
Getter as external float64 array and an offset
Getter as float64 array
Vec2.get? ( io Float64 v[], in UInt32 o )
Getter as float64 array and an offset
Vec2 Vec2.getBarycentricCoords? ( in Vec2 a, in Vec2 b, in Vec2 c )
Returns the barycentric coordinates of this vector in the triangle formed by a, b and c
Hash for this value
Returns the inversed version of this vector
Boolean Vec2.isInsideTriangle? ( in Vec2 a, in Vec2 b, in Vec2 c )
Returns true if this Vec2 is inside of a triangle formed by a, b and c
Boolean Vec2.isInsideTriangle? ( in Vec2 a, in Vec2 b, in Vec2 c, in Scalar tolerance )
Returns true if this Vec2 is inside of a triangle and has a minimum distance defined by tolerance.
Returns the length of this vector
Returns the squared length of this vector
Vec2 Vec2.linearInterpolate? ( in Vec2 other, in Scalar t )
Linearly interpolates this vector with another one based on a scalar blend value (0.0 to 1.0)
Vec2 Vec2.multiply? ( in Vec2 other )
Overload method for the multiply operator
Vec2 Vec2.multiplyScalar? ( in Scalar other )
Returns the product of this vector and a scalar
Returns the negated version of this vector
Vec2.normalize! ()
Vec2 Vec2.rotate? ( in Scalar radians )
Turns the vector provided a rotation in radians
Setter from (standard/external) float32 array
Vec2.set! ( in Float32 v<>, in UInt32 o )
Setter from (standard/external) float32 array and an offset
Setter from (standard/external) float64 array
Vec2.set! ( in Float64 v<>, in UInt32 o )
Setter from (standard/external) float64 array and an offset
Setter from same scalar for all components
Vec2.set! ( in Scalar x, in Scalar y )
Setter from scalar components
Vec2.setComponent! ( in Size i, in Scalar v )
Sets the component of this vector by index
Vec2.setNull! ()
Sets all components of this vec to 0.0
Sets this vector to its unit vector and returns its previous length
Vec2 Vec2.subtract? ( in Vec2 other )
Overload method for the subtract operator
Returns the unit vector of this one, throws and exception if almost zero length
Returns the unit vector of this one, with an arbitrary value if almost zero length
Scalar Vec2.unitsAngleTo? ( in Vec2 other )
Returns the angle (in radians) of this vector to another one
注釈
expects both vectors to be units (else use angleTo)