Basic functionality of Coordinate class. Can be replaced by C extension. This file should not be loaded directly, but via coordinate.rb

class Coordinate

*   +   +@   -   -@   /   ==   =~   Coordinate.epsilon   Coordinate.epsilon=   Coordinate.new   []   []=   abs   absolute   angle   angle_deg   collect   cross_product   deep_copy   dist   distance   dot   dot_product   dup   each   each_index   inspect   map   map!   minus!   normalize   normalize!   plus!   r   self.[]   self.from_array   self.from_coordinate   set_coord   to_a   to_coordinate   to_s   x=   y=   z=  

Coordinate.new(x = 0.0, y = 0.0, z = 0.0) # => Coordinate

Creates new Coordinate from three values, ommited arguments are set to zero

Initializators

self.[](*array) # => Coordinate

Creates new Coordinate using array notation (without brackets)

c = Coordinate[1.0, 0.0, 0.0]

self.from_array(array) # => Coordinate

Creates new coordinate from array of three floats

c1 = Coordinate([1.0, 0.0, 0.0])
c2 = Coordinate(some_array)

self.from_coordinate(coordinate) # => Coordinate

Write to components

Following three methods provide write to the coordinate elements with type checking.

x=(value) # => Float (value written)

y=(value) # => Float (value written)

z=(value) # => Float (value written)

Basics

deep_copy # => Coordinate

Creates real copy of the object

dup # => Coordinate

Creates real copy of the object

set_coord(coordinate) # => nil

Sets the coordinate (its elements) from other object

Element access

[](index) # => Float

Returns selected element

c = Coordinate[1.0, 2.0, 3.0]
c[2]
=> 3.0

[]=(index,value) # => Float (value written)

Write to element selected by index

c = Coordinate[0.0, 0.0, 0.0]
c[0] = 1.0
c
=> Coordinate: [1.0, 0.0, 0.0]

Type conversion

to_s # => String

Conversion to string

Coordinate[1.0, 2.0, 3.0].to_s
=> "Coordinate: [1.0, 2.0, 3.0]"

inspect # => String

Equal to to_s with prepended newline for nice irb output.

to_a # => Array of Floats

Converts Coordinate to Array

Coordinate[1.0, 2.0, 3.0].to_a
=> [1.0, 2.0, 3.0]

to_coordinate # => Coordinate

Allows conversion of descendants to Coordinate

Iterators

each_index # => nil

Iterate over indexes

each # => nil

Iterate over elements

collect # => Coordinate

Iterate over elements, results of the block are returned as new Coordinate

map # => Coordinate

Synonym for collect

map! # => nil

Iterate over elements, result of the block replaces original value of element

Unary operators

+@ # => self

Unary plus. Does nothing.

-@ # => Coordinate

Unary minus. Returns deep copy with all x,y,z multiplied by -1.0

Operators: coordinate - coordinate

+(coordinate) # => Coordinate

Coordinate addition

-(coordinate) # => Coordinate

Coordinate subtraction

plus!(coordinate) # => nil

In-place coordinate addition, faster than using a = a + b

minus!(coordinate) # => nil

In-place coordinate subtraction, faster than using a = a - b

dot_product(coordinate) # => Float

Dot product

dot(coordinate) # => Float

Dot product, synonym for dot_product

cross_product(coordinate) # => Coordinate

Cross product

Operators: coordinate - something else

*(operand) # => Coordinate | Float (Coordinate * Coordinate)

Multiplication operator, allows Coordinate * Numeric or Coordinate, returns dot product for Coordinate * Coordinate.

/(operand) # => Coordinate

Division of coordinate by number (Numeric)

Comparison

== (coordinate) # => true | false

=~ (coordinate) # => true | false

Loose comparison, difference between each pair of elements must be smaller than class variable epsilon.

Coordinate.epsilon=(value) # => Float (value written)

Sets threshold for loose comparison (class variable epsilon)

Coordinate.epsilon # => Float

Reads threshold for loose comparison (class variable epsilon)

Misc

absolute # => Float

abs # => Float

Synonym for absolute

r # => Float

Synonym for absolute

normalize # => Coordinate

Returns normalized vector

normalize! # => nil

In-place version of normalize

distance(coordinate) # => Float

Distance between two points specified by coordinates

dist(coordinate) # => Float

Synonym for distance

angle(coordinate) # => Float

Angle between two 3D vectors in space (in radians)

angle_deg(coordinate) # => Float

Angle between two 3D vectors in space (in degrees)