Chem::Spatial::Size3
Inherits Struct / Value / Object
A Size3 represents the size of an object in three-dimensional
space.
Constructors
new(x : Float64, y : Float64, z : Float64)
Creates a size with values x, y and z. Raises
ArgumentError if x, y or z is negative.
Instance methods
-(rhs : self) : self
Returns the element-wise substraction of the size by rhs.
WARNING: This will clamp negative values to zero.
[](index : Int) : Float64
Returns the element at index in the XYZ order. Raises
IndexError if index is out of bounds.
size = Size3[10, 15, 20]
size[0] # => 10
size[1] # => 15
size[2] # => 20
size[3] # raises IndexError
size[-1] # raises IndexError
Returns true if the elements of the size are within delta
from each other, else false.
Size3[1, 2, 3].close_to?(Size3[1, 2, 3]) # => true
Size3[1, 2, 3].close_to?(Size3[1.001, 1.999, 3.00004], 1e-3) # => true
Size3[1, 2, 3].close_to?(Size3[3, 2, 1]) # => false
Size3[1, 2, 3].close_to?(Size3[1.001, 1.999, 3.00004], 1e-8) # => false
map
Sourcetransform
Returns a new size with the return value of the given block, which is invoked with the X, Y, and Z components.
Size3[1, 2, 3].transform do |x, y, z|
x *= 2
z /= 0.3
{x, y, z}
end # => Size3[2, 2, 10]