Skip to content

Commit 953ee8f

Browse files
authored
CUDA: Add more math functions (#4793)
1 parent f289673 commit 953ee8f

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

source/MRCuda/MRCudaFloat.cuh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ __device__ inline float lengthSq( const float2& a )
5454
return a.x * a.x + a.y * a.y;
5555
}
5656

57+
__device__ inline float length( const float2& a )
58+
{
59+
return sqrt( a.x * a.x + a.y * a.y );
60+
}
61+
5762
__device__ inline float dot( const float2& a, const float2& b )
5863
{
5964
return a.x * b.x + a.y * b.y;

source/MRCuda/MRCudaMath.cuh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ struct Box3
3131
float3 min;
3232
float3 max;
3333

34+
__device__ bool valid() const
35+
{
36+
return min.x <= max.x && min.y <= max.y && min.z <= max.z;
37+
}
38+
3439
__device__ float3 getBoxClosestPointTo( const float3& pt ) const
3540
{
3641
return { clamp( pt.x, min.x, max.x ), clamp( pt.y, min.y, max.y ), clamp( pt.z, min.z, max.z ) };
@@ -46,6 +51,18 @@ struct Box3
4651
if ( pt.z > max.z ) max.z = pt.z;
4752
}
4853

54+
__device__ Box3 intersection( const Box3& b ) const
55+
{
56+
Box3 res;
57+
res.min.x = fmax( min.x, b.min.x );
58+
res.min.y = fmax( min.y, b.min.y );
59+
res.min.z = fmax( min.z, b.min.z );
60+
res.max.x = fmin( max.x, b.max.x );
61+
res.max.y = fmin( max.y, b.max.y );
62+
res.max.z = fmin( max.z, b.max.z );
63+
return res;
64+
}
65+
4966
__device__ float3 operator[]( const int i ) const
5067
{
5168
assert( i == 0 || i == 1 );

0 commit comments

Comments
 (0)