struct
Chem::Spatial::Size3
- Chem::Spatial::Size3
- Struct
- Value
- Object
Overview
A Size3 represents the size of an object in three-dimensional
space.
Defined in:
chem/spatial/size3.crConstructors
-
.[](x : Number, y : Number, z : Number) : self
Returns a size with values x, y and z.
-
.new(x : Float64, y : Float64, z : Float64)
Creates a size with values x, y and z.
-
.zero : self
Returns the zero size.
Instance Method Summary
-
#*(rhs : Number) : self
Returns the element-wise multiplication of the size by rhs.
-
#*(rhs : self) : self
Returns the element-wise multiplication of the size by rhs.
-
#+(rhs : self) : self
Returns the element-wise addition of the size by rhs.
-
#-(rhs : self) : self
Returns the element-wise subtraction of the size by rhs.
-
#/(rhs : Number) : self
Returns the element-wise division of the size by rhs.
-
#/(rhs : self) : self
Returns the element-wise division of the size by rhs.
-
#=~(other : self) : Bool
Returns
trueif the elements of the sizes are close to each other, elsefalse. -
#[](index : Int) : Float64
Returns the element at index in the XYZ order.
- #clamp(min : Number | Nil, max : Number | Nil) : self
- #clamp(range : Range) : self
-
#close_to?(rhs : self, delta : Number = Float64::EPSILON) : Bool
Returns
trueif the elements of the sizes are within delta from each other, elsefalse. - #map(& : Float64 -> Float64) : self
-
#transform(& : Float64, Float64, Float64 -> FloatTriple) : self
Returns a new size with the return value of the given block, which is invoked with the X, Y, and Z components.
-
#x : Float64
X component of the size.
-
#y : Float64
Y component of the size.
-
#z : Float64
Z component of the size.
Constructor Detail
Returns a size with values x, y and z.
Creates a size with values x, y and z. Raises
ArgumentError if x, y or z is negative.
Instance Method Detail
Returns the element-wise multiplication of the size by rhs.
Returns the element-wise multiplication of the size by rhs.
Returns the element-wise subtraction of the size by rhs.
WARNING This will clamp negative values to zero.
Returns true if the elements of the sizes are close to each
other, else false. See the #close_to? method.
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 sizes 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
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]