KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_shape_ellipse.cpp File Reference
#include <qa_utils/wx_utils/unit_test_utils.h>
#include <cmath>
#include <limits>
#include <chrono>
#include <random>
#include <stdexcept>
#include <geometry/eda_angle.h>
#include <geometry/shape_ellipse.h>
#include <geometry/shape_line_chain.h>
#include <geometry/shape_circle.h>
#include <geometry/shape_rect.h>
#include <geometry/shape_arc.h>

Go to the source code of this file.

Functions

static BOX2I bruteForceEllipseBBox (const VECTOR2I &aCenter, int aMajorR, int aMinorR, const EDA_ANGLE &aRotation, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aEndAngle, bool aIsArc, int aNSamples=10000)
 Compute a bounding box by sampling 10,000 points around the ellipse Used as ground truth to verify BBox() implementation.
 
 BOOST_AUTO_TEST_CASE (ConstructorSwapsMajorMinor)
 
 BOOST_AUTO_TEST_CASE (ConstructorClampsDegenerate)
 
 BOOST_AUTO_TEST_CASE (AxisAlignedEllipseBBox)
 
 BOOST_AUTO_TEST_CASE (RotatedEllipseBBoxAt45Degrees)
 
 BOOST_AUTO_TEST_CASE (RandomClosedEllipseBBoxVsBruteForce)
 
 BOOST_AUTO_TEST_CASE (RandomEllipticalArcBBoxVsBruteForce)
 
 BOOST_AUTO_TEST_CASE (CirclePerimeterViaRamanujan)
 
 BOOST_AUTO_TEST_CASE (EllipsePerimeterMatchesHighResIntegration)
 
 BOOST_AUTO_TEST_CASE (SemiCircleArcLength)
 
 BOOST_AUTO_TEST_CASE (QuarterCircleArcLength)
 
 BOOST_AUTO_TEST_CASE (PointInsideClosedAxisAligned)
 
 BOOST_AUTO_TEST_CASE (PointInsideRotatedEllipse)
 
 BOOST_AUTO_TEST_CASE (PointInsideArcAlwaysFalse)
 
 BOOST_AUTO_TEST_CASE (SquaredDistanceCircleAgreesWithRadialDistance)
 
 BOOST_AUTO_TEST_CASE (SquaredDistanceZeroInsideClosedEllipse)
 
 BOOST_AUTO_TEST_CASE (SquaredDistanceOutlineOnlyReturnsBoundaryDist)
 
 BOOST_AUTO_TEST_CASE (ConvertToPolylineClosedEllipseIsClosed)
 
 BOOST_AUTO_TEST_CASE (ConvertToPolylineArcIsOpenWithCorrectEndpoints)
 
 BOOST_AUTO_TEST_CASE (ConvertToPolylineAllPointsWithinMaxError)
 
 BOOST_AUTO_TEST_CASE (ConvertToPolylineTighterErrorYieldsMorePoints)
 
 BOOST_AUTO_TEST_CASE (CollideSegmentThroughClosedEllipse)
 
 BOOST_AUTO_TEST_CASE (CollideSegmentEndpointInsideClosedEllipse)
 
 BOOST_AUTO_TEST_CASE (CollideSegmentOutsideFar)
 
 BOOST_AUTO_TEST_CASE (CollideSegmentNearMissWithinClearance)
 
 BOOST_AUTO_TEST_CASE (CollideDegenerateSegmentAtCenter)
 
 BOOST_AUTO_TEST_CASE (CollideDegenerateSegmentFarAway)
 
 BOOST_AUTO_TEST_CASE (CollideSegmentVsRotatedEllipse)
 
 BOOST_AUTO_TEST_CASE (CollideSegmentVsArcUpperHalf)
 
 BOOST_AUTO_TEST_CASE (CollideCircleDegenerateAgreesWithShapeCircle)
 
 BOOST_AUTO_TEST_CASE (CollideEllipseVsCircleOverlap)
 
 BOOST_AUTO_TEST_CASE (CollideEllipseVsCircleDisjoint)
 
 BOOST_AUTO_TEST_CASE (CollideEllipseVsRectContainsEllipse)
 
 BOOST_AUTO_TEST_CASE (CollideEllipseVsRectDisjoint)
 
 BOOST_AUTO_TEST_CASE (CollideEllipseVsRectEdgeIntersects)
 
 BOOST_AUTO_TEST_CASE (CollideEllipseVsLineChainIntersects)
 
 BOOST_AUTO_TEST_CASE (CollideEllipseInsideClosedChain)
 
 BOOST_AUTO_TEST_CASE (CollideEllipseVsArcOverlap)
 
 BOOST_AUTO_TEST_CASE (CollideEllipseVsEllipseOverlap)
 
 BOOST_AUTO_TEST_CASE (CollideEllipseVsEllipseDisjoint)
 
 BOOST_AUTO_TEST_CASE (CollideEllipseInsideAnotherEllipse)
 
 BOOST_AUTO_TEST_CASE (CollideEllipseVsRect)
 
 BOOST_AUTO_TEST_CASE (RotateByFullTurnPreservesBBox)
 
 BOOST_AUTO_TEST_CASE (RotateCircleAboutCenterIsBBoxInvariant)
 
 BOOST_AUTO_TEST_CASE (RotateAboutNonCenterTranslatesAndRotates)
 
 BOOST_AUTO_TEST_CASE (MirrorLeftRightFlipsCenter)
 
 BOOST_AUTO_TEST_CASE (MirrorTopBottomFlipsCenter)
 
 BOOST_AUTO_TEST_CASE (MirrorLeftRightTwiceIsIdentity)
 
 BOOST_AUTO_TEST_CASE (MirrorTopBottomTwiceIsIdentity)
 
 BOOST_AUTO_TEST_CASE (MirrorArcSwapsAndReflectsSweep)
 
 BOOST_AUTO_TEST_CASE (MirrorArcAsymmetricSwapsSweep)
 
 BOOST_AUTO_TEST_CASE (FormatContainsExpectedFields)
 
 BOOST_AUTO_TEST_CASE (FuzzRandomEllipsesInvariantsAndDeterminism)
 
 BOOST_AUTO_TEST_CASE (CrossCheckSegmentCollideAgainstTessellation)
 
 BOOST_AUTO_TEST_CASE (NormalizeArcAnglesOnSwap)
 Test that normalize() adjusts arc angles when swapping major/minor radii.
 
 BOOST_AUTO_TEST_CASE (NormalizeClosedEllipseNoAngleShift)
 Test that normalize() does NOT adjust angles for closed ellipses (only arcs).
 
 BOOST_AUTO_TEST_CASE (FullSweepAngleInSweep)
 Test that isAngleInSweep handles full-sweep (start=0, end=360) correctly.
 
 BOOST_AUTO_TEST_CASE (CacheConsistencyAfterSetRotation)
 Test that the cache is consistent after SetRotation.
 
 BOOST_AUTO_TEST_CASE (CacheConsistencyAfterSetMajorRadius)
 Test that the cache is consistent after SetMajorRadius.
 
 BOOST_AUTO_TEST_CASE (PointInsideAfterRotationChange)
 Test PointInside after rotation change.
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/59]

◆ BOOST_AUTO_TEST_CASE() [2/59]

BOOST_AUTO_TEST_CASE ( CacheConsistencyAfterSetMajorRadius )

Test that the cache is consistent after SetMajorRadius.

Definition at line 1016 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::BBox(), BOOST_CHECK_EQUAL(), DEGREES_T, BOX2< Vec >::GetHeight(), BOX2< Vec >::GetWidth(), and SHAPE_ELLIPSE::SetMajorRadius().

◆ BOOST_AUTO_TEST_CASE() [3/59]

BOOST_AUTO_TEST_CASE ( CacheConsistencyAfterSetRotation )

Test that the cache is consistent after SetRotation.

Definition at line 995 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::BBox(), BOOST_CHECK_EQUAL(), DEGREES_T, BOX2< Vec >::GetHeight(), BOX2< Vec >::GetWidth(), and SHAPE_ELLIPSE::SetRotation().

◆ BOOST_AUTO_TEST_CASE() [4/59]

BOOST_AUTO_TEST_CASE ( CirclePerimeterViaRamanujan )

Definition at line 227 of file test_shape_ellipse.cpp.

References DEGREES_T, SHAPE_ELLIPSE::GetLength(), and M_PI.

◆ BOOST_AUTO_TEST_CASE() [5/59]

BOOST_AUTO_TEST_CASE ( CollideCircleDegenerateAgreesWithShapeCircle )

◆ BOOST_AUTO_TEST_CASE() [6/59]

BOOST_AUTO_TEST_CASE ( CollideDegenerateSegmentAtCenter )

Definition at line 465 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [7/59]

BOOST_AUTO_TEST_CASE ( CollideDegenerateSegmentFarAway )

Definition at line 476 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [8/59]

BOOST_AUTO_TEST_CASE ( CollideEllipseInsideAnotherEllipse )

Definition at line 654 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [9/59]

BOOST_AUTO_TEST_CASE ( CollideEllipseInsideClosedChain )

Definition at line 608 of file test_shape_ellipse.cpp.

References chain, SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [10/59]

BOOST_AUTO_TEST_CASE ( CollideEllipseVsArcOverlap )

Definition at line 624 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [11/59]

BOOST_AUTO_TEST_CASE ( CollideEllipseVsCircleDisjoint )

Definition at line 554 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [12/59]

BOOST_AUTO_TEST_CASE ( CollideEllipseVsCircleOverlap )

Definition at line 544 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [13/59]

BOOST_AUTO_TEST_CASE ( CollideEllipseVsEllipseDisjoint )

Definition at line 644 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [14/59]

BOOST_AUTO_TEST_CASE ( CollideEllipseVsEllipseOverlap )

Definition at line 634 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [15/59]

BOOST_AUTO_TEST_CASE ( CollideEllipseVsLineChainIntersects )

Definition at line 595 of file test_shape_ellipse.cpp.

References chain, SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [16/59]

BOOST_AUTO_TEST_CASE ( CollideEllipseVsRect )

Definition at line 664 of file test_shape_ellipse.cpp.

References actual, ANGLE_0, and BOOST_CHECK_EQUAL().

◆ BOOST_AUTO_TEST_CASE() [17/59]

BOOST_AUTO_TEST_CASE ( CollideEllipseVsRectContainsEllipse )

Definition at line 564 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [18/59]

BOOST_AUTO_TEST_CASE ( CollideEllipseVsRectDisjoint )

Definition at line 575 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [19/59]

BOOST_AUTO_TEST_CASE ( CollideEllipseVsRectEdgeIntersects )

Definition at line 585 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [20/59]

BOOST_AUTO_TEST_CASE ( CollideSegmentEndpointInsideClosedEllipse )

◆ BOOST_AUTO_TEST_CASE() [21/59]

BOOST_AUTO_TEST_CASE ( CollideSegmentNearMissWithinClearance )

Definition at line 450 of file test_shape_ellipse.cpp.

References std::abs(), actual, SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [22/59]

BOOST_AUTO_TEST_CASE ( CollideSegmentOutsideFar )

Definition at line 440 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [23/59]

BOOST_AUTO_TEST_CASE ( CollideSegmentThroughClosedEllipse )

◆ BOOST_AUTO_TEST_CASE() [24/59]

BOOST_AUTO_TEST_CASE ( CollideSegmentVsArcUpperHalf )

Definition at line 501 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [25/59]

BOOST_AUTO_TEST_CASE ( CollideSegmentVsRotatedEllipse )

Definition at line 486 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [26/59]

BOOST_AUTO_TEST_CASE ( ConstructorClampsDegenerate )

◆ BOOST_AUTO_TEST_CASE() [27/59]

BOOST_AUTO_TEST_CASE ( ConstructorSwapsMajorMinor )

◆ BOOST_AUTO_TEST_CASE() [28/59]

BOOST_AUTO_TEST_CASE ( ConvertToPolylineAllPointsWithinMaxError )

◆ BOOST_AUTO_TEST_CASE() [29/59]

BOOST_AUTO_TEST_CASE ( ConvertToPolylineArcIsOpenWithCorrectEndpoints )

Definition at line 368 of file test_shape_ellipse.cpp.

References chain, SHAPE_ELLIPSE::ConvertToPolyline(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [30/59]

BOOST_AUTO_TEST_CASE ( ConvertToPolylineClosedEllipseIsClosed )

Definition at line 357 of file test_shape_ellipse.cpp.

References chain, SHAPE_ELLIPSE::ConvertToPolyline(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [31/59]

BOOST_AUTO_TEST_CASE ( ConvertToPolylineTighterErrorYieldsMorePoints )

◆ BOOST_AUTO_TEST_CASE() [32/59]

BOOST_AUTO_TEST_CASE ( CrossCheckSegmentCollideAgainstTessellation )

◆ BOOST_AUTO_TEST_CASE() [33/59]

BOOST_AUTO_TEST_CASE ( EllipsePerimeterMatchesHighResIntegration )

Definition at line 237 of file test_shape_ellipse.cpp.

References DEGREES_T, SHAPE_ELLIPSE::GetLength(), M_PI, and N.

◆ BOOST_AUTO_TEST_CASE() [34/59]

BOOST_AUTO_TEST_CASE ( FormatContainsExpectedFields )

Definition at line 812 of file test_shape_ellipse.cpp.

References DEGREES_T, and SHAPE_ELLIPSE::Format().

◆ BOOST_AUTO_TEST_CASE() [35/59]

BOOST_AUTO_TEST_CASE ( FullSweepAngleInSweep )

Test that isAngleInSweep handles full-sweep (start=0, end=360) correctly.

Definition at line 979 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [36/59]

◆ BOOST_AUTO_TEST_CASE() [37/59]

BOOST_AUTO_TEST_CASE ( MirrorArcAsymmetricSwapsSweep )

◆ BOOST_AUTO_TEST_CASE() [38/59]

BOOST_AUTO_TEST_CASE ( MirrorArcSwapsAndReflectsSweep )

◆ BOOST_AUTO_TEST_CASE() [39/59]

◆ BOOST_AUTO_TEST_CASE() [40/59]

◆ BOOST_AUTO_TEST_CASE() [41/59]

◆ BOOST_AUTO_TEST_CASE() [42/59]

◆ BOOST_AUTO_TEST_CASE() [43/59]

BOOST_AUTO_TEST_CASE ( NormalizeArcAnglesOnSwap )

Test that normalize() adjusts arc angles when swapping major/minor radii.

When minor > major, radii swap and rotation += 90. For arcs, angles must shift by -90 to keep the same physical arc.

Definition at line 937 of file test_shape_ellipse.cpp.

References EDA_ANGLE::AsDegrees(), BOOST_CHECK_EQUAL(), DEGREES_T, SHAPE_ELLIPSE::GetEndAngle(), SHAPE_ELLIPSE::GetMajorRadius(), SHAPE_ELLIPSE::GetMinorRadius(), SHAPE_ELLIPSE::GetRotation(), and SHAPE_ELLIPSE::GetStartAngle().

◆ BOOST_AUTO_TEST_CASE() [44/59]

BOOST_AUTO_TEST_CASE ( NormalizeClosedEllipseNoAngleShift )

Test that normalize() does NOT adjust angles for closed ellipses (only arcs).

Definition at line 964 of file test_shape_ellipse.cpp.

References EDA_ANGLE::AsDegrees(), BOOST_CHECK_EQUAL(), DEGREES_T, SHAPE_ELLIPSE::GetMajorRadius(), SHAPE_ELLIPSE::GetMinorRadius(), SHAPE_ELLIPSE::GetRotation(), and SHAPE_ELLIPSE::IsArc().

◆ BOOST_AUTO_TEST_CASE() [45/59]

BOOST_AUTO_TEST_CASE ( PointInsideAfterRotationChange )

Test PointInside after rotation change.

Test if cache is stale.

Definition at line 1035 of file test_shape_ellipse.cpp.

References DEGREES_T, SHAPE_ELLIPSE::PointInside(), and SHAPE_ELLIPSE::SetRotation().

◆ BOOST_AUTO_TEST_CASE() [46/59]

BOOST_AUTO_TEST_CASE ( PointInsideArcAlwaysFalse )

Definition at line 313 of file test_shape_ellipse.cpp.

References DEGREES_T, and SHAPE_ELLIPSE::PointInside().

◆ BOOST_AUTO_TEST_CASE() [47/59]

BOOST_AUTO_TEST_CASE ( PointInsideClosedAxisAligned )

Definition at line 287 of file test_shape_ellipse.cpp.

References DEGREES_T, and SHAPE_ELLIPSE::PointInside().

◆ BOOST_AUTO_TEST_CASE() [48/59]

BOOST_AUTO_TEST_CASE ( PointInsideRotatedEllipse )

Definition at line 301 of file test_shape_ellipse.cpp.

References DEGREES_T, and SHAPE_ELLIPSE::PointInside().

◆ BOOST_AUTO_TEST_CASE() [49/59]

BOOST_AUTO_TEST_CASE ( QuarterCircleArcLength )

Definition at line 277 of file test_shape_ellipse.cpp.

References DEGREES_T, SHAPE_ELLIPSE::GetLength(), and M_PI.

◆ BOOST_AUTO_TEST_CASE() [50/59]

BOOST_AUTO_TEST_CASE ( RandomClosedEllipseBBoxVsBruteForce )

◆ BOOST_AUTO_TEST_CASE() [51/59]

◆ BOOST_AUTO_TEST_CASE() [52/59]

BOOST_AUTO_TEST_CASE ( RotateAboutNonCenterTranslatesAndRotates )

◆ BOOST_AUTO_TEST_CASE() [53/59]

◆ BOOST_AUTO_TEST_CASE() [54/59]

BOOST_AUTO_TEST_CASE ( RotateCircleAboutCenterIsBBoxInvariant )

◆ BOOST_AUTO_TEST_CASE() [55/59]

BOOST_AUTO_TEST_CASE ( RotatedEllipseBBoxAt45Degrees )

◆ BOOST_AUTO_TEST_CASE() [56/59]

BOOST_AUTO_TEST_CASE ( SemiCircleArcLength )

Definition at line 267 of file test_shape_ellipse.cpp.

References DEGREES_T, SHAPE_ELLIPSE::GetLength(), and M_PI.

◆ BOOST_AUTO_TEST_CASE() [57/59]

BOOST_AUTO_TEST_CASE ( SquaredDistanceCircleAgreesWithRadialDistance )

◆ BOOST_AUTO_TEST_CASE() [58/59]

BOOST_AUTO_TEST_CASE ( SquaredDistanceOutlineOnlyReturnsBoundaryDist )

Definition at line 345 of file test_shape_ellipse.cpp.

References std::abs(), DEGREES_T, and SHAPE_ELLIPSE::SquaredDistance().

◆ BOOST_AUTO_TEST_CASE() [59/59]

BOOST_AUTO_TEST_CASE ( SquaredDistanceZeroInsideClosedEllipse )

◆ bruteForceEllipseBBox()

static BOX2I bruteForceEllipseBBox ( const VECTOR2I & aCenter,
int aMajorR,
int aMinorR,
const EDA_ANGLE & aRotation,
const EDA_ANGLE & aStartAngle,
const EDA_ANGLE & aEndAngle,
bool aIsArc,
int aNSamples = 10000 )
static

Compute a bounding box by sampling 10,000 points around the ellipse Used as ground truth to verify BBox() implementation.

Definition at line 46 of file test_shape_ellipse.cpp.

References bruteForceEllipseBBox(), and M_PI.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and bruteForceEllipseBBox().