Sign in

    KKKIIO/selene/math does not have a README file

    Affine3

    pub(all) struct Affine3 {
    x_axis : Vec3
    y_axis : Vec3
    z_axis : Vec3
    translation : Vec3
    } derive(Eq,
    Debug
    )

    impl Default for Affine3
    impl Mul for Affine3

    Affine3::from_scale_rotation_translation

    fn Affine3::from_scale_rotation_translation(scale : Vec3, rotation : Quat, translation : Vec3) -> Affine3

    Affine3::identity

    fn Affine3::identity() -> Affine3

    Affine3::inverse

    fn Affine3::inverse(self : Affine3) -> Affine3?

    Affine3::mul

    fn Affine3::mul(self : Affine3, other : Affine3) -> Affine3

    Affine3::transform_point3

    fn Affine3::transform_point3(self : Affine3, value : Vec3) -> Vec3

    Affine3::transform_vector3

    fn Affine3::transform_vector3(self : Affine3, value : Vec3) -> Vec3

    Axis

    pub(all) enum Axis {
    X
    Y
    } derive(Eq,
    Debug
    )

    Coordinate axis in 2D space.

    Constructors:

    • X : The horizontal axis
    • Y : The vertical axis

    HAlign

    pub(all) enum HAlign {
    Left
    Center
    Right
    } derive(Eq,
    Debug
    )

    Mat4

    pub(all) struct Mat4 {
    m00 : Double
    m01 : Double
    m02 : Double
    m03 : Double
    m10 : Double
    m11 : Double
    m12 : Double
    m13 : Double
    m20 : Double
    m21 : Double
    m22 : Double
    m23 : Double
    m30 : Double
    m31 : Double
    m32 : Double
    m33 : Double
    } derive(Eq,
    Debug
    )

    impl Default for Mat4

    Mat4::from_trs

    fn Mat4::from_trs(translation : Vec3, rotation : Quat, scale : Vec3) -> Mat4

    Mat4::identity

    fn Mat4::identity() -> Mat4

    Mat4::mul

    fn Mat4::mul(self : Mat4, other : Mat4) -> Mat4

    Mat4::transform_point

    fn Mat4::transform_point(self : Mat4, point : Vec3) -> Vec3

    Quat

    pub(all) struct Quat {
    x : Double
    y : Double
    z : Double
    w : Double
    } derive(Eq,
    Debug
    )

    impl Default for Quat
    impl Mul for Quat

    Quat::Quat

    fn Quat::Quat(x : Double, y : Double, z : Double, w : Double) -> Quat

    Quat::conjugate

    fn Quat::conjugate(self : Quat) -> Quat

    Quat::dot

    fn Quat::dot(self : Quat, other : Quat) -> Double

    Quat::from_axis_angle

    fn Quat::from_axis_angle(axis : Vec3, radians : Double) -> Quat

    Quat::from_basis

    fn Quat::from_basis(x_axis : Vec3, y_axis : Vec3, z_axis : Vec3) -> Quat

    Quat::identity

    fn Quat::identity() -> Quat

    Quat::inverse

    fn Quat::inverse(self : Quat) -> Quat

    Quat::length_squared

    fn Quat::length_squared(self : Quat) -> Double

    Quat::multiply

    fn Quat::multiply(self : Quat, other : Quat) -> Quat

    Quat::nlerp

    fn Quat::nlerp(self : Quat, other : Quat, alpha : Double) -> Quat

    Quat::normalize

    fn Quat::normalize(self : Quat) -> Quat

    Quat::rotate_vec3

    fn Quat::rotate_vec3(self : Quat, vec : Vec3) -> Vec3

    Quat::to_rapier

    Rect

    pub(all) struct Rect {
    position : Vec2
    size : Vec2
    } derive(Eq, Hash,
    Debug
    )

    The Rect struct represents a rectangle defined by its position and size.

    Rect::intersects

    fn Rect::intersects(a : Rect, b : Rect) -> Bool

    Check if two rectangles intersect

    Rect::shift

    fn Rect::shift(self : Rect, dir : Vec2) -> Rect

    Shift the rectangle by a given vector.

    RepeatMode

    pub(all) enum RepeatMode {
    RepeatX
    RepeatY
    NoRepeat
    Repeat
    }

    Mode controlling texture repetition behavior along axes.

    Constructors:

    • RepeatX : Repeat texture horizontally only
    • RepeatY : Repeat texture vertically only
    • NoRepeat : No repetition in either direction
    • Repeat : Repeat texture in both directions

    Transform

    pub(all) struct Transform {
    a : Double
    b : Double
    c : Double
    d : Double
    tx : Double
    ty : Double
    }

    2D transformation matrix represented as: [a c tx] [b d ty] [0 0 1 ] where (tx, ty) is translation, and the 2x2 matrix handles rotation/scale/skew

    impl Mul for Transform

    Transform::Transform

    fn Transform::Transform(a? : Double, b? : Double, c? : Double, d? : Double, tx? : Double, ty? : Double) -> Transform

    Create transform from matrix components

    Transform::append

    fn Transform::append(self : Transform, other : Transform) -> Transform

    Append a transform (self * other).

    This means other is applied before self in point space.

    Transform::append_rotation_deg

    fn Transform::append_rotation_deg(self : Transform, deg : Double) -> Transform

    Append rotation in degrees.

    Transform::append_rotation_rad

    fn Transform::append_rotation_rad(self : Transform, rad : Double) -> Transform

    Append rotation (self * R).

    Transform::append_scale

    fn Transform::append_scale(self : Transform, sx : Double, sy : Double) -> Transform

    Append scale (self * S).

    Transform::append_skew

    fn Transform::append_skew(self : Transform, kx : Double, ky : Double) -> Transform

    Append skew (self * K).

    Transform::append_translation

    fn Transform::append_translation(self : Transform, tx : Double, ty : Double) -> Transform

    Append translation (self * T).

    Transform::apply_to_point

    fn Transform::apply_to_point(self : Transform, x : Double, y : Double) -> (Double, Double)

    Apply transform to a point

    Transform::apply_to_vec2

    fn Transform::apply_to_vec2(self : Transform, vec : Vec2) -> Vec2

    Transform::clone

    fn Transform::clone(self : Transform) -> Transform

    Creates a deep copy of the transform.

    Parameters:

    • self : The transform to clone.

    Returns a new Transform instance with identical matrix values.

    Transform::compose

    fn Transform::compose(self : Transform, other : Transform) -> Transform

    Compose two transforms in left-to-right order (self * other). This is equivalent to multiply.

    Transform::flip_x

    fn Transform::flip_x(width : Double) -> Transform

    Flip transform horizontally

    Transform::flip_y

    fn Transform::flip_y(height : Double) -> Transform

    Flip transform vertically

    Transform::from_rotation_deg

    fn Transform::from_rotation_deg(deg : Double) -> Transform

    Create rotation transform (degrees)

    Transform::from_rotation_rad

    fn Transform::from_rotation_rad(rad : Double) -> Transform

    Create rotation transform (radians)

    Transform::from_scale

    fn Transform::from_scale(sx : Double, sy : Double) -> Transform

    Create scale transform

    Transform::from_skew

    fn Transform::from_skew(kx : Double, ky : Double) -> Transform

    Create skew transform

    Transform::from_translation

    fn Transform::from_translation(tx : Double, ty : Double) -> Transform

    Create translation transform

    Transform::get_rotation_rad

    fn Transform::get_rotation_rad(self : Transform) -> Double

    Get rotation angle in radians

    Transform::get_scale

    fn Transform::get_scale(self : Transform) -> (Double, Double)

    Get scale values (ignoring rotation)

    Transform::get_translation

    fn Transform::get_translation(self : Transform) -> (Double, Double)

    Get translation values

    Transform::identity

    fn Transform::identity() -> Transform

    Create identity transform

    Transform::inverse

    fn Transform::inverse(self : Transform) -> Transform?

    Calculate inverse transform

    Transform::multiply

    fn Transform::multiply(self : Transform, other : Transform) -> Transform

    Multiply two transforms (this * other)

    Transform::prepend

    fn Transform::prepend(self : Transform, other : Transform) -> Transform

    Prepend a transform (other * self).

    This means other is applied after self in point space.

    Transform::prepend_rotation_deg

    fn Transform::prepend_rotation_deg(self : Transform, deg : Double) -> Transform

    Prepend rotation in degrees.

    Transform::prepend_rotation_rad

    fn Transform::prepend_rotation_rad(self : Transform, rad : Double) -> Transform

    Prepend rotation (R * self).

    Transform::prepend_scale

    fn Transform::prepend_scale(self : Transform, sx : Double, sy : Double) -> Transform

    Prepend scale (S * self).

    Transform::prepend_skew

    fn Transform::prepend_skew(self : Transform, kx : Double, ky : Double) -> Transform

    Prepend skew (K * self).

    Transform::prepend_translation

    fn Transform::prepend_translation(self : Transform, tx : Double, ty : Double) -> Transform

    Prepend translation (T * self).

    Transform::set_translation

    fn Transform::set_translation(self : Transform, tx : Double, ty : Double) -> Transform

    Alias of with_translation.

    Transform::with_translation

    fn Transform::with_translation(self : Transform, tx : Double, ty : Double) -> Transform

    Return a new transform with updated translation, keeping linear terms.

    VAlign

    pub(all) enum VAlign {
    Top
    Center
    Bottom
    } derive(Eq,
    Debug
    )

    Vec2

    pub(all) struct Vec2(Double, Double) derive(Eq, Hash,
    Debug
    )

    2D vector with x and y components.

    Fields:

    • 0 : The x component of the vector.
    • 1 : The y component of the vector.

    Example:

    let v1 = @math.Vec2(3.0, 4.0)
    let v2 = @math.Vec2::zero()
    inspect(v1[X], content="3")
    inspect(v1[Y], content="4")
    inspect(v2[X], content="0")
    inspect(v2[Y], content="0")

    impl Add for Vec2
    impl Default for Vec2
    impl Mul for Vec2
    impl Neg for Vec2
    impl Sub for Vec2

    Vec2::clone

    fn Vec2::clone(self : Vec2) -> Vec2

    Vec2::distance

    fn Vec2::distance(this : Vec2) -> Double

    Calculates the magnitude (length) of the vector.

    Parameters:

    • this : The vector to calculate the magnitude for.

    Returns the magnitude of the vector as a Double value.

    Example:

    let v = @math.Vec2(3.0, 4.0)
    inspect(v.distance(), content="5") // sqrt(3² + 4²) = 5

    Vec2::distance_to

    fn Vec2::distance_to(this : Vec2, other : Vec2) -> Double

    Calculates the Euclidean distance between this vector and another vector.

    Parameters:

    • this : The first vector (starting point).
    • other : The second vector (ending point).

    Returns the Euclidean distance between the two vectors as a Double.

    Example:

    let v1 = @math.Vec2(0.0, 0.0)
    let v2 = @math.Vec2(3.0, 4.0)
    inspect(v1.distance_to(v2), content="5")

    Vec2::dot

    fn Vec2::dot(this : Vec2, other : Vec2) -> Double

    Calculates the dot product of two 2D vectors.

    Parameters:

    • this : The first vector.
    • other : The second vector.

    Returns the dot product as a Double value.

    Example:

    let v1 = @math.Vec2(3.0, 4.0)
    let v2 = @math.Vec2(2.0, 1.0)
    inspect(v1.dot(v2), content="10") // 3*2 + 4*1 = 10

    Vec2::normalize

    fn Vec2::normalize(this : Vec2) -> Vec2

    Normalizes the vector to a unit vector with magnitude 1.

    Parameters:

    • this : The vector to normalize.

    Returns a new Vec2 representing the unit vector in the same direction as the original vector. If the original vector has zero magnitude, returns a zero vector Vec2(0.0, 0.0).

    Example:

    let v = @math.Vec2(3.0, 4.0)
    let normalized = v.normalize()
    inspect(normalized.distance(), content="1") // Unit vector has magnitude 1

    Vec2::op_get

    fn Vec2::op_get(this : Vec2, axis : Axis) -> Double

    Vec2::scalar_div

    fn Vec2::scalar_div(this : Vec2, scalar : Double) -> Vec2

    Vec2::scalar_mul

    fn Vec2::scalar_mul(this : Vec2, scalar : Double) -> Vec2

    Vec2::update

    fn Vec2::update(this : Vec2, axis : Axis, value : Double) -> Vec2

    Creates a new vector with the specified component updated to a new value.

    Parameters:

    • this : The original vector to update.
    • axis : The coordinate axis to update (X for horizontal, Y for vertical).
    • value : The new value to set for the specified axis.

    Returns a new Vec2 with the specified component updated while keeping the other component unchanged.

    Example:

    let v = @math.Vec2(3.0, 4.0)
    let updated_x = v.update(X, 10.0)
    let updated_y = v.update(Y, 20.0)
    inspect(updated_x, content="Vec2(10, 4)")
    inspect(updated_y, content="Vec2(3, 20)")

    Vec2::zero

    fn Vec2::zero() -> Vec2

    Vec3

    pub(all) struct Vec3 {
    x : Double
    y : Double
    z : Double
    } derive(Eq,
    Debug
    )

    impl Add for Vec3
    impl Default for Vec3
    impl Mul for Vec3
    impl Neg for Vec3
    impl Sub for Vec3

    Vec3::Vec3

    fn Vec3::Vec3(x : Double, y : Double, z : Double) -> Vec3

    Vec3::cross

    fn Vec3::cross(self : Vec3, other : Vec3) -> Vec3

    Vec3::dot

    fn Vec3::dot(self : Vec3, other : Vec3) -> Double

    Vec3::length

    fn Vec3::length(self : Vec3) -> Double

    Vec3::length_squared

    fn Vec3::length_squared(self : Vec3) -> Double

    Vec3::lerp

    fn Vec3::lerp(self : Vec3, other : Vec3, alpha : Double) -> Vec3

    Vec3::normalize

    fn Vec3::normalize(self : Vec3) -> Vec3

    Vec3::one

    fn Vec3::one() -> Vec3

    Vec3::scalar_div

    fn Vec3::scalar_div(self : Vec3, scalar : Double) -> Vec3

    Vec3::scalar_mul

    fn Vec3::scalar_mul(self : Vec3, scalar : Double) -> Vec3

    Vec3::to_rapier

    Vec3::x_axis

    fn Vec3::x_axis() -> Vec3

    Vec3::y_axis

    fn Vec3::y_axis() -> Vec3

    Vec3::z_axis

    fn Vec3::z_axis() -> Vec3

    Vec3::zero

    fn Vec3::zero() -> Vec3

    normalize_angle

    fn normalize_angle(angle : Double) -> Double

    Normalizes an angle to the range [0, 2PI) radians.

    Parameters:

    • angle : The angle in radians to normalize.

    Returns the normalized angle in the range [0, 2PI) radians.

    Example:

    // Positive angle greater than 2PI
    inspect(@cmath.normalize_angle(7.0), content="0.7168146928204138")

    // Negative angle
    inspect(@cmath.normalize_angle(-1.0), content="5.283185307179586")

    // Angle already in range
    inspect(@cmath.normalize_angle(1.5), content="1.5")

    quat_from_rapier

    fn quat_from_rapier(value :
    Quat
    ) -> Quat

    vec3_from_rapier

    fn vec3_from_rapier(value :
    Vec3
    ) -> Vec3