mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-06 10:26:03 +08:00
refs #449 Implement SubdivisionConverters with less precision errors
This commit is contained in:
committed by
Mathew Sutcliffe
parent
e3b0720295
commit
2d9e9863c2
@@ -25,6 +25,7 @@
|
|||||||
#include <QSharedDataPointer>
|
#include <QSharedDataPointer>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
@@ -117,9 +118,11 @@ namespace BlackMisc
|
|||||||
virtual double fromDefault(double factor) const override
|
virtual double fromDefault(double factor) const override
|
||||||
{
|
{
|
||||||
using BlackMisc::Math::CMathUtils;
|
using BlackMisc::Math::CMathUtils;
|
||||||
factor /= FactorPolicy::factor();
|
double part1 = CMathUtils::trunc(factor / FactorPolicy::factor());
|
||||||
double part2 = CMathUtils::fract(factor) * SubdivPolicy::subfactor();
|
double remaining = std::fmod(factor, FactorPolicy::factor());
|
||||||
return CMathUtils::trunc(factor) + part2 / SubdivPolicy::fraction();
|
double part2 = CMathUtils::trunc(remaining / SubdivPolicy::subfactor());
|
||||||
|
remaining = std::fmod(remaining, SubdivPolicy::subfactor());
|
||||||
|
return part1 + (part2 + remaining) / SubdivPolicy::fraction();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -142,10 +145,13 @@ namespace BlackMisc
|
|||||||
virtual double fromDefault(double factor) const override
|
virtual double fromDefault(double factor) const override
|
||||||
{
|
{
|
||||||
using BlackMisc::Math::CMathUtils;
|
using BlackMisc::Math::CMathUtils;
|
||||||
factor /= FactorPolicy::factor();
|
double part1 = CMathUtils::trunc(factor / FactorPolicy::factor());
|
||||||
double part2 = CMathUtils::fract(factor) * SubdivPolicy::subfactor();
|
double remaining = std::fmod(factor, FactorPolicy::factor());
|
||||||
double part3 = CMathUtils::fract(part2) * SubdivPolicy::subfactor();
|
double part2 = CMathUtils::trunc(remaining / SubdivPolicy::subfactor());
|
||||||
return CMathUtils::trunc(factor) + (CMathUtils::trunc(part2) + part3 / SubdivPolicy::fraction()) / SubdivPolicy::fraction();
|
remaining = std::fmod(remaining, SubdivPolicy::subfactor());
|
||||||
|
double part3 = CMathUtils::trunc(remaining / SubdivPolicy::subfactor());
|
||||||
|
remaining = std::fmod(remaining, SubdivPolicy::subfactor());
|
||||||
|
return part1 + part2 / SubdivPolicy::fraction() + (part3 + remaining) / (SubdivPolicy::fraction() * SubdivPolicy::fraction());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user