Skip to content

Commit

Permalink
Allow subscripted mutations of Gf.Matrix4d, etc Gf.
Browse files Browse the repository at this point in the history
- Ensures subscripted access to Gf.Matrix4d mutates each row and column
  correctly. Each row and column is represented as Gf.Vec4d.
- Extends inlined Gf math methods to support Gf.Vec3d, eventually will
  autogenerate implementations for other types using Swift macros.
- Fixes for properly marking methods as @inlinable.

Signed-off-by: furby™ <devs@wabi.foundation>
  • Loading branch information
furby-tm committed Jan 1, 2025
1 parent 23a1291 commit 838f01a
Show file tree
Hide file tree
Showing 8 changed files with 446 additions and 74 deletions.
68 changes: 34 additions & 34 deletions Sources/PixarUSD/Base/Gf/MathInline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public extension Gf
/// - Parameter epsilon: The tolerance to use.
///
/// - Returns: `true` if the values are within **epsilon** of each other.
@inline(__always)
@inlinable
static func isClose(_ a: Double, _ b: Double, within epsilon: Double) -> Bool
{
Pixar.GfIsClose(a, b, epsilon)
Expand All @@ -30,7 +30,7 @@ public extension Gf
/// - Parameter radians: The angle in radians.
///
/// - Returns: The angle in degrees.
@inline(__always)
@inlinable
static func radiansToDegrees(angle radians: Double) -> Double
{
Pixar.GfRadiansToDegrees(radians)
Expand All @@ -40,7 +40,7 @@ public extension Gf
/// - Parameter radians: The angle in degrees.
///
/// - Returns: The angle in radians.
@inline(__always)
@inlinable
static func degreesToRadians(angle degrees: Double) -> Double
{
Pixar.GfDegreesToRadians(degrees)
Expand All @@ -50,209 +50,209 @@ public extension Gf

/// Returns the inner product of **x** with itself: specifically, `x * x`.
/// Defined for **Int**, **Float**, **Double**, and all **GfVec** types.
@inline(__always)
@inlinable
static func sqr(_ x: Int) -> Double
{
Pixar.GfSqr(x)
}

/// Returns the inner product of **x** with itself: specifically, `x * x`.
/// Defined for **Int**, **Float**, **Double**, and all **GfVec** types.
@inline(__always)
@inlinable
static func sqr(_ x: Float) -> Double
{
Pixar.GfSqr(x)
}

/// Returns the inner product of **x** with itself: specifically, `x * x`.
/// Defined for **Int**, **Float**, **Double**, and all **GfVec** types.
@inline(__always)
@inlinable
static func sqr(_ x: Double) -> Double
{
Pixar.GfSqr(x)
}

/// Returns the inner product of **x** with itself: specifically, `x * x`.
/// Defined for **Int**, **Float**, **Double**, and all **GfVec** types.
@inline(__always)
@inlinable
static func sqr(_ x: GfVec2f) -> Double
{
Pixar.GfSqr(x)
}

/// Returns the inner product of **x** with itself: specifically, `x * x`.
/// Defined for **Int**, **Float**, **Double**, and all **GfVec** types.
@inline(__always)
@inlinable
static func sqr(_ x: GfVec3f) -> Double
{
Pixar.GfSqr(x)
}

/// Return sqrt(f).
@inline(__always)
@inlinable
static func sqrt(_ f: Double) -> Double
{
Pixar.GfSqrt(f)
}

/// Return sqrt(f).
@inline(__always)
@inlinable
static func sqrt(_ f: Float) -> Float
{
Pixar.GfSqrt(f)
}

/// Return exp(f).
@inline(__always)
@inlinable
static func exp(_ f: Double) -> Double
{
Pixar.GfExp(f)
}

/// Return exp(f).
@inline(__always)
@inlinable
static func exp(_ f: Float) -> Float
{
Pixar.GfExp(f)
}

/// Return log(f).
@inline(__always)
@inlinable
static func log(_ f: Double) -> Double
{
Pixar.GfLog(f)
}

/// Return log(f).
@inline(__always)
@inlinable
static func log(_ f: Float) -> Float
{
Pixar.GfLog(f)
}

/// Return floor(f).
@inline(__always)
@inlinable
static func floor(_ f: Double) -> Double
{
Pixar.GfFloor(f)
}

/// Return floor(f).
@inline(__always)
@inlinable
static func floor(_ f: Float) -> Float
{
Pixar.GfFloor(f)
}

/// Return ceil(f).
@inline(__always)
@inlinable
static func ceil(_ f: Double) -> Double
{
Pixar.GfCeil(f)
}

/// Return ceil(f).
@inline(__always)
@inlinable
static func ceil(_ f: Float) -> Float
{
Pixar.GfCeil(f)
}

/// Return abs(f).
@inline(__always)
@inlinable
static func abs(_ f: Double) -> Double
{
Pixar.GfAbs(f)
}

/// Return abs(f).
@inline(__always)
@inlinable
static func abs(_ f: Float) -> Float
{
Pixar.GfAbs(f)
}

/// Return round(f).
@inline(__always)
@inlinable
static func round(_ f: Double) -> Double
{
Pixar.GfRound(f)
}

/// Return round(f).
@inline(__always)
@inlinable
static func round(_ f: Float) -> Float
{
Pixar.GfRound(f)
}

/// Return pow(f, p).
@inline(__always)
@inlinable
static func pow(_ f: Double, _ p: Double) -> Double
{
Pixar.GfPow(f, p)
}

/// Return pow(f, p).
@inline(__always)
@inlinable
static func pow(_ f: Float, _ p: Float) -> Float
{
Pixar.GfPow(f, p)
}

/// Return sin(v).
@inline(__always)
@inlinable
static func sin(_ v: Double) -> Double
{
Pixar.GfSin(v)
}

/// Return sin(v).
@inline(__always)
@inlinable
static func sin(_ v: Float) -> Float
{
Pixar.GfSin(v)
}

/// Return cos(v).
@inline(__always)
@inlinable
static func cos(_ v: Double) -> Double
{
Pixar.GfCos(v)
}

/// Return cos(v).
@inline(__always)
@inlinable
static func cos(_ v: Float) -> Float
{
Pixar.GfCos(v)
}

/// Return sin(v) in s and cos(v) in c.
@inline(__always)
@inlinable
static func sinCos(_ v: Double, _ s: inout Double, _ c: inout Double)
{
Pixar.GfSinCos(v, &s, &c)
}

/// Return sin(v) in s and cos(v) in c.
@inline(__always)
@inlinable
static func sinCos(_ v: Float, _ s: inout Float, _ c: inout Float)
{
Pixar.GfSinCos(v, &s, &c)
}

/// Return the resulting of clamping value to lie between
/// min and max. This function is also defined for GfVecs.
@inline(__always)
@inlinable
static func clamp(_ value: Double, _ min: Double, _ max: Double) -> Double
{
Pixar.GfClamp(value, min, max)
}

/// Return the resulting of clamping value to lie between
/// min and max. This function is also defined for GfVecs.
@inline(__always)
@inlinable
static func clamp(_ value: Float, _ min: Float, _ max: Float) -> Float
{
Pixar.GfClamp(value, min, max)
Expand All @@ -263,7 +263,7 @@ public extension Gf
/// If a = `n b` for some integer n, zero is returned.
/// Otherwise, for positive a, the value returned is `fmod(a,b)`,
/// and for negative `a`, the value returned is `fmod(a,b) + b`.
@inline(__always)
@inlinable
static func mod(_ a: Double, _ b: Double) -> Double
{
Pixar.GfMod(a, b)
Expand All @@ -274,7 +274,7 @@ public extension Gf
/// If a = `n b` for some integer n, zero is returned.
/// Otherwise, for positive a, the value returned is `fmod(a,b)`,
/// and for negative `a`, the value returned is `fmod(a,b) + b`.
@inline(__always)
@inlinable
static func mod(_ a: Float, _ b: Float) -> Float
{
Pixar.GfMod(a, b)
Expand Down
Loading

0 comments on commit 838f01a

Please sign in to comment.