Class: Numerix::Vector2

Inherits:
VectorBase show all
Defined in:
lib/numerix/vector2.rb

Overview

A structure encapsulating two single precision floating point values.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Structure

#[], #[]=, #address, #dup, #each, #pack, #ptr, size, unpack

Constructor Details

#initialize(*args) ⇒ Vector2

TODO



15
16
# File 'lib/numerix/vector2.rb', line 15

def initialize(*args) # TODO
end

Instance Attribute Details

#xFloat

Returns the X component of the vector.

Returns:

  • (Float)

    the X component of the vector.



9
10
11
# File 'lib/numerix/vector2.rb', line 9

def x
  @x
end

#yFloat

Returns the Y component of the vector.

Returns:

  • (Float)

    the Y component of the vector.



13
14
15
# File 'lib/numerix/vector2.rb', line 13

def y
  @y
end

Class Method Details

.clamp(min, max) ⇒ Vector2 .clamp(min, max) ⇒ Vector2

Returns a vector that is result of clamping a vector between the specified minimum and maximum values.

Overloads:

  • .clamp(min, max) ⇒ Vector2

    Clamps the vector's components between the specified values.

    Parameters:

    • min (Float)

      The minimum value.

    • max (Float)

      The maximum value.

  • .clamp(min, max) ⇒ Vector2

    Clamps the vector's on a component-wise basis between the minimum and maximum values of the specified vectors.

    Parameters:

    • min (Vector2)

      The minimum value.

    • max (Vector2)

      The maximum value.

Returns:

  • (Vector2)

    the result of clamping this vector.



476
477
# File 'lib/numerix/vector2.rb', line 476

def clamp(vector, min, max)
end

.create_norm(x, y) ⇒ Vector2

Creates and returns a normalized vector from the specified components.

This is more efficient than creating and then normalizing.

Parameters:

  • x (Float)

    The X component of the vector.

  • y (Float)

    The Y component of the vector.

Returns:

  • (Vector2)

    the newly created normalized vector.



455
456
# File 'lib/numerix/vector2.rb', line 455

def create_norm(x, y)
end

.lerp(vector1, vector2, amount) ⇒ Vector2

Linearly interpolates between two vectors based on the given weighting.

Parameters:

  • vector1 (Vector2)

    The first source vector.

  • vector2 (Vector2)

    The second source vector.

  • amount (Float)

    Value between 0.0 and 1.0 indicating the weight of the second source vector.

Returns:

  • (Vector2)

    the interpolated vector.



488
489
# File 'lib/numerix/vector2.rb', line 488

def lerp(vector1, vector2, amount)
end

.max(vector, other) ⇒ Vector2 .max(vector, value) ⇒ Vector2

Returns a vector with a maximum set of values.

Overloads:

  • .max(vector, other) ⇒ Vector2

    Returns a vector whose elements are the maximum of each of the pairs of elements in the two source vectors.

    Parameters:

    • vector (Vector2)

      The first source vector.

    • other (Vector2)

      The second source vector.

  • .max(vector, value) ⇒ Vector2

    Returns a vector whose elements are the maximum of each of vector element and the specified value.

    Parameters:

    • vector (Vector2)

      The source vector.

    • value (Float)

      The maximum value.

Returns:

  • (Vector2)

    the maximized vector.



530
531
# File 'lib/numerix/vector2.rb', line 530

def max(vector, other)
end

.min(vector, other) ⇒ Vector2 .min(vector, value) ⇒ Vector2

Returns a vector with a minimum set of values.

Overloads:

  • .min(vector, other) ⇒ Vector2

    Returns a vector whose elements are the minimum of each of the pairs of elements in the two source vectors.

    Parameters:

    • vector (Vector2)

      The first source vector.

    • other (Vector2)

      The second source vector.

  • .min(vector, value) ⇒ Vector2

    Returns a vector whose elements are the minimum of each of vector element and the specified value.

    Parameters:

    • vector (Vector2)

      The source vector.

    • value (Float)

      The minimum value.

Returns:

  • (Vector2)

    the minimized vector.



509
510
# File 'lib/numerix/vector2.rb', line 509

def min(vector, other)
end

.oneVector2

Returns the vector <1.0, 1.0>.

Returns:

  • (Vector2)

    the vector <1.0, 1.0>.



433
434
# File 'lib/numerix/vector2.rb', line 433

def one
end

.unit_xVector2

Returns the vector <1.0, 0.0>.

Returns:

  • (Vector2)

    the vector <1.0, 0.0>.



438
439
# File 'lib/numerix/vector2.rb', line 438

def unit_x
end

.unit_yVector2

Returns the vector <0.0, 1.0>.

Returns:

  • (Vector2)

    the vector <0.0, 1.0>.



443
444
# File 'lib/numerix/vector2.rb', line 443

def unit_y
end

.zeroVector2

Returns the vector <0.0, 0.0>.

Returns:

  • (Vector2)

    the vector <0.0, 0.0>.



428
429
# File 'lib/numerix/vector2.rb', line 428

def zero
end

Instance Method Details

#*(scalar) ⇒ Vector2 #*(other) ⇒ Vector2

Vector multiplication.

Overloads:

  • #*(scalar) ⇒ Vector2

    Scalar vector multiplication.

    Parameters:

    • scalar (Float)

      The scalar value.

  • #*(other) ⇒ Vector2

    Multiplies this vector by another.

    Parameters:

    • other (Vector2)

      The source vector to multiply.

Returns:

  • (Vector2)

    the product vector.



285
286
# File 'lib/numerix/vector2.rb', line 285

def *(other)
end

#**(exponent) ⇒ Vector2

Raises the vector to the given power.

Parameters:

  • exponent (Float)

    The power to raise the vector to.

Returns:

  • (Vector2)

    New vector that is result of the operation.



250
251
# File 'lib/numerix/vector2.rb', line 250

def **(exponent)
end

#+(other) ⇒ Vector2

Adds this vector with another.

Parameters:

  • other (Vector2)

    The vector to add.

Returns:

  • (Vector2)

    the sum of the vectors.



259
260
# File 'lib/numerix/vector2.rb', line 259

def +(other)
end

#-(other) ⇒ Vector2

Gets the difference of this vector and another.

Parameters:

  • other (Vector2)

    The vector to subtract.

Returns:

  • (Vector2)

    the difference of the vectors.



268
269
# File 'lib/numerix/vector2.rb', line 268

def -(other)
end

#-@Vector2

Performs unary negation on this vector instance.

Returns:

  • (Vector2)

    the vector with swapped +/- values.



318
319
# File 'lib/numerix/vector2.rb', line 318

def -@
end

#*(scalar) ⇒ Vector2 #*(other) ⇒ Vector2

Vector division.

Overloads:

  • #*(scalar) ⇒ Vector2

    Scalar vector division.

    Parameters:

    • scalar (Float)

      The scalar value.

  • #*(other) ⇒ Vector2

    Divides this vector by another.

    Parameters:

    • other (Vector2)

      The source vector to divide.

Returns:

  • (Vector2)

    the resulting vector.



302
303
# File 'lib/numerix/vector2.rb', line 302

def /(other)
end

#==(other) ⇒ Boolean

Returns flag if this vector instance is equal to the given object.

Parameters:

  • other (Object)

    The object to compare.

Returns:

  • (Boolean)

    true if objects are equal, otherwise false.



311
312
# File 'lib/numerix/vector2.rb', line 311

def ==(other)
end

#absVector2

Returns a vector whose elements are the absolute values of each of this vector's elements.

Returns:

  • (Vector2)

    a vector whose elements are the absolute values of each of this vector's elements.



109
110
# File 'lib/numerix/vector2.rb', line 109

def abs
end

#angle(other) ⇒ Float

Computes the angle between this vector and another.

Parameters:

  • other (Vector2)

    The vector to calculate angle from.

Returns:

  • (Float)

    the angle, in degrees, between the two vectors.



346
347
# File 'lib/numerix/vector2.rb', line 346

def angle(other)
end

#clamp(min, max) ⇒ Vector2 #clamp(min, max) ⇒ Vector2

Returns a vector that is result of clamping this vector between the specified minimum and maximum values.

Overloads:

  • #clamp(min, max) ⇒ Vector2

    Clamps the vector's components between the specified values.

    Parameters:

    • min (Float)

      The minimum value.

    • max (Float)

      The maximum value.

  • #clamp(min, max) ⇒ Vector2

    Clamps the vector's on a component-wise basis between the minimum and maximum values of the specified vectors.

    Parameters:

    • min (Vector2)

      The minimum value.

    • max (Vector2)

      The maximum value.

Returns:

  • (Vector2)

    the result of clamping this vector.

See Also:



147
148
# File 'lib/numerix/vector2.rb', line 147

def clamp(min, max)
end

#clamp!(min, max) ⇒ Vector2 #clamp!(min, max) ⇒ Vector2

Clamps this vector between the specified minimum and maximum values.

Overloads:

  • #clamp!(min, max) ⇒ Vector2

    Clamps the vector's components between the specified values.

    Parameters:

    • min (Float)

      The minimum value.

    • max (Float)

      The maximum value.

  • #clamp!(min, max) ⇒ Vector2

    Clamps the vector's on a component-wise basis between the minimum and maximum values of the specified vectors.

    Parameters:

    • min (Vector2)

      The minimum value.

    • max (Vector2)

      The maximum value.

Returns:

See Also:



169
170
# File 'lib/numerix/vector2.rb', line 169

def clamp!(min, max)
end

#cross_product(other) ⇒ Float

Returns the cross-product between this vector and another.

Parameters:

  • other (Vector2)

    The source vector.

Returns:

  • (Float)

    the cross product.



355
356
# File 'lib/numerix/vector2.rb', line 355

def cross_product(other)
end

#distance(vector) ⇒ Float

Returns the Euclidean distance between this vector and another.

Parameters:

  • vector (Vector2)

    The point to get distance between.

Returns:

  • (Float)

    the distance.



51
52
# File 'lib/numerix/vector2.rb', line 51

def distance(vector)
end

#distance_squared(vector) ⇒ Float

Returns the squared Euclidean distance between this vector and another.

Parameters:

  • vector (Vector2)

    The point to get distance between.

Returns:

  • (Float)

    the distance squared.



59
60
# File 'lib/numerix/vector2.rb', line 59

def distance_squared(vector)
end

#dot(other) ⇒ Float

Returns the dot product of this vector and another.

Parameters:

  • other (Vector2)

    the source vector to compute dot product of.

Returns:

  • (Float)

    the dot product.



124
125
# File 'lib/numerix/vector2.rb', line 124

def dot(other)
end

#length_squaredFloat

Returns the length of the vector squared.

Returns:

  • (Float)

    the length of the vector squared.



20
21
# File 'lib/numerix/vector2.rb', line 20

def length_squared
end

#lerp(vector, amount) ⇒ Vector2

Linearly interpolates between this vector and another based on the given weighting.

Parameters:

  • vector (Vector2)

    The source vector to interpolate between.

  • amount (Float)

    Value between 0.0 and 1.0 indicating the weight of the given vector.

Returns:

  • (Vector2)

    the interpolated vector.

See Also:



89
90
# File 'lib/numerix/vector2.rb', line 89

def lerp(vector, amount)
end

#lerp!(vector, amount) ⇒ self

Linearly interpolates between this vector and another based on the given weighting, altering the values of this vector.

Parameters:

  • vector (Vector2)

    The source vector to interpolate between.

  • amount (Float)

    Value between 0.0 and 1.0 indicating the weight of the given vector.

Returns:

  • (self)

See Also:



103
104
# File 'lib/numerix/vector2.rb', line 103

def lerp!(vector, amount)
end

#mapObject Also known as: collect

See Also:



223
224
# File 'lib/numerix/vector2.rb', line 223

def map
end

#map! {|component| ... } ⇒ self Also known as: collect!

Invokes the given block once for each element of self, replacing the element with the value returned by the block.

The values of the vector are altered without creating a ne object.

Yields:

  • (component)

    Yields a component of the vector to the block.

Yield Parameters:

  • component (Float)

    The yielded component.

Returns:

  • (self)

See Also:



238
239
# File 'lib/numerix/vector2.rb', line 238

def map!
end

#max_valueFloat

Returns the greatest value of the vector's components.

Returns:

  • (Float)

    the greatest value of the vector's components.



42
43
# File 'lib/numerix/vector2.rb', line 42

def max_value
end

#min_valueFloat

Returns the lowest value of the vector's components.

Returns:

  • (Float)

    the lowest value of the vector's components.



37
38
# File 'lib/numerix/vector2.rb', line 37

def min_value
end

#normalizeVector2

Returns a new vector with the same direction as the given vector, but with a length of 1.0.

Returns:

  • (Vector2)

    a normalized vector.



67
68
# File 'lib/numerix/vector2.rb', line 67

def normalize
end

#normalize!self

Alters this vector instance to maintain same direction, but adjust values so that vector has a length of 1.0.

Returns:

  • (self)


75
76
# File 'lib/numerix/vector2.rb', line 75

def normalize!
end

#one?Boolean

Returns flag indicating if all values of the vector are equal to 1.0.

Returns:

  • (Boolean)

    flag indicating if all values of the vector are equal to 1.0.



26
27
# File 'lib/numerix/vector2.rb', line 26

def one?
end

#reflect(other) ⇒ Vector2

Alters this vector to be the reflection of the specified normal.

Parameters:

  • other (Vector2)

    The normal of the surface being reflected off.

Returns:

  • (Vector2)

    a newly created reflected vector.



327
328
# File 'lib/numerix/vector2.rb', line 327

def reflect(other)
end

#reflect!(other) ⇒ self

Returns the reflection of a vector off a surface that has the specified normal.

Parameters:

  • other (Vector2)

    The normal of the surface being reflected off.

Returns:

  • (self)


337
338
# File 'lib/numerix/vector2.rb', line 337

def reflect!(other)
end

#sqrtVector2

Returns a vector whose elements are the square root of each of this vector's elements.

Returns:

  • (Vector2)

    a vector whose elements are the square root of each of this vector's elements.



115
116
# File 'lib/numerix/vector2.rb', line 115

def sqrt
end

#to_aArray<Float> Also known as: elements

Returns an Array representation of this instance.

Returns:

  • (Array<Float>)

    an Array representation of this instance.



179
180
# File 'lib/numerix/vector2.rb', line 179

def to_a
end

#to_hHash{Symbol => Float}

Returns a Hash representation of this instance.

Returns:

  • (Hash{Symbol => Float})

    a Hash representation of this instance.



186
187
# File 'lib/numerix/vector2.rb', line 186

def to_h
end

#to_planePlane

Returns a Plane representation of this instance.

Returns:

  • (Plane)

    a Plane representation of this instance.



196
197
# File 'lib/numerix/vector2.rb', line 196

def to_plane
end

#to_quaternionQuaternion

Returns a Quaternion representation of this instance.

Returns:



191
192
# File 'lib/numerix/vector2.rb', line 191

def to_quaternion
end

#to_sString

Returns a String representation of this instance.

Returns:

  • (String)

    a String representation of this instance.



174
175
# File 'lib/numerix/vector2.rb', line 174

def to_s
end

#to_vec3Vector3

Returns a Numerix::Vector3 representation of this instance.

Returns:



201
202
# File 'lib/numerix/vector2.rb', line 201

def to_vec3
end

#to_vec4Vector4

Returns a Numerix::Vector4 representation of this instance.

Returns:



206
207
# File 'lib/numerix/vector2.rb', line 206

def to_vec4
end

#transform(matrix) ⇒ Vector2 #transform(matrix) ⇒ Vector2 #transform(rotation) ⇒ Vector2

Returns a new vector by applying a transformation.

Overloads:

  • #transform(matrix) ⇒ Vector2

    Transforms this vector by the given matrix.

    Parameters:

    • matrix (Matrix4x4)

      The transformation matrix.

  • #transform(matrix) ⇒ Vector2

    Transforms this vector by the given matrix.

    Parameters:

    • matrix (Matrix3x2)

      The transformation matrix.

  • #transform(rotation) ⇒ Vector2

    Transforms this vector by the specified rotation value.

    Parameters:

    • rotation (Quaternion)

      The rotation to apply.

Returns:

  • (Vector2)

    new transformed vector.

See Also:



379
380
# File 'lib/numerix/vector2.rb', line 379

def transform(other)
end

#transform(matrix) ⇒ self #transform(matrix) ⇒ self #transform(rotation) ⇒ self

Transforms this vector by the given matrix.

Overloads:

  • #transform(matrix) ⇒ self

    Transforms this vector by the given matrix.

    Parameters:

    • matrix (Matrix4x4)

      The transformation matrix.

  • #transform(matrix) ⇒ self

    Transforms this vector by the given matrix.

    Parameters:

    • matrix (Matrix3x2)

      The transformation matrix.

  • #transform(rotation) ⇒ self

    Transforms this vector by the specified rotation value.

    Parameters:

    • rotation (Quaternion)

      The rotation to apply.

Returns:

  • (self)

See Also:



403
404
# File 'lib/numerix/vector2.rb', line 403

def transform!(other)
end

#transform_normal(matrix) ⇒ Vector2

Transforms a vector normal by the given matrix.

Parameters:

Returns:

  • (Vector2)

    new transformed vector.



412
413
# File 'lib/numerix/vector2.rb', line 412

def transform_normal(matrix)
end

#transform_normal!(matrix) ⇒ self

Transforms a vector normal by the given matrix.

Parameters:

Returns:

  • (self)


421
422
# File 'lib/numerix/vector2.rb', line 421

def transform_normal!(matrix)
end

#zero?Boolean

Returns flag indicating if all values of the vector are equal to 0.0.

Returns:

  • (Boolean)

    flag indicating if all values of the vector are equal to 0.0.



32
33
# File 'lib/numerix/vector2.rb', line 32

def zero?
end