Commit Graph

658 Commits

Author SHA1 Message Date
Seth Hillbrand 0a55ca5e96 Add standard ToString representation of hash 2024-06-25 18:34:57 -07:00
Seth Hillbrand a9d9d7ac06 Rearrange VERTEX and VERTEX_SET to please MSW/Apple 2024-06-25 18:04:53 -07:00
Seth Hillbrand 4fff28220e Extract common code into VERTEX_SET mixin
The VERTEX_SET is useful when we need to quickly find elements that are
close to each other.  Extracting to a mixin keeps the code from
diverging between implementations and simplifies that maintenance.
2024-06-25 12:19:56 -07:00
Seth Hillbrand 3c88b1ebc7 Suppress fallthrough warnings 2024-06-25 12:18:44 -07:00
Alex Shvartzkop 43be7491ff Add default constructor to MMH3_HASH. 2024-06-25 01:19:55 +03:00
Alex Shvartzkop bee70bca7f Fix redefinition error in mmh3_hash.h. 2024-06-25 01:15:47 +03:00
dsa-t cb41b53ab7 Use MurmurHash3_x64_128 (MMH3_HASH) for polygon checksum.
Improves performance when moving footprints.

See https://gitlab.com/kicad/code/kicad/-/issues/18148
2024-06-24 21:19:43 +00:00
Alex Shvartzkop ec271c20db Slightly optimize SEG::NearestPoint. 2024-06-20 04:25:33 +03:00
Marek Roszko 7c35139505 std::sqrt is not constexpr until C++26 2024-06-19 07:34:58 -04:00
Seth Hillbrand cde153c75f Avoid some overflows in KiROUND 2024-06-18 21:37:00 -07:00
Seth Hillbrand bcf6b620a8 Large rework of BEZIER_POLY
Add direct handling of quadratic beziers to save compute time and number
of points.  Update cubic interpolation to reduce number of points
generated for a given smoothness

Cache data on open and used cached data to avoid multiple re-calcs

Remove minimum line length and number of segments and replace with
standard max error level.  Allows us to specify the tolerance of bezier
interpolation
2024-06-18 17:55:41 -07:00
Seth Hillbrand e3231e6996 Rework VECTOR2D promotion rules
VECTOR + scalar = vector type (KiROUND when VECTOR is integral and
scalar is float)
VECTOR + VECTOR = common type vector

Implemented with concepts in template rules - SWIG compatible
2024-06-15 13:41:07 -07:00
Seth Hillbrand f7450e5b37 Fix SWIG compile
SWIG doesn't like a lot of the new C++20 elements, so fall back to basic
cast that should get almost every case
2024-06-14 17:41:05 -07:00
Seth Hillbrand 6df16d053e Add specialization for unsigned scalar add/sub
Adding/subtracting an unsigned scalar to a signed vector should maintain
the same signed vector

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18212
2024-06-14 17:27:59 -07:00
Alex Shvartzkop 9d0ee029bc Add a upper >= lower check to Clamp.
Similar to std::clamp.
2024-06-12 23:05:33 +03:00
Alex Shvartzkop e49d233923 Move BOX2I_MINMAX to separate header. 2024-06-12 23:05:33 +03:00
Seth Hillbrand 9d9028c979 Handle unsigned VECTOR2 casts
The previous overflow handling code casted the int_min value into an
unsigned, meaning that the min value and max value were almost the same,
clamping the output to unreasonable values.

Updated code handles floating points first, then does integer casting
through int64_t
2024-06-10 12:40:01 -07:00
Alex Shvartzkop 76b2741a92 Make sure to add start points to arcs in TransformOvalToPolygon.
Otherwise the long line segments can be non-parallel to the centerline.

This was the root cause of the slowdown in https://gitlab.com/kicad/code/kicad/-/issues/18156

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18156
2024-06-09 20:04:27 +03:00
Seth Hillbrand 31a0652c58 Force VECTOR2 templates to use standard promotion rules
This forces the operators -, +, * to use standard promotion rules when
operating on vectors of two different types.  Previously, this depended
on the order in which the operator was called, so subtracting a VECTOR2D
from a VECTOR2I could have a different result than negating the result
of subtracting the same vectors in the opposite order
2024-06-07 15:32:07 -07:00
Seth Hillbrand 08f181115b Use KiROUND for consistency
Ensure that it is clear we are rounding to nearest point
2024-06-04 08:55:42 -07:00
Seth Hillbrand 590bd6237d Fix off-by-one error in distance check for arcs 2024-06-03 16:29:06 -07:00
Seth Hillbrand e8c96a8a20 Fixups for a9ae86ee
Correcting a couple mistakes and clarifying rounding
2024-05-31 17:31:50 -07:00
Seth Hillbrand 382477c622 Fix sin/cos fixed values 2024-05-31 17:10:36 -07:00
Seth Hillbrand 2f9b10e379 Revert "Add additional 45° shortcuts for sin/cos"
Needs more testing

This reverts commit e83ca5e91d.
2024-05-31 14:40:10 -07:00
Seth Hillbrand e83ca5e91d Add additional 45° shortcuts for sin/cos 2024-05-31 13:27:52 -07:00
Seth Hillbrand a9ae86eefd Cleanup geometry functions
Added Distance(VECTOR2) function that returns a double.  Removed
superfluous EuclideanNorm, GetLineLength, integer constructor for
EDA_ANGLE (this promotes to double in the CTOR), DistanceLinePoint and
HitTestPoints

Also extended the size for arc calculations that get distances to center
points to avoid overflow
2024-05-31 12:26:37 -07:00
Seth Hillbrand 75ab3d9e8b Handle arcs dp coupling
Calculate coupled arcs and spacing

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17967
2024-05-30 16:11:12 -07:00
Seth Hillbrand 429625e311 Unify SHAPE_ARC clockwise calc.
We don't really need the extra angle calculations
2024-05-30 14:19:57 -07:00
Jon Evans 81efc7778a Fix bad clearance logic in cecc1a2f
(cherry picked from commit a1cd73e730)

Co-authored-by: Jon Evans <jon@craftyjon.com>
2024-05-23 15:21:40 +00:00
Jon Evans 5b3b0ff836 Use true arc collision for segment<>arc
Using an approximation here results in different collision
results for segment<>arc than point<>arc, which
can cause odd behavior in the router.
2024-05-23 08:56:10 -04:00
Seth Hillbrand 819bdf4372 Fix qa failure 2024-05-21 16:26:00 -07:00
Seth Hillbrand 4a800adffc Avoid int overflow in collisions
When calculating arc collisions, avoid overflowing the integer distance,
which gives a false nearest point

(cherry picked from commit 0a227ea916)
2024-05-21 09:34:45 -07:00
Seth Hillbrand f22c904352 Ensure that arc closest positions are matched
We switch from squared to absolute calcualtion when calling into the arc
collision so be sure to catch the new positions and distances

(cherry picked from commit 160a493885)
2024-05-21 09:34:45 -07:00
Seth Hillbrand 8147527437 Optimize SHAPE_ARC collisions
Handle arcs that are actually circles

Ensure that we get a good clearance value even inside arcs
2024-05-21 09:34:45 -07:00
Seth Hillbrand 57c0953c39 Return closest point on line-circle intersection
Don't only look for the segment endpoints when asking the closest point.
If we have a collision, we need to get the collision point
2024-05-21 09:34:45 -07:00
Seth Hillbrand 5e5741edd3 Minor optimizations
Most of the lines in KiCad are on 45° angles.  We can avoid sqrts by
recognizing that this implies the x/y values are the same.  Therefore,
the length of the hypotenuse is sqrt(2) * x.
2024-05-16 11:50:48 -07:00
John Beard fa7e842c8c Rework item distribution
This splits the tool into two separate tools: by center and
by even gaps. Previously, this was automatically decided, based on
if the items could have any gaps between them. This was unintuitive
as it would appear to arrange by centre point sometimes but not others.
When items aren't all the same width, the results can then be very
different, based only on the starting positions.

The new behaviour is to have a dedicated tool for each, which echos
how graphical programs like Inkscape manage this.

The by-gaps method is then extended to work for overlapping items
(when items overlap, the overlaps are made equal). The logic is
centralised in kimath/geometry, and some QA is added. This should
make it easier to extend to eeschema, for example.

This also (attempts to) address some rounding issues which could
cause minor, but compounding, errors to build up along the list
of items.

Also, fix bugs in the collection filtering - previously items
like markers were filtered out only after the selection size
was used to compute the gaps between items.
2024-05-05 03:35:09 +08:00
Seth Hillbrand 022dce2d1b Fix out of bounds access opportunity 2024-05-02 15:12:43 -07:00
Seth Hillbrand 339cf3f2e2 Fix simplify routine for last segment
The last segment of a track could be removed when the iterator does not
correctly loop.  Keeping the ll within bounds and checking for
equivalency instead of comparison works for last point
2024-04-30 16:11:20 -07:00
Seth Hillbrand 8b5564629a Optimize TestSegmentHitFast
Check for co-linear points (common occurence) before using expensive
EuclideanNorm
2024-04-29 17:48:32 -07:00
Seth Hillbrand 9e83a7bcb3 Update SHAPE_LINE_CHAIN::Simplify to better handle small diff
When simplifying, a small difference in successive points would allow a
larger difference than aMaxError to be removed.  This change checks the
intermediate points during removal to ensure we don't get overzelous
2024-04-29 17:48:32 -07:00
Jeff Young c59ed0bbb7 Flip symbol editor's Y axis to match other editors. 2024-04-27 13:47:56 +01:00
Alex Shvartzkop cf6d30706b More clang build fixes. 2024-04-23 21:50:22 +03:00
Alex Shvartzkop 124b511037 Fix build on clang. 2024-04-23 21:44:55 +03:00
Alex Shvartzkop b1180d9377 Fix some warnings. 2024-04-23 16:34:07 +00:00
Alex Shvartzkop 865e3a9f3c Improvements when working closer to 32-bit integer limits.
- Changes BOX2 size to extended coordinates.
- Adds BOX2ISafe to construct a BOX2I that will fit in int32.
- Adds more checks.
- Safer computations.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17670
2024-04-23 16:34:07 +00:00
Alex Shvartzkop 5e70883ef6 Add self-intersection check algo for arcs in SHAPE_LINE_CHAIN. 2024-04-23 19:25:23 +03:00
Alex Shvartzkop fcdaa4a59e Cache center point and radius along with BBox in SHAPE_ARC. 2024-04-23 19:25:23 +03:00
Jeff Young e8be782687 Mostly clean-up, but also bug fixes with bounding boxes. 2024-04-22 11:16:14 +01:00
Seth Hillbrand 59f99d9a6a Re-add routine to remove duplicate points
The router needs to elimitate duplicate points but keep colinear
segments.  This re-creates the partial routine from the old Simplify()
function

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17582
2024-04-10 17:25:58 -07:00