|
KiCad PCB EDA Suite
|
#include <config.h>#include <cassert>#include <cmath>#include <cstdint>#include <limits>#include <typeinfo>#include <type_traits>#include <utility>#include <algorithm>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 numeric value to an integer using "round halfway cases away from zero" and clamp the result to the limits of the return type. | |
| 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<typename T> | |
| constexpr T | ct_sqrt_helper (T aX, T aLo, T aHi) |
| template<typename T> | |
| constexpr T | ct_sqrt (T aX) |
| Floor of the square root of an integer, evaluated at compile time. | |
| template<typename T> | |
| T | isqrt (T aX) |
| Exact floor of the square root of an integer. | |
| constexpr uint64_t | UnsignedAbs (int64_t aX) |
| Magnitude of a signed integer, well defined for INT64_MIN. | |
| uint64_t | RoundedHypotWide (uint64_t aX, uint64_t aY) |
| Nearest integer to sqrt( aX^2 + aY^2 ) for magnitudes of at most 2^63, using 128-bit arithmetic. | |
| uint64_t | RoundedHypot (int64_t aX, int64_t aY) |
| Nearest integer to sqrt( aX^2 + aY^2 ), computed exactly. | |
| 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. | |
Floor of the square root of an integer, evaluated at compile time.
Definition at line 197 of file util.h.
References ct_sqrt_helper(), and T.
Referenced by isqrt(), RoundedHypot(), and VECTOR2< T >::SquaredEuclideanNorm().
Definition at line 180 of file util.h.
References ct_sqrt_helper(), and T.
Referenced by ct_sqrt(), and ct_sqrt_helper().
| 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 276 of file util.h.
References std::abs(), and T.
Exact floor of the square root of an integer.
Negative input returns the largest root representable in T.
Definition at line 206 of file util.h.
Referenced by SEG::Collide(), SEG::Distance(), SEG::Distance(), SEG::LineDistance(), and RoundedHypot().
|
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 66 of file util.h.
References kimathLogOverflow(), and name.
Referenced by BOX2< VECTOR2I >::BOX2(), BOX2< VECTOR2I >::Centre(), BOX2< VECTOR2I >::GetBottom(), BOX2< VECTOR2I >::GetRight(), BOX2< VECTOR2I >::inflateAxis(), BOX2< VECTOR2I >::Intersects(), and BOX2< VECTOR2I >::Normalize().
| 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 55 of file util.cpp.
Referenced by KiCheckedCast(), and KiROUND().
|
constexpr |
Round a numeric value to an integer using "round halfway cases away from zero" and clamp the result to the limits of the return type.
In Debug build an assert fires if will not fit into the return type.
Definition at line 99 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 96 of file util.cpp.
References std::abs(), kimathLogDebug(), result, and sign().
Scale a number (value) by rational (numerator/denominator).
Numerator must be <= denominator.
Definition at line 160 of file util.h.
References T.
Referenced by BOOST_AUTO_TEST_CASE(), SEG::checkCollinearOverlap(), commonParallelProjection(), PNS::commonParallelProjection(), POLY_YSTRIPES_INDEX::Contains(), fractureIntersectX(), SEG::intersects(), SEG::LineDistance(), SEG::LineProject(), SEG::mutualDistanceSquared(), HALF_LINE::NearestPoint(), LINE::NearestPoint(), SEG::NearestPoint(), SHAPE_LINE_CHAIN::PointInside(), SHAPE_LINE_CHAIN_BASE::PointInside(), processEdge(), SEG::ReflectPoint(), VECTOR2< T >::Resize(), SCH_IO_LTSPICE_PARSER::ToKicadCoords(), and SCH_IO_LTSPICE_PARSER::ToLtSpiceCoords().
|
inline |
Nearest integer to sqrt( aX^2 + aY^2 ), computed exactly.
Ties cannot occur for integer input.
Definition at line 247 of file util.h.
References ct_sqrt(), isqrt(), RoundedHypotWide(), and UnsignedAbs().
Referenced by VECTOR2< T >::EuclideanNorm().
| uint64_t RoundedHypotWide | ( | uint64_t | aX, |
| uint64_t | aY ) |
Nearest integer to sqrt( aX^2 + aY^2 ) for magnitudes of at most 2^63, using 128-bit arithmetic.
Definition at line 62 of file util.cpp.
Referenced by RoundedHypot().
Definition at line 166 of file util.h.
References T.
Referenced by KIGFX::PREVIEW::ARC_GEOM_MANAGER::acceptExactPoint(), SCH_IO_GEDA::addBusEntries(), BOOST_AUTO_TEST_CASE(), BOARD_CONSTRAINT_ADAPTER::Build(), BuildCornersList_S_Shape(), PNS::DP_GATEWAYS::BuildFromPrimitivePair(), DIRECTION_45::BuildInitialTrace(), SCH_CONNECTIVITY::LIBRARY_SHAPE_FACT::Compare(), PNS::MULTI_DRAGGER::Drag(), KIGFX::SCH_PAINTER::draw(), CADSTAR_SCH_ARCHIVE_LOADER::getKiCadLength(), CADSTAR_SCH_ARCHIVE_LOADER::Load(), SCH_MOVE_TOOL::orthoLineDrag(), MARGIN_OFFSET_BINDER::parseInput(), PLOTTER::polyArc(), rescale(), VECTOR2< T >::Resize(), SHAPE_POLY_SET::splitSelfTouchingOutlines(), TransformRoundChamferedRectToPolygon(), PCB_DIM_ALIGNED::updateGeometry(), PCB_DIM_ORTHOGONAL::updateGeometry(), BITMAP_POINT_EDIT_BEHAVIOR::UpdateItem(), REFERENCE_IMAGE_POINT_EDIT_BEHAVIOR::UpdateItem(), and PCB_DIM_ALIGNED::updateText().
|
constexpr |
Magnitude of a signed integer, well defined for INT64_MIN.
Definition at line 234 of file util.h.
Referenced by RoundedHypot(), and VECTOR2< T >::SquaredEuclideanNorm().