KiCad PCB EDA Suite
|
#include <config.h>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <limits>
#include <typeinfo>
#include <type_traits>
Go to the source code of this file.
Functions | |
void | kimathLogDebug (const char *aFormatString,...) |
Helper to avoid directly including wx/log.h for the templated functions in kimath. | |
void | kimathLogOverflow (double v, const char *aTypeName) |
Workaround to avoid the empty-string conversion issue in wxWidgets. | |
template<typename in_type = long long int, typename ret_type = int> | |
constexpr ret_type | KiCheckedCast (in_type v) |
Perform a cast between numerical types. | |
template<typename fp_type , typename ret_type = int> | |
constexpr ret_type | KiROUND (fp_type v, bool aQuiet=false) |
Round a floating point number to an integer using "round halfway cases away from zero". | |
template<typename T > | |
T | rescale (T aNumerator, T aValue, T aDenominator) |
Scale a number (value) by rational (numerator/denominator). | |
template<typename T > | |
constexpr int | sign (T val) |
template<> | |
int | rescale (int aNumerator, int aValue, int aDenominator) |
template<> | |
int64_t | rescale (int64_t aNumerator, int64_t aValue, int64_t aDenominator) |
template<class T > | |
std::enable_if< std::is_floating_point< T >::value, bool >::type | equals (T aFirst, T aSecond, T aEpsilon=std::numeric_limits< T >::epsilon()) |
Template to compare two floating point values for equality within a required epsilon. | |
std::enable_if< std::is_floating_point< T >::value, bool >::type equals | ( | T | aFirst, |
T | aSecond, | ||
T | aEpsilon = std::numeric_limits<T>::epsilon() |
||
) |
Template to compare two floating point values for equality within a required epsilon.
aFirst | value to compare. |
aSecond | value to compare. |
aEpsilon | allowed error. |
Definition at line 182 of file util.h.
References std::abs().
|
inlineconstexpr |
Perform a cast between numerical types.
Will clamp the return value to numerical type limits.
In Debug build an assert fires if will not fit into the return type.
Definition at line 68 of file util.h.
References kimathLogOverflow(), and name.
void kimathLogDebug | ( | const char * | aFormatString, |
... | |||
) |
void kimathLogOverflow | ( | double | v, |
const char * | aTypeName | ||
) |
Workaround to avoid the empty-string conversion issue in wxWidgets.
Definition at line 58 of file util.cpp.
Referenced by KiCheckedCast(), and KiROUND().
|
constexpr |
Round a floating point number to an integer using "round halfway cases away from zero".
In Debug build an assert fires if will not fit into the return type.
Definition at line 100 of file util.h.
References kimathLogOverflow(), and name.
int rescale | ( | int | aNumerator, |
int | aValue, | ||
int | aDenominator | ||
) |
int64_t rescale | ( | int64_t | aNumerator, |
int64_t | aValue, | ||
int64_t | aDenominator | ||
) |
Definition at line 80 of file util.cpp.
References std::abs(), kimathLogDebug(), and sign().
T rescale | ( | T | aNumerator, |
T | aValue, | ||
T | aDenominator | ||
) |
Scale a number (value) by rational (numerator/denominator).
Numerator must be <= denominator.
Definition at line 153 of file util.h.
Referenced by BOOST_AUTO_TEST_CASE(), commonParallelProjection(), PNS::commonParallelProjection(), SEG::intersects(), SEG::LineDistance(), SEG::LineProject(), SEG::mutualDistanceSquared(), SEG::NearestPoint(), HALF_LINE::NearestPoint(), LINE::NearestPoint(), SHAPE_LINE_CHAIN_BASE::PointInside(), processEdge(), processHole(), SEG::ReflectPoint(), VECTOR2< T >::Resize(), SCH_IO_LTSPICE_PARSER::ToKicadCoords(), and SCH_IO_LTSPICE_PARSER::ToLtSpiceCoords().
|
constexpr |
Definition at line 159 of file util.h.
Referenced by BuildCornersList_S_Shape(), PNS::DP_GATEWAYS::BuildFromPrimitivePair(), DIRECTION_45::BuildInitialTrace(), KIGFX::SCH_PAINTER::draw(), CADSTAR_SCH_ARCHIVE_LOADER::getKiCadLength(), CADSTAR_SCH_ARCHIVE_LOADER::Load(), PCB_IO_EAGLE::orientFPText(), SCH_MOVE_TOOL::orthoLineDrag(), PCB_IO_EAGLE::packageText(), PLOTTER::polyArc(), rescale(), VECTOR2< T >::Resize(), TransformRoundChamferedRectToPolygon(), PCB_DIM_ALIGNED::updateGeometry(), PCB_DIM_ORTHOGONAL::updateGeometry(), PCB_POINT_EDITOR::updateItem(), EE_POINT_EDITOR::updateParentItem(), and PCB_DIM_ALIGNED::updateText().