File tree Expand file tree Collapse file tree 4 files changed +43
-8
lines changed Expand file tree Collapse file tree 4 files changed +43
-8
lines changed Original file line number Diff line number Diff line change @@ -535,6 +535,26 @@ namespace p
535
535
}
536
536
#pragma endregion Sort
537
537
538
+ #pragma region Transformations
539
+ template <typename T, typename Index>
540
+ void Normalize (T* first, Index size)
541
+ {
542
+ T magnitude = {};
543
+ for (Index i = 0 ; i < size; ++i)
544
+ {
545
+ const T& value = first[i];
546
+ magnitude += value * value;
547
+ }
548
+ if (magnitude > T (0 ))
549
+ {
550
+ const T invMagnitude = InvSqrt (magnitude);
551
+ for (Index i = 0 ; i < size; ++i)
552
+ {
553
+ first[i] *= invMagnitude;
554
+ }
555
+ }
556
+ }
557
+ #pragma endregion Transformations
538
558
539
559
/* * Generates CRC hash of the memory area */
540
560
PIPE_API u32 MemCrc32 (const void * Data, i32 Length, u32 CRC = 0 );
Original file line number Diff line number Diff line change @@ -841,17 +841,20 @@ namespace p
841
841
new (Super::data + firstIdx) Type (value);
842
842
return firstIdx;
843
843
}
844
- Type& AddRef ()
844
+ inline Type& AddRef ()
845
845
{
846
- return Super::data[Add ()];
846
+ const i32 idx = Add ();
847
+ return Super::data[idx];
847
848
}
848
- Type& AddRef (Type&& value)
849
+ inline Type& AddRef (Type&& value)
849
850
{
850
- return Super::data[Add (p::Forward<Type>(value))];
851
+ const i32 idx = Add (p::Forward<Type>(value));
852
+ return Super::data[idx];
851
853
}
852
- Type& AddRef (const Type& value)
854
+ inline Type& AddRef (const Type& value)
853
855
{
854
- return Super::data[Add (value)];
856
+ const i32 idx = Add (value);
857
+ return Super::data[idx];
855
858
}
856
859
857
860
template <typename SortPredicate = TLess<Type>>
Original file line number Diff line number Diff line change @@ -259,6 +259,18 @@ namespace p
259
259
{
260
260
return 1 .f / Sqrt (x);
261
261
}
262
+ inline PIPE_API double InvSqrt (double x)
263
+ {
264
+ return 1 . / Sqrt (x);
265
+ }
266
+ inline PIPE_API float InvSqrt (i32 x)
267
+ {
268
+ return 1 .f / Sqrt (x);
269
+ }
270
+ inline PIPE_API double InvSqrt (i64 x)
271
+ {
272
+ return 1 . / Sqrt (x);
273
+ }
262
274
263
275
template <typename T>
264
276
static constexpr T Square (T val)
Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ namespace p
85
85
const T lengthSquared = LengthSquared ();
86
86
if (lengthSquared > 0 .f )
87
87
{
88
- const float scale = InvSqrt (lengthSquared);
88
+ const auto scale = InvSqrt (lengthSquared);
89
89
x *= scale;
90
90
y *= scale;
91
91
}
@@ -365,7 +365,7 @@ namespace p
365
365
const T lengthSqrt = LengthSquared ();
366
366
if (lengthSqrt > 0 .f )
367
367
{
368
- const float scale = InvSqrt (lengthSqrt);
368
+ const auto scale = InvSqrt (lengthSqrt);
369
369
x *= scale;
370
370
y *= scale;
371
371
z *= scale;
You can’t perform that action at this time.
0 commit comments