Commit Graph

345 Commits

Author SHA1 Message Date
Roberto Fernandez Bautista b4835c8208 Add test case for SHAPE_ARC::Collide( seg ) + remove unneeded candidates
Followup to commit 01068e0d41
2021-12-13 18:06:11 +00:00
Tomasz Wlostowski 01068e0d41 geometry: fix SHAPE_ARC/SEG collision
The arc2segment collision should at also include the arc endpoint projections on the segment being tested. Not sure it covers all possible cases, though.

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/9023
2021-12-09 00:37:58 +01:00
jean-pierre charras 0dad504e91 POLY_GRID_PARTITION: detect a divide by 0, set a wxASSERT and avoid the crash. 2021-12-08 16:07:11 +01:00
Roberto Fernandez Bautista 2d1ad52212 SHAPE_LINE_CHAIN: Fix arc indices rotation after merging duplicate points
Fixes https://gitlab.com/kicad/code/kicad/-/issues/9843
2021-12-05 15:12:09 +00:00
Roberto Fernandez Bautista c463818b57 SHAPE_LINE_CHAIN: Only fix up arc indices if last pt is part of an arc
Fixes https://gitlab.com/kicad/code/kicad/-/issues/9843
2021-12-03 22:04:55 +00:00
Jon Evans 0570c22732 Use point collision test for zero-length segments
SEG::SquaredDistance( SEG& ) does not do the right thing
for segments with zero length at the moment.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/9791
2021-11-27 09:08:34 -05:00
Jon Evans b4342d813b Fix SHAPE_LINE_CHAIN::Slice when end is an arc followed by a point
Fixes https://gitlab.com/kicad/code/kicad/-/issues/9770
2021-11-25 10:05:33 -05:00
Tomasz Wlostowski 5d2f3257da libs/kimath: user-settable distance threshold for SEG::ApproxParallel() 2021-11-22 01:35:12 +01:00
Roberto Fernandez Bautista 1026c24c65 SHAPE_LINE_CHAIN fix rotation of indices after going through Clipper
Clipper might mess up the rotation of the indices such that an arc can be split between
the end point and wrap around to the start point. Detect if this happened and fix it as
required.

Also, handle arcs at the last segment of the chain correctly, meaning we can have arcs
towards the end of the chain that finish at the starting point of the chain.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/9670
2021-11-20 16:47:08 +00:00
Roberto Fernandez Bautista d47bd3a04d Rewrite broken collision routine SHAPE_ARC::Collide( SEG& aSeg ) 2021-11-15 14:04:37 +00:00
Roberto Fernandez Bautista cb7e57fb43 CIRCLE::IntersectLine fix incorrect algorithm documentation comments 2021-11-15 14:04:37 +00:00
Roberto Fernandez Bautista 0c3da0f072 Implement true arc collisions for arcs inside a SHAPE_LINE_CHAIN 2021-11-15 14:04:37 +00:00
Jeff Young d66487c383 Make sure RTree bounding box is at least as big as hole.
Fixes https://gitlab.com/kicad/code/kicad/issues/9526
2021-11-05 14:29:10 +00:00
Johannes Pfister 64f77b3596 PNS: Add support for 90-degree corner modes
Fixes https://gitlab.com/kicad/code/kicad/-/issues/6902
2021-11-03 02:14:23 +00:00
jean-pierre charras 29c3601061 SHAPE_POLY_SET: add FullPointCount(), mainly for statistics and debug. 2021-10-24 15:06:24 +02:00
Jeff Young 9b9e379aa0 Overhaul arc internal model to not over-specify information. 2021-10-15 12:45:43 +01:00
Roberto Fernandez Bautista 9e557d84c6 Ensure appended arcs are valid arcs (start, mid, end cannot be collinear)
Fixes https://gitlab.com/kicad/code/kicad/-/issues/9380
2021-10-13 18:58:21 +01:00
Roberto Fernandez Bautista 4b8ca18bf7 Remove unfinished code for handling arcs in SHAPE_POLY_SET::booleanOp
Boolean Ops on polygons with arcs are not supported (the only exception
is Simplify)

Also fix a bug in SHAPE_LINE_CHAIN::splitArc that resulted in an
exception

Partially fixes https://gitlab.com/kicad/code/kicad/-/issues/9380
2021-10-13 18:29:32 +01:00
Seth Hillbrand c1e6fdfb47 Polygon triangulation: Check for broken remainders
If the last three points of a tesselation are concave, we will never be
able to triangulate them.  They were likely formed from a bad polygon,
so we will drop the triangle and return completed

Fixes https://gitlab.com/kicad/code/kicad/issues/9380
2021-10-12 12:14:42 -07:00
Seth Hillbrand 52bbfb9109 Remove dependency of dot size on linear mils
Changes a dot to be a square pixel (linewidth x linewidth).  This allows
the removal of IU dependencies and ensures that a dot is always visible
on screen.  Also makes sure that cairo is setting the current linewidth
during its stroke routines

Fixes https://gitlab.com/kicad/code/kicad/issues/9362
2021-10-10 09:40:26 -07:00
Jeff Young f606679164 Proper numeric sorting for intersheet refs.
Also expunges the horrifically named std::remove and std::remove_if
(neither of which remove anything).
2021-10-01 18:29:21 +01:00
Jon Evans e2368b733c Allow selection of NPTH pads with zero copper size
Fixes https://gitlab.com/kicad/code/kicad/-/issues/9249
2021-09-26 18:17:50 -04:00
Roberto Fernandez Bautista 4abee7c2eb Fix SHAPE_LINE_CHAIN::Split when inserting a point on an arc
Ensure the arc is split into two at the point specified.

Partly fixes https://gitlab.com/kicad/code/kicad/-/issues/9023
Additional work required to ensure that the shove state is preserved.
2021-09-26 15:15:51 +01:00
Jeff Young 46949abe4a Don't scroll to highlight an object already visible. 2021-09-25 15:31:52 +01:00
Seth Hillbrand 28bd734313 Prevent invalid paths in fracture
We are not always sure of the path validity in fracture.  Nominally, the
Clipper Simplify routine should remove invalid parts but in the case
where it doesn't, we need to recover gracefully, even if the output
polygon is not valid.

Fixes https://gitlab.com/kicad/code/kicad/issues/9199
2021-09-21 10:49:39 -07:00
Jeff Young f64abcba36 Restore BBoxCache usage for zone fill performance. 2021-09-09 16:43:47 +01:00
Roberto Fernandez Bautista ed39b33d74 Fix edge case in CIRCLE::Intersect that caused a divide-by-zero crash
Also add some additional test cases.
2021-08-25 19:11:19 +01:00
Jon Evans 80355f04a9 Fix SHAPE_LINE_CHAIN::Replace at end of chain 2021-08-13 16:59:45 -04:00
Roberto Fernandez Bautista d9cf939ba1 SHAPE_LINE_CHAIN::Replace Don't call front() or back() if empty
Fixes https://gitlab.com/kicad/code/kicad/-/issues/8949
2021-08-12 16:32:06 +01:00
Roberto Fernandez Bautista ab3564f12d Fix formatting in prior commit 2021-08-11 17:40:23 +01:00
Roberto Fernandez Bautista 22df01183d Fix edge cases in CIRCLE::Intersect that were causing KiROUND overflow 2021-08-11 17:31:27 +01:00
Roberto Fernandez Bautista 11fc74920c Fix infinite loop in SHAPE_LINE_CHAIN::Slice
Was resulting in infinite loop due to wrong calculation
in NextShape.
2021-08-09 21:10:33 +01:00
Roberto Fernandez Bautista ae87dc686a Fix SHAPE_LINE_CHAIN::NearestPoint when aAllowInternalShapePoints=false
Fixes https://gitlab.com/kicad/code/kicad/-/issues/8770
2021-08-08 20:58:20 +01:00
Roberto Fernandez Bautista 1edb96cc5b Fix SHAPE_LINE_CHAIN::Slice(), splitting arcs when required 2021-08-08 19:09:54 +01:00
Roberto Fernandez Bautista eaf8eb284a Add true arc-to-polyline collisions 2021-08-05 17:45:12 +01:00
Roberto Fernandez Bautista dd65ce9523 Simplify & move new arc collision code into Kimath library
Don't need to check intersections with the circle, just fix the
calculated "projected" point from the end points.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/8234
2021-08-05 17:45:12 +01:00
Roberto Fernandez Bautista b6be10f05c Fix CIRCLE::Intersect( const SEG& aSeg ) and add unit tests 2021-08-05 17:45:12 +01:00
Roberto Fernandez Bautista 318435aedb Add more test cases: simulate zone fill around arc + diff pair meander 2021-08-05 17:45:11 +01:00
jean-pierre charras b6664eecf2 arc: fix incorrect arc center calculation for angle < 0 or > 180 deg 2021-08-05 18:15:55 +02:00
Jeff Young c00f4ed5d2 Add regression tests for track cleaner. 2021-08-03 16:17:18 +01:00
david-beinder 3a833debea ShapeToPolygon: implement negative inflation
Fixes https://gitlab.com/kicad/code/kicad/-/issues/8859
2021-07-28 10:37:56 +00:00
Wayne Stambaugh 78e5e98ea0 Pass VECTOR2I objects by reference instead of on the stack. 2021-07-27 08:41:27 -04:00
Wayne Stambaugh 8fd83cbb95 Pass wxPoint objects by reference instead of on the stack. 2021-07-26 15:35:33 -04:00
Jeff Young 4760480f40 Quiet compiler warnings. 2021-07-22 13:03:17 +01:00
david-beinder 937e4b1d8c ShapeToPoly: Fix outline/arc intersection for large expansions
Fixes https://gitlab.com/kicad/code/kicad/-/issues/8820
Adds shortcut code path for 90deg corners
Segments are now actually symetrical
Refactored and commented the code
2021-07-22 11:53:08 +00:00
Wayne Stambaugh 4c457b5ed3 More NULL expunging. 2021-07-18 14:31:55 -04:00
jean-pierre charras 25e9d17722 Fix a boost compatibility with old boost versions.
(replace boost::optional::has_value() by its definition is_initialized())
2021-07-16 14:01:26 +02:00
david-beinder 8b3ccab0a3 Implement explicit polygon construction for most pad shapes
Fixes https://gitlab.com/kicad/code/kicad/-/issues/8650
2021-07-13 14:51:58 +00:00
jean-pierre charras 54b6f51633 DSN export: export RECT and ARC shapes (on silkscreen layer) from footprints
Also export arc track segments as lines. (Freerouter does not support QARCs)
Fixes #8769
https://gitlab.com/kicad/code/kicad/issues/8769
2021-07-11 18:15:40 +02:00
jean-pierre charras ec64e8ad5b TransformRingToPolygon(): fix incorrect approximation of the hole. 2021-07-06 13:59:05 +02:00
Roberto Fernandez Bautista 72435c78af Fix out of bounds crash in SHAPE_LINE_CHAIN::splitArc
Check that the index references a point that is part of an arc
2021-07-05 20:29:24 +01:00
jean-pierre charras 515669284a convert_basic_shapes_to_polygon: some enhancements:
- allows setting a minimal seg count for circles and rounded end segments.
- When using ERROR_OUTSIDE, ensure the arc correction is the actual value
needed by the segment count, not the max value allowed
2021-07-05 17:46:02 +02:00
Jon Evans 3103ff9aa3 Fix display of filled polygons with arcs in the outline 2021-07-04 12:10:59 -04:00
Jon Evans ddc20dadc0 Formatting and spelling tweaks 2021-07-03 15:43:40 -04:00
Roberto Fernandez Bautista cee5920d5c Remove dead code (SHAPE_LINE_CHAIN::DetectArcs) 2021-07-03 19:37:50 +00:00
Roberto Fernandez Bautista 778c64de88 Implement ClearArcs() and check curved polys don't get a booleanOp
We cannot (yet) support passing several curved outlines through clipper.
In these cases, the caller should ClearArcs() before processing.
2021-07-03 19:37:50 +00:00
Roberto Fernandez Bautista 260a9d0540 Use ZFillFunction to modify arcs post clipper (does not fully work yet)
Added a unit test to verify union and intersection of polygons result
in desired results: subject + clip - intersect == union
2021-07-03 19:37:50 +00:00
Roberto Fernandez Bautista 437e2783fb Use Clipper Z value to detect arcs post clipper 2021-07-03 19:37:50 +00:00
Roberto Fernandez Bautista a9a8aa8243 SHAPE_LINE_CHAIN splitArc on Insert, Remove and Replace
This ensures that the arc shapes remain correct after removing
a point belonging to an arc or inserting a point in the middle
of an arc.

Simplify implementation of Replace( ..., aP ). Now a Remove
operation followed by an Insert operation.

Improve QA test for SHAPE_LINE_CHAIN Append, Insert and Replace

Implement SHAPE_LINE_CHAIN::splitArc to break up an arc into two

Implement SHAPE_ARC::ConstructFromStartEndCenter and add qa test
2021-07-03 19:37:50 +00:00
Roberto Fernandez Bautista 3f73d8c2b5 SHAPE_LINE_CHAIN::Area() should always be positive
The algorithm relied on the assumption that the points were
ordered anti-clockwise. When ordered in a clockwise fashion, the
result was correct but negative.

Refer to https://www.mathopenref.com/coordpolygonarea2.html
for more information.
2021-07-03 19:37:50 +00:00
Roberto Fernandez Bautista c3051ba48a Refactor SHAPE_LINE_CHAIN to allow two shapes per point
m_shapes now has two possible indices. The first one is populated if
the point is associated with an arc and the second index is populated
if the point is shared between two arcs.
2021-07-03 19:37:50 +00:00
Roberto Fernandez Bautista c1361ae173 SHAPE_POLY_SET: Detect arcs after boolean operations 2021-07-03 19:37:50 +00:00
Roberto Fernandez Bautista 3ee8b4825c Implement SHAPE_LINE_CHAIN::DetectArcs and add qa test 2021-07-03 19:37:50 +00:00
Roberto Fernandez Bautista 14c3d9055e Add CIRCLE::Contains( VECTOR2I aP ) and add unit tests 2021-07-03 19:37:50 +00:00
Seth Hillbrand a28d9f17e8 WIP 2021-07-03 19:37:50 +00:00
Seth Hillbrand 8521deb38d De-scope ClipperLib namespace 2021-07-03 19:37:50 +00:00
Seth Hillbrand 6c224156f5 Adding conversion from points to arcs
Allows detection of arcs from segments in a SHAPE_LINE_CHAIN, converting
them to SHAPE_ARCs in the chain
2021-07-03 19:37:50 +00:00
Seth Hillbrand 5b2be906b8 Removing CLIPPER poly support 2021-07-03 19:37:50 +00:00
Seth Hillbrand 4f4deece6d ADDED support for reading/writing arcs in polys
This adds support for reading and writing arc elements in polygons.
2021-07-03 19:37:50 +00:00
Marek Roszko eff75b630f Get rid of anonymous struct typedefs
We are using C++14 where there is no reason for this and is banned in C++20 under P1766R1. MSVC generates a warning under C++14 as a reminder.
2021-07-01 18:28:41 -04:00
Wayne Stambaugh 507a88524a KiCad internal library header file housekeeping. 2021-07-01 13:46:38 -04:00
Wayne Stambaugh 175b474c3e Coverity issue fixes.
Fixes issues #280412, #314755, #329615, #332459, #332157, #332167,
2021-06-30 18:08:49 -04:00
jean-pierre charras 17737af130 Fix some issues related to SHAPE_ARC:
- Some are related to shape errors when the allowed error to approximate circle
by segment is large and arc radius small.
- fix the actual error used in ConvertToPolyline().
- Use SHAPE_ARC::DefaultAccuracyForPCB() instead of a fixed value as extra margin
in zones. It should not change something, because it is also a fixed value
(5 micrometers), but it is not a magic number.
-TransformArcToPolygon() fix some issues and add a new algo, based on the arc actual
outline shape (initial algo is still available in code, just in case).
2021-06-30 13:33:49 +02:00
jean-pierre charras bcb5618315 Fix incorrect calculation in TransformCircleToPolygon(), only noticeable
when the allowed aError is (unusually) large.
2021-06-28 18:51:37 +02:00
jean-pierre charras fa49b54f93 Fix minor issue in TransformCircleToPolygon() when aError is set to a large value.
pcb_painter.cpp: add (but not activate) compil option to show the conversion
of SHAPE_ARC::ConvertToPolyline as segments, for debug purposes.
2021-06-28 15:50:16 +02:00
jean-pierre charras 9a865b1989 Fix a typo and a minor compil warning 2021-06-28 14:37:35 +02:00
jean-pierre charras 310adedf85 Add GetCircleToSegmentError() to geometry/geometry_utils.
This function returns the error created by a circle to segment approximation.
2021-06-26 18:57:07 +02:00
jean-pierre charras 3c81403424 Refinements in Arc to Polygon transform: slightly better shapes of arc ends.
Note also the transform is still not good: the same parameters are applied
to convert inner arc, outer arc and middle arc of a thick arc to segments.
But these parameters depend on arc radius (or circle radius) value.
2021-06-26 14:20:55 +02:00
jean-pierre charras 31d7a0a8d1 TransformArcToPolygon(): slightly better approximation of arc.
The error between the "right" shape and the polygon is slightly smaller.
The approximations of the inner arc and the outer arc are better, but not perfect.
Also add (for test and debug purpose only) the code to show the polygon when
drawing a PCB_ARC (currently disabled)
2021-06-25 18:46:16 +02:00
jean-pierre charras 1d6ad4a52a SHAPE_ARC::ConvertToPolyline(): fix ugly approximation for some arcs.
Arcs with small radius can be approximated with very few segments.
However, if the thickness is large, relative to the radius, the approximation
must be based on the external radius, not the arc radius.
The difference can be significant.
This is especially noticeable for these graphic arcs in filled zones.
2021-06-23 18:30:02 +02:00
Seth Hillbrand a04d6401c1 Transform arcs more accurately
Segment approximation for arcs leaves small "indents" where the rounded
edges of two segments don't quite meet.

This gives closer approximation by calculating the inner and outer joint
points based on the radius, eliminating the indents.
2021-06-11 14:26:38 -07:00
luz paz f968fc8719 Fix source comment / documentation typos 2021-06-09 19:32:58 +00:00
Marek Roszko ffa87e69c6 Remove/replace some stdint.h includes 2021-06-08 21:17:57 -04:00
Jeff Young 53a75a4961 Fix actual-clearance handling in arc collision routines.
Fixes https://gitlab.com/kicad/code/kicad/issues/8407
2021-06-03 18:33:59 +01:00
Jeff Young 976e756b02 Formatting. 2021-06-03 18:33:59 +01:00
Seth Hillbrand 059f79dfdb Re-remove KiROUND from header
Moves routines requiring KiROUND (and util.h by extension) to the cpp
file
2021-06-03 08:44:17 -07:00
Marek Roszko 29783f125b Eliminate one wxRect constructor in BOX2
The only usage auto converted to BOX2D anyway...
2021-06-03 01:27:15 -04:00
Seth Hillbrand cf1c75ecd4 Handle rounding errors in seg length calculation
SQRT needs to be passed through KiROUND before returning otherwise,
truncation errrors will accumulate between routing and DRC

Fixes https://gitlab.com/kicad/code/kicad/issues/8541
2021-06-02 16:42:35 -07:00
Marek Roszko c294d28275 Split POLY_GRID_PARTITION to a cpp file
Not entirely a lightweight class
2021-06-02 18:31:30 -04:00
Marek Roszko 13abb9f947 Shift some seg functions to the cpp file 2021-06-02 18:31:30 -04:00
jean-pierre charras b6de4da686 Fix compatibility with wxWidgets 3.0.x
Fixes #8533
https://gitlab.com/kicad/code/kicad/issues/8533
2021-06-02 10:02:20 +02:00
Marek Roszko 0b4a680dbb Hotglue wxLogDebug into math/util.h without the global include 2021-06-02 00:26:16 -04:00
Marek Roszko cf2bb5692a Remove the wxLog calls from math/util.h for now
This was leaking windows headers and partial wx headers to 1084 compilation units......
This also means math/util.h is leaking to 1084 compilation units which seems a bit high too.
2021-06-01 18:44:22 -04:00
Jeff Young 46d746c9da Performance optimizations. 2021-06-01 23:11:54 +01:00
Tomasz Wlostowski 2d8264124d geometry: SHAPE_LINE_CHAIN::PathLength() now can accept the maximum index of the segment to calculate the length to 2021-05-29 00:13:24 +02:00
Tomasz Wlostowski 7553b7b092 geometry: add minimum distance threshold parameter to SHAPE_LINE_CHAIN::Find()/FindSegment() 2021-05-29 00:13:24 +02:00
Tomasz Wlostowski b3fb7190df geometry: SEG::Contains() should use Distance(), not SquaredDistance() for correct rounding 2021-05-29 00:13:24 +02:00
Tomasz Wlostowski e7fe8c4ddb geometry: rework SHAPE_LINE_CHAIN::Intersect() to explicitly indicate touching vertices and remove references to SEGs from INTERSECTION structure 2021-05-29 00:13:24 +02:00
Jon Evans f30ebbde33 Fix accuracy of tuning path calculation when measuring arcs
Fixes https://gitlab.com/kicad/code/kicad/-/issues/8401
2021-05-10 21:22:51 -04:00
Jon Evans 715c61ac9f PNS: Fix yet more arc edge cases
Fixes https://gitlab.com/kicad/code/kicad/-/issues/8150
2021-04-12 19:59:55 -04:00