struct Chem::Spatial::Size3

Overview

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

Defined in:

chem/spatial/size3.cr

Constructors

Instance Method Summary

Constructor Detail

def self.[](x : Number, y : Number, z : Number) : self #

Returns a size with values x, y and z.


[View source]
def self.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.


[View source]
def self.zero : self #

Returns the zero size.


[View source]

Instance Method Detail

def *(rhs : Number) : self #

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


[View source]
def *(rhs : self) : self #

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


[View source]
def +(rhs : self) : self #

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


[View source]
def -(rhs : self) : self #

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

WARNING This will clamp negative values to zero.


[View source]
def /(rhs : Number) : self #

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


[View source]
def /(rhs : self) : self #

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


[View source]
def [](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

[View source]
def clamp(min : Number | Nil, max : Number | Nil) : self #

[View source]
def clamp(range : Range) : self #

[View source]
def 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

[View source]
def map(& : Float64 -> Float64) : self #

[View source]
def 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.

Size3[1, 2, 3].transform do |x, y, z|
  x *= 2
  z /= 0.3
  {x, y, z}
end # => Size3[2, 2, 10]

[View source]
def x : Float64 #

X component of the size.


[View source]
def y : Float64 #

Y component of the size.


[View source]
def z : Float64 #

Z component of the size.


[View source]