Commit Graph

328 Commits

Author SHA1 Message Date
Jeff Young 9f151025b3 Fix typo found by dsa-t.
(cherry picked from commit 7e97dc6974)
2022-10-21 11:14:05 +01:00
Jeff Young 3213ea582d Avoid trying to draw empty pads.
Fixes https://gitlab.com/kicad/code/kicad/issues/12605

(cherry picked from commit e866dfe137)
2022-10-19 14:38:40 +01:00
Jeff Young 56f58cf53f Manual cherry-pick of 6ed3618ce5. 2022-10-19 13:49:53 +01:00
Jeff Young 9cb6df9c38 Don't crash on empty SHAPE_LINE_CHAINs.
Fixes https://gitlab.com/kicad/code/kicad/issues/12407

(cherry picked from commit fc74de81fb)
2022-09-28 13:30:04 +01:00
Seth Hillbrand b324abefe5 Handle cases where Simplify removes all outlines
This could theoretically happen for a fully degenerate polygon

Fixes https://gitlab.com/kicad/code/kicad/issues/12120

(cherry picked from commit 5a37211fdb)
2022-09-06 10:42:02 -07:00
Roberto Fernandez Bautista f92d25e00b Fix SHAPE_LINE_CHAIN::Simplify() when there are only 3 points in the chain
We weren't updating m_shapes properly.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/11695

(cherry picked from commit 1fa1b44d02)
2022-08-19 20:58:28 +01:00
Seth Hillbrand 675a5a6e7b Fix simplify routine
The change in c9c31fcbc2 missed a number of cases.  This reverts back to
the system as it existed before 2be352b9f9
but using the revised method of determining A-B-C distance and avoiding
resizing the arrays
2022-08-01 09:48:29 -07:00
Seth Hillbrand c9c31fcbc2 Don't resize vectors in hot loops
Fixes a slowdown caused by erasing elements from the middle of a vector
during a hot loop in SHAPE_LINE_CHAIN::Simplify().  This gets called
quite a bit when loading boards and updating lines, so it needs to be as
fast as possible

Fixes https://gitlab.com/kicad/code/kicad/issues/12115
2022-07-31 12:48:25 -07:00
Alex ee4e4d0773 Don't recalculate constants at every call in isqrt.
(cherry picked from commit 27869b1a37)
2022-07-29 08:55:43 -07:00
Seth Hillbrand df9cf0a0c3 Fix crash in PNS walkaround
Placing via in walkaround mode and colliding with an arc triggered an
unneeded assertion.

Also fixes the bad assertion format that did not receive strings
2022-07-28 09:36:31 -07:00
Alex 6d26e8e3e8 math: Use intrinsic functions for 64-bit rescale on MSVC.
(cherry picked from commit c107abe247)
2022-07-16 18:05:35 +00:00
Seth Hillbrand 95fcf53353 Handle basic rounding error in schematic import
The fractional part of Altium schematic units is an integer number of
1/10000 mil segments, which is 2.54 nm.  The internal unit of eeschema
is 10 nm, so each fractional unit in Altium is 0.254 base eeschema
units.  To be consistent with
cf33cfcad1
we round to the nearest 10nm for each element

Fixes https://gitlab.com/kicad/code/kicad/issues/11742

(cherry picked from commit 6fef054c51)
2022-07-07 11:14:25 -07:00
Tomasz Wlostowski 2be352b9f9 geometry: more robust colinearity test in SHAPE_LINE_CHAIN::Simplify()
We now test the midpoint (B) of the 3 consecutive polyline points (A, B, C), since (assuming the angle between AB and BC is > 90 degrees) AC is always longer than
AB or BC. This minimizes the distance computation rounding error (in the previous algorithm, taking the point C for colineraity test) if AB is short and BC is very long, the test would
often fail due to rouding error in projection/line distance computation


(cherry picked from commit 3aed13278d)
2022-06-08 16:13:15 +00:00
Tomasz Wlostowski 8afb8190af geometry: use dedicated 64-bit integer square root for distance computations
Guarantees 1 LSB error, while the C++ double type has 55 mantissa bits (meaning for sqrt(X) >~ 2^22.5) the error is not guaranteed.


(cherry picked from commit e6ebc2b9b9)
2022-06-08 16:12:59 +00:00
Seth Hillbrand 2c2f69d05c Initialize area check
Ensure that the max_poly set is zero before using

(cherry picked from commit 2a9d7314ca)
2022-05-26 08:20:15 -07:00
Seth Hillbrand 1fe956c069 Handle hand-drawn holes in unfracture
We can't know that all holes will be ccw when entering unfracture.
Instead, we set the largest polyline to be the outline and the others to
be the holes.
2022-05-25 13:19:07 -07:00
jean-pierre charras c07ac8b3db Gerbview: seriously speed up the calculation time to draw polygons on OpenGL.
Mainly CacheTriangulation() was creating triangles using partition mode.
But this mode is optimized for Pcbnew and Gerbview and different internal units.
Now CacheTriangulation() is used in no partition, much faster in GERBVIEW_PAINTER.
From Master branch
2022-05-13 18:33:53 +02:00
dsa-t fdfe5a813e Clamp cursor to limits of coordinates representation
Also improves large distance handling.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/8846

(cherry picked from commit 68655540eb)
2022-04-04 13:38:50 -07:00
Seth Hillbrand 207820e112 Avoid duplicate points in trapezoid pads
Duplicate points can be either positive-facing or negative facing, so
test absolutes

Fixes https://gitlab.com/kicad/code/kicad/issues/11025
2022-03-22 13:30:22 -07:00
Jeff Young 0070a4686e Cherry-pick the short-arc-is-really-a-segment fix from master.
Fixes https://gitlab.com/kicad/code/kicad/issues/11119
2022-03-16 15:15:15 +00:00
Jeff Young 53bd87d792 Performance fixes for the board from hell....
(cherry picked from commit e4b56ab7f1)
2022-03-16 15:14:51 +00:00
Seth Hillbrand 9ca35cbcee Rework of a24cdcb3f0
Inflate with linked holes needs to account for fractured polygons,
otherwise inflating with positive value will create rounded divots where
overlapping fracture lines meet and inflating with negative value will
create spaces between fracture lines.

Calling Simplify before Inflate takes an inordinate amount of time as
the Clipper healing routine is rather slow.  Our own Unfracture is meant
to heal the results of our Fracture routine and works much more quickly.
After healing, we still call the Simplify routine
2022-03-10 09:14:13 -08:00
Seth Hillbrand a24cdcb3f0 Always return simplified polygons
Clipper can handle complex input polygons but we will sometimes struggle
dealing with outputs from the inflate routine that have degenerate or
overlapping points.  Calling Simplify after the inflate keeps our
polygons easier to handle

Fixes https://gitlab.com/kicad/code/kicad/issues/11036
2022-03-09 16:19:15 -08:00
Seth Hillbrand a940607524 Adds uncertainty propagation to center point calc
Since we use center points to move back and forth for angle and
adjustments, we want to ensure that our center point is stable.

Rounding using integers introduces a 0.5 int uncertainty in each
measurement.  These are combined together multiple times to calculate
the center point, which combines the uncertainty.  Propagating the
uncertainty to the final calculation allows us to assign a range of true
values and pick the value that is most likely the correct value.

Fixes https://gitlab.com/kicad/code/kicad/issues/10739

(cherry picked from commit ed7222b1e7)
2022-03-08 10:34:41 -08:00
Tomasz Wlostowski 680163f8a8 Cherry-pick commits from Master and about SVG import:
*Fixes in the SVG import polygon postprocessing:
- don't drop subsequent polys when a non-filled primitive is imported 'in between'
- fix missing holes (also related to the interleaving of stroke and filled shapes, depending on the software that wrote the SVG file)

*GRAPHICS_IMPORTER_BUFFER: forgot to store the indices of the paths belonging to a compound shape

*pcbnew: GRAPHICS_IMPORTER can now recognize multi-path shapes (and postprocess polygons with holes into Kicad-compatible fractured polysets)

*SHAPE_POLY_SET: polysets can now be built from a bunch of arbitraily ordered oriented outlines.
Used by the SVG hole support

*SVG_IMPORT_PLUGIN: enable postprocessing of polygons with degeneracy and holes

*pcbnew: SVG importer support for even-odd fill rule
2022-02-21 10:50:05 +01:00
Jeff Young 9c48707c88 For Coverity. 2022-02-17 14:30:47 +00:00
Jeff Young ff21a16f7d Formatting. 2022-02-17 14:30:47 +00:00
Wayne Stambaugh 54f91a0221 Wide characterize libs and bitmap2component source. 2022-02-09 09:01:53 -05:00
Seth Hillbrand 8fc831cbc2 Validate arc output when editing
Handles checking output of the arc to ensure we don't end up generating
an invalid arc.  Also keeps the limit of the arc angle to be (360,360)
excluding 0.

Fixes https://gitlab.com/kicad/code/kicad/issues/10070
2022-02-06 17:18:04 -08:00
Seth Hillbrand 857683d372 Remove unneeded distance calc 2022-01-18 15:58:20 -08:00
Marek Roszko 1e05732f55 Add std::hash specialization for VECTOR2I
(cherry picked from commit 589a03afcd)

Fixes https://gitlab.com/kicad/code/kicad/issues/10275
2022-01-05 20:32:46 -08:00
Jeff Young 1b033d56a7 Improve clean up tracks & vias algorithm for neck-downs.
Fixes https://gitlab.com/kicad/code/kicad/issues/10098

(cherry picked from commit d5a5928e5a)
2021-12-23 17:01:39 +00:00
Roberto Fernandez Bautista 4de4347baa SHAPE_ARC::Collide( aSeg ) must check segment end points as candidates
The edge case is when the segment is completely contained inside the arc
(This partially reverts b4835c8208 and
adds the missing test cases)
2021-12-14 16:14:56 +00:00
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