KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_shape_ellipse.cpp File Reference
#include <qa_utils/wx_utils/unit_test_utils.h>
#include <algorithm>
#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>
#include <geometry/circle.h>
#include <geometry/intersection.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.
 
static bool containsPointNear (const std::vector< VECTOR2I > &aPoints, const VECTOR2I &aExpected)
 
 BOOST_AUTO_TEST_CASE (IntersectEllipseWithEllipse)
 
 BOOST_AUTO_TEST_CASE (IntersectEllipseWithOffsetCircle)
 
 BOOST_AUTO_TEST_CASE (IntersectEllipseWithSegment)
 
 BOOST_AUTO_TEST_CASE (IntersectEllipseWithEllipticalArc)
 
 BOOST_AUTO_TEST_CASE (IntersectionVisitorHandlesEllipses)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/64]

◆ BOOST_AUTO_TEST_CASE() [2/64]

BOOST_AUTO_TEST_CASE ( CacheConsistencyAfterSetMajorRadius )

Test that the cache is consistent after SetMajorRadius.

Definition at line 1015 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/64]

BOOST_AUTO_TEST_CASE ( CacheConsistencyAfterSetRotation )

Test that the cache is consistent after SetRotation.

Definition at line 994 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/64]

BOOST_AUTO_TEST_CASE ( CirclePerimeterViaRamanujan )

Definition at line 226 of file test_shape_ellipse.cpp.

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

◆ BOOST_AUTO_TEST_CASE() [5/64]

BOOST_AUTO_TEST_CASE ( CollideCircleDegenerateAgreesWithShapeCircle )

◆ BOOST_AUTO_TEST_CASE() [6/64]

BOOST_AUTO_TEST_CASE ( CollideDegenerateSegmentAtCenter )

Definition at line 464 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [7/64]

BOOST_AUTO_TEST_CASE ( CollideDegenerateSegmentFarAway )

Definition at line 475 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [8/64]

BOOST_AUTO_TEST_CASE ( CollideEllipseInsideAnotherEllipse )

Definition at line 653 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [9/64]

BOOST_AUTO_TEST_CASE ( CollideEllipseInsideClosedChain )

Definition at line 607 of file test_shape_ellipse.cpp.

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

◆ BOOST_AUTO_TEST_CASE() [10/64]

BOOST_AUTO_TEST_CASE ( CollideEllipseVsArcOverlap )

Definition at line 623 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [11/64]

BOOST_AUTO_TEST_CASE ( CollideEllipseVsCircleDisjoint )

Definition at line 553 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [12/64]

BOOST_AUTO_TEST_CASE ( CollideEllipseVsCircleOverlap )

Definition at line 543 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [13/64]

BOOST_AUTO_TEST_CASE ( CollideEllipseVsEllipseDisjoint )

Definition at line 643 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [14/64]

BOOST_AUTO_TEST_CASE ( CollideEllipseVsEllipseOverlap )

Definition at line 633 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [15/64]

BOOST_AUTO_TEST_CASE ( CollideEllipseVsLineChainIntersects )

Definition at line 594 of file test_shape_ellipse.cpp.

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

◆ BOOST_AUTO_TEST_CASE() [16/64]

BOOST_AUTO_TEST_CASE ( CollideEllipseVsRect )

Definition at line 663 of file test_shape_ellipse.cpp.

References actual, ANGLE_0, and BOOST_CHECK_EQUAL().

◆ BOOST_AUTO_TEST_CASE() [17/64]

BOOST_AUTO_TEST_CASE ( CollideEllipseVsRectContainsEllipse )

Definition at line 563 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [18/64]

BOOST_AUTO_TEST_CASE ( CollideEllipseVsRectDisjoint )

Definition at line 574 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [19/64]

BOOST_AUTO_TEST_CASE ( CollideEllipseVsRectEdgeIntersects )

Definition at line 584 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [20/64]

BOOST_AUTO_TEST_CASE ( CollideSegmentEndpointInsideClosedEllipse )

◆ BOOST_AUTO_TEST_CASE() [21/64]

BOOST_AUTO_TEST_CASE ( CollideSegmentNearMissWithinClearance )

Definition at line 449 of file test_shape_ellipse.cpp.

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

◆ BOOST_AUTO_TEST_CASE() [22/64]

BOOST_AUTO_TEST_CASE ( CollideSegmentOutsideFar )

Definition at line 439 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [23/64]

BOOST_AUTO_TEST_CASE ( CollideSegmentThroughClosedEllipse )

◆ BOOST_AUTO_TEST_CASE() [24/64]

BOOST_AUTO_TEST_CASE ( CollideSegmentVsArcUpperHalf )

Definition at line 500 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [25/64]

BOOST_AUTO_TEST_CASE ( CollideSegmentVsRotatedEllipse )

Definition at line 485 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [26/64]

BOOST_AUTO_TEST_CASE ( ConstructorClampsDegenerate )

◆ BOOST_AUTO_TEST_CASE() [27/64]

BOOST_AUTO_TEST_CASE ( ConstructorSwapsMajorMinor )

◆ BOOST_AUTO_TEST_CASE() [28/64]

BOOST_AUTO_TEST_CASE ( ConvertToPolylineAllPointsWithinMaxError )

◆ BOOST_AUTO_TEST_CASE() [29/64]

BOOST_AUTO_TEST_CASE ( ConvertToPolylineArcIsOpenWithCorrectEndpoints )

Definition at line 367 of file test_shape_ellipse.cpp.

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

◆ BOOST_AUTO_TEST_CASE() [30/64]

BOOST_AUTO_TEST_CASE ( ConvertToPolylineClosedEllipseIsClosed )

Definition at line 356 of file test_shape_ellipse.cpp.

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

◆ BOOST_AUTO_TEST_CASE() [31/64]

BOOST_AUTO_TEST_CASE ( ConvertToPolylineTighterErrorYieldsMorePoints )

◆ BOOST_AUTO_TEST_CASE() [32/64]

BOOST_AUTO_TEST_CASE ( CrossCheckSegmentCollideAgainstTessellation )

◆ BOOST_AUTO_TEST_CASE() [33/64]

BOOST_AUTO_TEST_CASE ( EllipsePerimeterMatchesHighResIntegration )

Definition at line 236 of file test_shape_ellipse.cpp.

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

◆ BOOST_AUTO_TEST_CASE() [34/64]

BOOST_AUTO_TEST_CASE ( FormatContainsExpectedFields )

Definition at line 811 of file test_shape_ellipse.cpp.

References DEGREES_T, and SHAPE_ELLIPSE::Format().

◆ BOOST_AUTO_TEST_CASE() [35/64]

BOOST_AUTO_TEST_CASE ( FullSweepAngleInSweep )

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

Definition at line 978 of file test_shape_ellipse.cpp.

References SHAPE_ELLIPSE::Collide(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [36/64]

◆ BOOST_AUTO_TEST_CASE() [37/64]

BOOST_AUTO_TEST_CASE ( IntersectEllipseWithEllipse )

◆ BOOST_AUTO_TEST_CASE() [38/64]

BOOST_AUTO_TEST_CASE ( IntersectEllipseWithEllipticalArc )

◆ BOOST_AUTO_TEST_CASE() [39/64]

BOOST_AUTO_TEST_CASE ( IntersectEllipseWithOffsetCircle )

◆ BOOST_AUTO_TEST_CASE() [40/64]

BOOST_AUTO_TEST_CASE ( IntersectEllipseWithSegment )

Definition at line 1104 of file test_shape_ellipse.cpp.

References ANGLE_0, containsPointNear(), and SHAPE_ELLIPSE::Intersect().

◆ BOOST_AUTO_TEST_CASE() [41/64]

BOOST_AUTO_TEST_CASE ( IntersectionVisitorHandlesEllipses )

Definition at line 1131 of file test_shape_ellipse.cpp.

References ANGLE_0, ANGLE_90, BOOST_CHECK_EQUAL(), CIRCLE, and circle().

◆ BOOST_AUTO_TEST_CASE() [42/64]

BOOST_AUTO_TEST_CASE ( MirrorArcAsymmetricSwapsSweep )

◆ BOOST_AUTO_TEST_CASE() [43/64]

BOOST_AUTO_TEST_CASE ( MirrorArcSwapsAndReflectsSweep )

◆ BOOST_AUTO_TEST_CASE() [44/64]

◆ BOOST_AUTO_TEST_CASE() [45/64]

◆ BOOST_AUTO_TEST_CASE() [46/64]

◆ BOOST_AUTO_TEST_CASE() [47/64]

◆ BOOST_AUTO_TEST_CASE() [48/64]

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 936 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() [49/64]

BOOST_AUTO_TEST_CASE ( NormalizeClosedEllipseNoAngleShift )

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

Definition at line 963 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() [50/64]

BOOST_AUTO_TEST_CASE ( PointInsideAfterRotationChange )

Test PointInside after rotation change.

Test if cache is stale.

Definition at line 1034 of file test_shape_ellipse.cpp.

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

◆ BOOST_AUTO_TEST_CASE() [51/64]

BOOST_AUTO_TEST_CASE ( PointInsideArcAlwaysFalse )

Definition at line 312 of file test_shape_ellipse.cpp.

References DEGREES_T, and SHAPE_ELLIPSE::PointInside().

◆ BOOST_AUTO_TEST_CASE() [52/64]

BOOST_AUTO_TEST_CASE ( PointInsideClosedAxisAligned )

Definition at line 286 of file test_shape_ellipse.cpp.

References DEGREES_T, and SHAPE_ELLIPSE::PointInside().

◆ BOOST_AUTO_TEST_CASE() [53/64]

BOOST_AUTO_TEST_CASE ( PointInsideRotatedEllipse )

Definition at line 300 of file test_shape_ellipse.cpp.

References DEGREES_T, and SHAPE_ELLIPSE::PointInside().

◆ BOOST_AUTO_TEST_CASE() [54/64]

BOOST_AUTO_TEST_CASE ( QuarterCircleArcLength )

Definition at line 276 of file test_shape_ellipse.cpp.

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

◆ BOOST_AUTO_TEST_CASE() [55/64]

BOOST_AUTO_TEST_CASE ( RandomClosedEllipseBBoxVsBruteForce )

◆ BOOST_AUTO_TEST_CASE() [56/64]

◆ BOOST_AUTO_TEST_CASE() [57/64]

BOOST_AUTO_TEST_CASE ( RotateAboutNonCenterTranslatesAndRotates )

◆ BOOST_AUTO_TEST_CASE() [58/64]

◆ BOOST_AUTO_TEST_CASE() [59/64]

BOOST_AUTO_TEST_CASE ( RotateCircleAboutCenterIsBBoxInvariant )

◆ BOOST_AUTO_TEST_CASE() [60/64]

BOOST_AUTO_TEST_CASE ( RotatedEllipseBBoxAt45Degrees )

◆ BOOST_AUTO_TEST_CASE() [61/64]

BOOST_AUTO_TEST_CASE ( SemiCircleArcLength )

Definition at line 266 of file test_shape_ellipse.cpp.

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

◆ BOOST_AUTO_TEST_CASE() [62/64]

BOOST_AUTO_TEST_CASE ( SquaredDistanceCircleAgreesWithRadialDistance )

◆ BOOST_AUTO_TEST_CASE() [63/64]

BOOST_AUTO_TEST_CASE ( SquaredDistanceOutlineOnlyReturnsBoundaryDist )

Definition at line 344 of file test_shape_ellipse.cpp.

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

◆ BOOST_AUTO_TEST_CASE() [64/64]

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 45 of file test_shape_ellipse.cpp.

References bruteForceEllipseBBox(), and M_PI.

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

◆ containsPointNear()

static bool containsPointNear ( const std::vector< VECTOR2I > & aPoints,
const VECTOR2I & aExpected )
static