struct

Chem::Spatial::Size3

Inherits Struct / Value / Object

A Size3 represents the size of an object in three-dimensional space.

Constructors

[](x : Number, y : Number, z : Number) : self

Returns a size with values x, y and z.

Source
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.

Source
zero

Returns the zero size.

Source

Instance methods

*(rhs : Number) : self

Returns the element-wise multiplication of the size by rhs.

Source
*(rhs : self) : self

Returns the element-wise multiplication of the size by rhs.

Source
+(rhs : self) : self

Returns the element-wise addition of the size by rhs.

Source
-(rhs : self) : self

Returns the element-wise substraction of the size by rhs.

WARNING: This will clamp negative values to zero.

Source
/(rhs : Number) : self

Returns the element-wise division of the size by rhs.

Source
/(rhs : self) : self

Returns the element-wise division of the size by rhs.

Source
[](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
Source
clamp(min : Number | Nil, max : Number | Nil) : self
Source
clamp(range : Range) : self
Source
close_to?(rhs : self, delta : Number = Float64::EPSILON) : Bool

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
Source
transform

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]
Source
x

X component of the size.

Source
y

Y component of the size.

Source
z

Z component of the size.

Source