Skip to content

Commit

Permalink
Fix compilation for real
Browse files Browse the repository at this point in the history
  • Loading branch information
lhog committed Dec 13, 2024
1 parent 7bf0c36 commit 2e76f84
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
13 changes: 13 additions & 0 deletions rts/System/float3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ CR_REG_METADATA(float3, (CR_MEMBER(x), CR_MEMBER(y), CR_MEMBER(z)))
float float3::maxxpos = -1.0f;
float float3::maxzpos = -1.0f;

float3 float3::PickNonParallel() const
{
// https://math.stackexchange.com/questions/3122010/how-to-deterministically-pick-a-vector-that-is-guaranteed-to-be-non-parallel-to
auto mi = std::min_element(std::begin(xyz), std::end(xyz), [](const auto& a, const auto& b) { return math::fabs(a) < math::fabs(b); });
auto Mi = std::max_element(std::begin(xyz), std::end(xyz), [](const auto& a, const auto& b) { return math::fabs(a) > math::fabs(b); });
float3 npVec{ 0.0f };
npVec.xyz[std::distance(std::begin(xyz), mi)] = *Mi;

// don't normalize as it most likely will go as argument to cross,
// and the cross result will need to be normalized anyway
return npVec;
}

bool float3::IsInBounds() const
{
assert(maxxpos > 0.0f); // check if initialized
Expand Down
12 changes: 1 addition & 11 deletions rts/System/float3.h
Original file line number Diff line number Diff line change
Expand Up @@ -752,17 +752,7 @@ class float3
*/

// deterministically pick a non-parallel vector to the current one
float3 PickNonParallel() const {
// https://math.stackexchange.com/questions/3122010/how-to-deterministically-pick-a-vector-that-is-guaranteed-to-be-non-parallel-to
auto mi = std::min_element(std::begin(xyz), std::end(xyz), [](const auto& a, const auto& b) { return math::fabs(a) < math::fabs(b); });
auto Mi = std::max_element(std::begin(xyz), std::end(xyz), [](const auto& a, const auto& b) { return math::fabs(a) > math::fabs(b); });
float3 npVec{ 0.0f };
npVec.xyz[std::distance(std::begin(xyz), mi)] = *Mi;

// don't normalize as it most likely will go as argument to cross,
// and the cross result will need to be normalized anyway
return npVec;
}
float3 PickNonParallel() const;

bool Normalized() const { return math::fabs(1.0f - SqLength()) <= cmp_eps(); }
static bool CheckNaN(float c) { return (!math::isnan(c) && !math::isinf(c)); }
Expand Down

0 comments on commit 2e76f84

Please sign in to comment.