mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-15 02:37:51 -06:00
Integrate scaling and unscaling into Point.hpp
This commit is contained in:
parent
89d376dc35
commit
8c04536514
4 changed files with 104 additions and 228 deletions
|
@ -288,6 +288,72 @@ private:
|
|||
|
||||
std::ostream& operator<<(std::ostream &stm, const Vec2d &pointf);
|
||||
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// Type safe conversions to and from scaled and unscaled coordinates
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Semantics are the following:
|
||||
// Upscaling (scaled()): only from floating point types (or Vec) to either
|
||||
// floating point or integer 'scaled coord' coordinates.
|
||||
// Downscaling (unscaled()): from arithmetic (or Vec) to floating point only
|
||||
|
||||
// Conversion definition from unscaled to floating point scaled
|
||||
template<class Tout,
|
||||
class Tin,
|
||||
class = FloatingOnly<Tin>>
|
||||
inline constexpr FloatingOnly<Tout> scaled(const Tin &v) noexcept
|
||||
{
|
||||
return Tout(v / Tin(SCALING_FACTOR));
|
||||
}
|
||||
|
||||
// Conversion definition from unscaled to integer 'scaled coord'.
|
||||
// TODO: is the rounding necessary? Here it is commented out to show that
|
||||
// it can be different for integers but it does not have to be. Using
|
||||
// std::round means loosing noexcept and constexpr modifiers
|
||||
template<class Tout = coord_t, class Tin, class = FloatingOnly<Tin>>
|
||||
inline constexpr ScaledCoordOnly<Tout> scaled(const Tin &v) noexcept
|
||||
{
|
||||
//return static_cast<Tout>(std::round(v / SCALING_FACTOR));
|
||||
return Tout(v / Tin(SCALING_FACTOR));
|
||||
}
|
||||
|
||||
// Conversion for Eigen vectors (N dimensional points)
|
||||
template<class Tout = coord_t,
|
||||
class Tin,
|
||||
int N,
|
||||
class = FloatingOnly<Tin>,
|
||||
int...EigenArgs>
|
||||
inline Eigen::Matrix<ArithmeticOnly<Tout>, N, EigenArgs...>
|
||||
scaled(const Eigen::Matrix<Tin, N, EigenArgs...> &v)
|
||||
{
|
||||
return (v / SCALING_FACTOR).template cast<Tout>();
|
||||
}
|
||||
|
||||
// Conversion from arithmetic scaled type to floating point unscaled
|
||||
template<class Tout = double,
|
||||
class Tin,
|
||||
class = ArithmeticOnly<Tin>,
|
||||
class = FloatingOnly<Tout>>
|
||||
inline constexpr Tout unscaled(const Tin &v) noexcept
|
||||
{
|
||||
return Tout(v * Tout(SCALING_FACTOR));
|
||||
}
|
||||
|
||||
// Unscaling for Eigen vectors. Input base type can be arithmetic, output base
|
||||
// type can only be floating point.
|
||||
template<class Tout = double,
|
||||
class Tin,
|
||||
int N,
|
||||
class = ArithmeticOnly<Tin>,
|
||||
class = FloatingOnly<Tout>,
|
||||
int...EigenArgs>
|
||||
inline constexpr Eigen::Matrix<Tout, N, EigenArgs...>
|
||||
unscaled(const Eigen::Matrix<Tin, N, EigenArgs...> &v) noexcept
|
||||
{
|
||||
return v.template cast<Tout>() * SCALING_FACTOR;
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
|
||||
// start Boost
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue