Commit Graph

369 Commits

Author SHA1 Message Date
qu1ck 0c049eccc7 Fix a bunch of compiler warnings 2023-04-11 17:01:30 +00:00
jean-pierre charras ac71227e75 Fix compil warnings. 2023-03-23 18:36:59 +01:00
Seth Hillbrand 97558b62ec Update to Clipper 1.2+
Updates to Clipper2 742614f, which includes bug fixes for specific KiCad
boards beyond Clipper2 itself

Fixes https://gitlab.com/kicad/code/kicad/issues/14294
2023-03-22 15:24:26 -07:00
Alex 98e635869f Improve anti-overflow in SEG::intersects.
Caused issues when testing against
A=( -INT_MAX, ... ), B=( INT_MAX, ... ) segments.

Fixes https://gitlab.com/kicad/code/kicad/issues/14293
2023-03-16 05:03:21 +03:00
jean-pierre charras 893a362d9e Minor Coverity and compil warnings fix. 2023-03-15 20:09:04 +01:00
jean-pierre charras e6945a85b0 fix compil and Coverity warnings. 2023-03-12 15:19:50 +01:00
Roberto Fernandez Bautista f1db501adb Fix warning in SHAPE_LINE_CHAIN::Slice 2023-03-11 16:18:53 +01:00
Jeff Young 43fa5e957f Fix shadowed variable warning. 2023-03-10 17:42:36 +00:00
Ian McInerney 5671a123b9 kimath: Fix some warnings 2023-03-10 16:38:35 +00:00
Ian McInerney 9292158c76 kimath: Switch from INT_MAX to std::numeric_limits 2023-03-10 16:38:35 +00:00
Jeff Young 2f2a00c307 Overflow safety.
Potential fix for some or all of
https://gitlab.com/kicad/code/kicad/-/issues/13969
2023-03-03 21:29:37 +00:00
Seth Hillbrand 1fda68099f Prevent inf when presented with 0 errormax
acos(1) returns 0, so this implies infinite segements to get to 0 error.
This is not reasonable but might be encountered in bad arcs or circles
that have 0 radius.  Instead of returning infinite or std::max segments,
we limit the error to be at least 1 IU
2023-03-02 10:21:05 -08:00
Seth Hillbrand 01039b50ca Correct the formula for error
The radius should always be positive but simply reversing the sign of
the inner expression only works in some cases
2023-02-22 16:24:26 -08:00
Marek Roszko aacc9746e3 Yeet the last of wxSize/wxPoint to stop leaking gdicmn everywhere 2023-02-18 22:57:18 -05:00
Seth Hillbrand 5a56b18b0e Revert "Update Clipper2 to version 1.1.1"
This reverts commit c594a0eba2.
2023-02-17 09:24:19 -08:00
Seth Hillbrand c594a0eba2 Update Clipper2 to version 1.1.1 2023-02-17 17:14:37 +01:00
Seth Hillbrand e60152e351 Fix island removal when copper->edge clearance is 0
Just testing a single point to find copper that is outside the board works
until the arc->segment conversion moves the board outline just enough to
have the filled copper slightly (few IU) outside of the converted outline.

Instead, we do an expensive check of comparing the size of the
intersection between the island and the island's intersection with the
board.  If the intersection is at least half as large as the original
island, we can say with certainty that the island is inside.  The margin
could be much smaller than half but this preserves the intent without
picking an arbitrary number that might be violated

Fixes https://gitlab.com/kicad/code/kicad/issues/13717
2023-02-02 19:19:26 +00:00
Vincenzo Fortunato 42b4f49e7f Fix polygon self intersection check
Fixes https://gitlab.com/kicad/code/kicad/issues/13628
2023-01-26 22:56:47 +00:00
Tomasz Wlostowski 4d208bac49 geometry: added SHAPE_SEGMENT::Is45Degree() method 2023-01-12 23:37:07 +01:00
Roberto Fernandez Bautista 33249d37b0 EAGLE SCH: Improve detail of curved shape imports (0.01mm error)
Follow-up from https://gitlab.com/kicad/code/kicad/-/merge_requests/1445
2023-01-10 22:45:46 +01:00
Roberto Fernandez Bautista ebce53d574 Allow specifying acuracy when appending an arc to a chain 2023-01-10 22:28:01 +01:00
Jon Evans 68bc18425b Handle zero-size pads in CornerListToPolygon
Fixes https://gitlab.com/kicad/code/kicad/-/issues/13276
2022-12-26 10:04:03 -05:00
Jon Evans b85fab9ab6 Support DXF ellipses and elliptical arcs
Fixes https://gitlab.com/kicad/code/kicad/-/issues/12563
2022-12-24 22:46:07 -05:00
Seth Hillbrand 035ff27b76 Be smarter about checking SHAPE_POLY_SET intersect
The segment iterator creates segments when needed, so using it in a dual
loop creates NlgN more copies than we need.  This shifts to a single
copy algorithm that then uses a sorting to preemptively abort the search
once the segments are outside of the search bounding box

Fixes https://gitlab.com/kicad/code/kicad/issues/13191
2022-12-18 08:01:19 -08:00
jean-pierre charras ca2dde23d0 SHAPE_ARC::Collide(): fix incorrect returned position of colliding point.
The previously returned position had nothing to do with the colliding point.
2022-12-18 15:40:15 +01:00
jean-pierre charras 1047e7143a SHAPE_ARC::GetCentralAngle(): ensure a 360 deg arc angle is always returned as 360 deg.
An arc having the same start and end points can be 0 or 360 deg arc.
In Kicad it is always 360 deg arc (i.e. a circle)
Fixes #13182
https://gitlab.com/kicad/code/kicad/issues/13182
2022-12-17 14:44:53 +01:00
Seth Hillbrand 83ced602a6 Free solution memory in Clipper2
The PolyTree64 memory is not automatically freed in the dtor, so call
this explicitly
2022-12-04 16:50:27 -08:00
Seth Hillbrand 73398e07a8 Fracture self-intersecting polygons
Self-intersecting polygons may form a hole after simplification, so make
sure that we fracture them as well to clear the hole

Fixes https://gitlab.com/kicad/code/kicad/issues/13067
2022-12-03 12:08:48 -08:00
Seth Hillbrand bd40684ecd Handle polygons' triangulation
Graphic polygons may be invalid and so need to be explicitly simplified
before triangulation.

Also clean up hole handling in triangulation routine
2022-11-28 15:46:12 -08:00
Seth Hillbrand 77770ff313 Revert "Ensure bad polys get simplified before triangulation"
This reverts commit fcf44091d2.
2022-11-28 12:38:16 -08:00
Seth Hillbrand fcf44091d2 Ensure bad polys get simplified before triangulation
If the poly set is self-intersecting, the triangulation may be
problematic and the full set needs simplification before.  We don't do
this uniformly because the simplification can be a slowdown if it is not
needed

Fixes https://gitlab.com/kicad/code/kicad/issues/12806
2022-11-28 10:37:37 -08:00
Alex 5e7c4b734c Small optimizations in DRC and SHAPE_POLY_SET. 2022-11-17 02:10:22 +05:00
Tomasz Wlostowski 0a69340953 geometry: fix incorrect 45 degree miter generation (likely a side bug after introduction of EDA_ANGLE) 2022-10-31 11:49:31 +01:00
Tomasz Wlostowski cd29dcf6e0 libs/kimath: SHAPE::Format() can now produce C++ object construction and simple test dump of shapes 2022-10-31 11:17:31 +01:00
Seth Hillbrand 8e97855557 Fix Clipper2 handling of Inflate/Deflate
For unknown reasons, Clipper2 only returns Paths structures from the
ClipperOffset::Execute routine.  Further, the Paths are not properly
ordered (outline->hole in outline, outline2->hole in outline2).
To get proper hierarchy, we need to run an additional pass of the
solution with the paths as Subject in a null union.  This is effectively
a Simplify() call but we keep the data in Clipper format to reduce the
churn/calc time
2022-10-28 17:01:36 -07:00
Seth Hillbrand 546e16a002 Add multi-level fallback in tesselation
Some clipper cases do not get resolved with the `FAST` mode, so in those
cases, do a second pass in the `SIMPLE` mode.  If both fail, return a
broken polygon instead of an infinite loop

Fixes https://gitlab.com/kicad/code/kicad/issues/12761
2022-10-28 10:17:58 -07:00
Seth Hillbrand 4cdf0bd6c9 Clipper2: Handle nested poly/hole/poly returns
In Clipper1, we had a flat tree structure on returns.  Clipper2 nests
these, so we need to properly handle the nesting structure when
importing the polygons
2022-10-21 16:14:34 -07:00
Jeff Young d16b23d16e Name shortening and line-break reduction. 2022-10-21 18:41:39 +01:00
Seth Hillbrand 27add591ec Add Clipper2
Currently this lives behind the advanced config flag `UseClipper2`.
Enabling this flag will route all Clipper-based calls through the
Clipper2 library instead of the older Clipper.  The changes should be
mostly transparent.

Of note, Clipper2 does not utilize the `STRICTLY_SIMPLE` flag because
clipper1 did not actually guarantee a strictly simple polygon.
Currently we ignore this flag but we may decide to run strictly-simple
operations through a second NULL union to simplify the results as much
as possible.

Additionally, the inflation options are slightly different.  We cannot
choose the fallback miter.  The fallback miter is always square.  This
only affects the CHAMFER_ACUTE_CORNERS option in inflate, which does not
appear to be used.

Lastly, we currently utilize the 64-bit integer coordinates for
calculations.  This appears to still be faster than 32-bit calculations
in Clipper1 on a modern x86 system.  This may not be the case for older
systems, particularly 32-bit systems.
2022-10-19 16:25:45 -07:00
Jeff Young e5de56b6cc Fix edge case in arc collision.
SHAPE_ARC::IntersectLine() fails when one of the arcs start points
is on the center point of the other -- in this case we can't extend
the line to the arc intersection because one point does not define
a line....

Fixes https://gitlab.com/kicad/code/kicad/issues/12609
2022-10-09 23:05:15 +01:00
Jeff Young e866dfe137 Avoid trying to draw empty pads.
Fixes https://gitlab.com/kicad/code/kicad/issues/12605
2022-10-09 20:28:54 +01:00
Jeff Young 19d270fe74 Text size sanity checking for TEXT_ITEMS_GRID.
Oh dear, there was a bunch going on here.  Firstly the move from int
to long long int for ValueFromString() means that we were no longer
catching overflows (as we were C-style casting it back to int in many
places).  But even when the overflow is caught, it would run in to
wxWidgets' empty string bug while trying to log it.

Fixes https://gitlab.com/kicad/code/kicad/issues/12577
2022-10-06 13:19:08 +01:00
Tomasz Wlostowski 26b2fd36d4 libs/kimath: fix divide by 0 for 0-length segments 2022-10-05 22:40:47 +02:00
Tomasz Wlostowski f80b48e1b0 libs/kimath: consider signed distances in parallelity check 2022-10-05 14:38:05 +02:00
Tomasz Wlostowski 6ed3618ce5 libs/kimath: improve numerical robustness of ApproxParallel/ApproxCollinear for segments of largely different lengths 2022-10-04 20:55:08 +02:00
Alex 58b03b0a1c Small optimizations. 2022-09-22 17:22:04 +00:00
Jeff Young fc74de81fb Don't crash on empty SHAPE_LINE_CHAINs.
Fixes https://gitlab.com/kicad/code/kicad/issues/12407
2022-09-13 13:28:00 +01:00
Jeff Young 9188838e50 RIP EDA_RECT. 2022-08-31 23:57:24 +01:00
Jeff Young b4492e0bd2 More EDA_RECE yeetage. 2022-08-31 17:19:50 +01:00
Seth Hillbrand b736460e71 Move optional access from value() to *operator
`value()` throws.  Where we check for existence, we don't need to use
the throwing version and should just use the unprotected variant
2022-08-30 13:59:39 -07:00