88 Commits

Author SHA1 Message Date
John Beard
1e272ca21b Geom: use SHAPE_SEGMENT for OVAL
OVAL didn't do anything SHAPE_SEGMENT couldn't already do.
2025-09-02 17:38:26 +08:00
Seth Hillbrand
8acf5c1a25 ADDED: Rounded Rectangles
Fixes https://gitlab.com/kicad/code/kicad/-/issues/4742
2025-08-29 17:37:30 -07:00
Seth Hillbrand
408e1feae2 Fix Chessboard splitting
Due to a bug(?) in Clipper2, 45° collinear edges may not be detected.
See https://github.com/AngusJohnson/Clipper2/issues/1008 for current
status.  In the meantime, we pre-process these to remove the extraneous
joints preventing our triangulation from getting mixed up

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18176
2025-08-27 15:00:58 -07:00
John Beard
9173d11398 Very minor Coverity fixes 2025-08-20 01:41:18 +08:00
Seth Hillbrand
b207ec8817 Remove negative index access from CPoint
Callers should be responsible for index count and/or use iterators
2025-08-08 10:46:45 -07:00
Seth Hillbrand
dd889ddac9 Add Tesselation QA tests 2025-08-04 22:20:42 -07:00
Seth Hillbrand
2aeecec9bd Remove Creepage generation from reporting
Recalculating creepeage every time we reported a new clearance error was
unneccesarily complex.  Since the clearance errors are always straight
lines, we just need to calculate the closest approach and present that
segment
2025-07-21 14:10:34 -07:00
Seth Hillbrand
4c03ab8ebb Finally remove other_math routines
Replace with standard SEG and VECTOR2 alternatives.  Add QA test for
additional SEG-line intersection routine
2025-07-21 11:03:17 -07:00
Seth Hillbrand
0459c54a92 Cleanup and clarify SEG::intersect and SEG::Collide
Fix handling of end point intersection case
Fix degenerate handling
Fix overflow cases
Simplify logic in SEG::Collide
Remove overly simplistic check for intersection

Add multiple QA regression tests
2025-07-21 11:03:17 -07:00
John Beard
d15b2b7305 SHAPE_ARC: Fix GetCentralAngle normalization documentation
This appears to have always been [-360 .. 360], as some tests in
test_shape_arc.cpp have had negative values for a very long time.

Add tests on the start, end and central angle accessors to enforce
the documented normalizations.
2025-06-08 09:55:54 +08:00
John Beard
026eb2512d QA Arc: update 'bad midpoint' test case after fix (2124f2b846) 2025-06-08 09:55:54 +08:00
John Beard
98efdaea5e QA Arc: add a test of SHAPE_ARC start/mid/end construction
Also add an expected-failure for an arc where a bad midpoint
should be corrected or rejected by the SHAPE_ARC constructor

Relates-To: https://gitlab.com/kicad/code/kicad/-/issues/21035
2025-05-31 19:30:23 +08:00
John Beard
1ad03f5717 QA: Fix angle-equality predicate
This was sometimes accepting a wrong value on the "other side" of
the correct value. Only actually affected one test, which is fixed.
2025-05-31 19:29:02 +08:00
Seth Hillbrand
9bedb6eedb Fix silk board edge collision case
First, fix the error limit check in drc_test_provider_edge_clearance.
Then, we rotate the final point incorrectly in SHAPE_ARC::Collide (need
negative angle).  We were not checking this result in the QA, so add the
proper tests
2025-05-19 17:49:03 -07:00
Jeff Young
4cd2e947a1 Slice() must also support aMaxError.
In some cases arcs are re-inserted.
2025-05-13 12:03:41 +01:00
Jeff Young
7f4853b8a5 Third go at fixing the kimath test. 2025-05-13 09:57:13 +01:00
Jeff Young
acf1dca1e1 Another go at fixing the kimath test. 2025-05-13 08:45:50 +01:00
Jeff Young
32cd142c39 Allow math tests to run with their own precision. 2025-05-12 21:57:52 +01:00
Seth Hillbrand
de09403b10 Fix mistake in arc circle collision
Need to test nearest point from the circle center to the arc.  Add QA to
prevent regression

Fixes https://gitlab.com/kicad/code/kicad/-/issues/20336
2025-03-14 18:06:09 -07:00
John Beard
d9a243d98c QA: Use data-driven tests in a few places
This means that you can run just a single case from the command line,
for example:

   `qa_pcbnew -t DRCCopperSliver/_0`

The case is also automatically printed as context.

This means that when isolating a specific defect in one case,
you can run only that one case, which is useful under debuggers
and also when using slow tools like valgrind.

Not all possibe tests are doing this, but they're easy to do
when needed (i.e. when you want to run just one case)
2025-01-24 20:13:19 +08:00
Seth Hillbrand
bfb3875a68 Add additional handling for arc collisions
Provides nearest point calculation for circles, segments and rects

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18203
2025-01-14 13:08:45 -08:00
Seth Hillbrand
b73481dd49 Update SHAPE_ARC::IntersectionPoints()
Force it to handle a number of edge cases from Arc-Arc collision test.
Unify and simplify the Collide Arc-Arc.  Add additional arc collision
QA test
2025-01-14 13:08:45 -08:00
Marek Roszko
02b3d03c23 Fix ctest for windows with env shim that is disabled for non windows, for now.
Also stuff a dummy fontconfig file to silence the dumb error on stdout, which interferes with testing
2025-01-04 22:08:58 -05:00
Seth Hillbrand
074e6df3bc Revert "Move thread pool to singleton class"
This reverts commit 361f61a02380881efb59b1cebfdc3e73322b3d3c.
2025-01-03 21:22:44 -08:00
Seth Hillbrand
361f61a023 Move thread pool to singleton class
Having thread pool as its own singleton in the library meant that each
kiface had its own threadpool, leading to many multiples of the threads
being started.  Placing a singleton class in PGM_BASE ensures that all
kifaces use the same thread pool.

The singleton class can be extended to provide single instance
guarantee for any element across kifaces
2025-01-03 13:51:11 -08:00
Seth Hillbrand
0b2d4d4879 Revise Copyright statement to align with TLF
Recommendation is to avoid using the year nomenclature as this
information is already encoded in the git repo.  Avoids needing to
repeatly update.

Also updates AUTHORS.txt from current repo with contributor names
2025-01-01 14:12:04 -08:00
Seth Hillbrand
e9bc8cfe9d Give Clipper1 a Viking funeral
Clears out the last spot where we were only using Clipper1 (how'd I
miss that?) and remove all calls to the Clipper1 structures
2024-12-23 17:12:09 -08:00
Seth Hillbrand
7916b1ddb8 Fix error in PointInside
If we are checking a point that is inline with multiple segments, we
were counting both the entry and exit as crossings, leading to points
inside a polygon being registered as outside.  Changing the conditional
to only catch one crossing as required.

Adds a QA check to ensure that this remains fixed

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18377
2024-11-07 09:09:00 -08:00
John Beard
201b60c670 Point editor single-corner chamfer tool
Come up with a plausible default chamfer size, rather
than prompting every time with a modal (and then you have
to handle when the chanfer doesn't fit). This could be
changed if it's more annoying this way. But if we had
proper edge-dragging in zones, probably would be better
than setting a chanfer manually.

Also fix the GetNeighbourIndexes which seems to have
always been broken (but is not actually used by anything at
present).

Relates-To: https://gitlab.com/kicad/code/kicad/-/issues/16771
2024-10-13 11:10:49 +08:00
John Beard
55370e7520 QA: BOOST_CHECK to _TEST in some KiMath tests
This tells you the arguments when it fails.

BOOST_TEST is available in all our Boost.Test version.
Even if you didn't use it, these calls should have been
BOOST_TEST_EQUAL(A, B) which also tells you the
arguments on a test failure.
2024-10-09 11:42:16 +08:00
John Beard
889e24988b Reference image: avoid overflow on large scales
This has always been possible (especially through the properties
panel with large scales), but it's even easier if the transform
origin is near a manipulated corner.

Check and reject scales that result in an overflowed image box.
2024-09-28 13:24:26 +01:00
John Beard
9eeab7a7a2 Dogbone: add test change missed in commit 2024-09-23 10:35:09 +01:00
John Beard
5ddbfd6fcd Dogbone: update tests
Need to use bigger numbers to avoid excessive rounding issues.
2024-09-20 11:27:19 +01:00
John Beard
1d2fb3ec82 Geom: add a simple OVAL type
Makes it easier to reason about oval shapes in geometric terms.

For now, this isn't a SHAPE, but it could be (and it's a
fairly common primitive, so it could be useful, though the
obvious use (clearance) is equivalent to a SEG with a clearance,
which is already a function that exists.
2024-09-19 06:35:43 +01:00
Seth Hillbrand
977d9e4e72 Fix compile issue on Clang/Linux
Overloaded operator couldn't figure out if it wanted to check 32 or 64
bit ints
2024-09-12 15:10:29 -07:00
John Beard
49b8a5ce74 VECTOR2, BOX2: Add constexpr to many functions
In the core geometric types, this can provide some
useful optimisation opportunites.

As most trig functions and std::sqrt aren't constexpr
until C++26, anything that involves a vector length
can't be constexpr yet. But std::clamp and, importantly,
KiROUND are, which does allow quite a bit. And squared
sizes do work, as they are just multiplies, so size
comparisons work too.

The floating point equals-with-epsilon function can't
be directly made constexpr until C++23 (unless std::abs
is replaced with manual code, but that may then forgo
the use of intrinsics at runtime). And they're probably
not important to have at compile-time.

Add a few tests with static_asserts to show/prove that
some non-trivial operations can be done at compile time,
for example BOX2 merging.
2024-09-11 22:35:35 +01:00
John Beard
f4eb173c43 BOX2: By-value GetInflated method
This allows better value-semantics and const correctness.

This is a common method, as the Inflate method is
in-place:

  BOX2I inflated = other;
  // 'Inflated' is not inflated yet
  inflated.Inflate( delta );
  // Now it is inflated, but it's not const

This is annoying, as the 'inflated' box cannot easily
be made const. Instead:

  const BOX2I inflated = other.GetInflated( delta );
2024-09-11 22:35:35 +01:00
John Beard
7fe5caffa6 BOX2: Fix Inflate parameter type
If this is just 'int', BOX2D will not Inflate
as you might expect if given an non-integer parameter,
but will instead do a conversion.

Use coord_type, like the two-parameter Inflate method.

Add a test for this.
2024-09-11 22:35:35 +01:00
John Beard
b2be0d39bd Snapping: Add construction geometry snapping
This is a pretty major rework of the snapping system.
The GRID_HELPERs now have a separate CONSTRUCTION_MANAGER
which handles some of the state involving "construction
geometry".

This is fed with 'extended' geometry (e.g. "infinite" lines from
segments) for use in generating things like intersection points.
It also handles adding this geoemtry to a GAL view item
(CONSTRUCTION_GEOM) for display to the user.

The process is:

* A TOOL creates a GRID_HELPER
* Optionally, it pre-loads a "persistent" batch of construction
  geometry (e.g. for an item's original position)
* The grid helper finds useful snap 'anchors' as before, including
  those involving the construction items.
* Other items on the board can be 'activated' by snapping to one
  of their main points. Then, if it has construction geometry,
  it will be added to the display. At most 2 items of this kind of
  geometry are shown, plus the original item, to reduce avoid
  too much clutter.

The dashed snap lines state machine is also handled in the
CONSTRUCTION_MANAGER and displayed in the CONSTRUCTION_GEOM item.
2024-09-11 22:35:35 +01:00
John Beard
5925f9c374 Break out some geom functions from dimension text adjustment
Put these in a separate header - they don't need to be available
whenever VECTOR2 is, but they are generic, reusable functions that
can have the corner cases defined and tested.
2024-09-11 22:08:36 +01:00
John Beard
78cb6c1189 SEG: Correct sign in LineDistance 2024-09-06 19:26:58 +01:00
Seth Hillbrand
3e5ca2ee7a Modify SHAPE_LINE_CHAIN::Simplify() to fix PNS
Issue raised by TomW, points included in new QA test where Simplify was
not properly removing colinear points.

Also removed TestSegmentHitFast() as the speed gains were minimal when
testing against the revised SEG::SquaredDistance routine in
TestSegmentHit()
2024-09-03 17:23:07 -07:00
John Beard
6167be1e98 QA: Remove duplicate function that exists in qa_utils 2024-08-28 13:49:36 +01:00
John Beard
1fb2d7fe26 Pcbnew: Snap to graphic/track intersections
Relates-To: https://gitlab.com/kicad/code/kicad/-/issues/2329
2024-08-28 13:49:36 +01:00
John Beard
0818ee1770 Pcbnew/FPedit: Add snap anchor type indicators
This allows to see what the current snap point is, which is useful when
zoomed in, or the point is like the corner of a rounded pad where it's
"in free space" and might not be immediately obvious.
2024-08-28 13:49:36 +01:00
Seth Hillbrand
9f4f3deec5 Don't use std::signbit for ints 2024-08-17 07:39:26 -07:00
Seth Hillbrand
fba2b7a04a Modify previous commit to correct logic
We are calculating the same value in two different ways.  If there is an
off-by-one issue in our calculation along axis, this still means that it
was a direct hit on the line as seen in the unit test cases
2024-08-16 17:05:39 -07:00
Lucas Dumont
f3bbf2b7bd Kimath: Squared distance can't be negative
Fixes https://gitlab.com/kicad/code/kicad/-/issues/18473
2024-08-16 17:05:39 -07:00
John Beard
5b772dde13 QA: Use modern Boost test print customisation point
Since Boost 1.64, you can use the boost_test_print_type
customisation point to provide test printing for types.
Move all test printing functions to this, and scrap the
fiddly Boost version handling to deal with older Boosts
(KiCad is now at minver 1.71).
2024-08-14 11:24:26 +01:00
John Beard
7fc367e688 Pcbnew: Add dogbone corner tool
This adds circular arcs in corners to allow for the router
cutter radius when routing a slot or corner that receives
a sharp corner.

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/18512
2024-08-07 23:01:32 -06:00