7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-26 00:26:09 +00:00
Commit Graph

876 Commits

Author SHA1 Message Date
John Beard
e2370c6e45 BEZIER: Avoid some copying in the ctor 2024-09-25 22:17:33 +01:00
John Beard
aea42a5cdf Pcbnew: handle connected copper circle points
Fixes: https://gitlab.com/kicad/code/kicad/-/issues/18774
2024-09-25 12:28:43 +01:00
John Beard
95beedb612 Dogbones: add slots for acute angles
It's actually not as hard as I thought, though
surely has wierd edge cases which users might need to
handle manually.
2024-09-22 13:45:19 +01:00
John Beard
a5e6f70122 Dogbone: handle small mouths even better
Including floating point roundoff, which can bite
for rectangles.
2024-09-20 10:57:07 +01:00
John Beard
671ecdf13c Dogbone: correct small mouth warning
It has to fit the cutter diameter, not the radius!

Also you can use SHAPE_ARC as a generic arc object.
2024-09-20 10:37:29 +01:00
John Beard
8fdb6d6e88 Feature: Exact item offset tool
This is a little bit like the bounding hull tool, but the
output is "exact" and it only supports the most common
source items.

By 'exact', this means that rounded corners are real arc
segments rather than polygonal approximations. Obviously,
this is rather tricky in the general case, and especially
for any concave shape or anything with a bezier in it.

Envisioned main uses:

* Creating courtyard and silkscreen offsets in footprints
* Making slots around line or arcs.

The one thing that it does not currently do, but which it might
plausibly do without reimplementing Clipper is convex polygons,
which would bring trapezoidal pad outsets for free. But that
is a stretch goal, and bounding hull can be used.
2024-09-19 06:35:43 +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
John Beard
99e1869987 Fix build: use same signature for alg::lexicographical_compare_three_way as std::
This makes it clearer that it is a polyfill-type affair
and make it easier to swap for the std:: one when the
compiler support is guaranteed.

Also avoid double underscores in parameter names,
as well as underscore-capital latter as they are reserved.
2024-09-18 06:56:03 +01:00
John Beard
f6a693475f BOX2: Add a KiROUND specialisation for BOX2D -> BOX2I 2024-09-11 22:35:35 +01:00
John Beard
5e9aba5555 Remove commented-out VECTOR2 dtor
It's been commented out for 11 years, so take the
opportunity while the header is being touched.
2024-09-11 22:35:35 +01: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
72e48aed52 Trigo: Add a GetRotated function to get a rotated VECTOR2I
This makes it easier to use value semantics and consts when
constructing geometry.
2024-09-11 22:08:36 +01:00
John Beard
a3a3f7648e Break ERROR_LOC out to its own header
Having this in geometry_utils.h means that touching
that header affects nearly every file, as this type is used
in EDA_SHAPE, BOARD_ITEM and SHAPE.
2024-09-11 22:08:36 +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
80abdee90d Make hash constexpr
Probably doesn't add much directly, but it documents and
enforces the implied contract that the hash is fixed,
and could be used for, say, compile time hash tables.
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
538b055c98 Remove ambiguity in MM3_HASH ctor 2024-09-06 10:31:16 -07:00
Seth Hillbrand
5ba50c26a9 Update embedded files hash to use Murmur3
SHA256 is fine for one-offs but for large libraries where we might be
running the hash on hundreds of files, the speed difference is
appreciable.  We don't require crytographic hashing, just a check that
the original file hasn't been corrupted so Murmur3 satisfies our basic
requirement.
2024-09-06 09:57:23 -07: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
Alex Shvartzkop
ebb418f22b Avoid some potential integer overflows in circle.cpp. 2024-08-29 00:35:38 +03: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
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
c7fa61cd94 GTK: Enable IME cancellation on canvas focus
This means that it doesn't start consuming hotkeys for
IME composition in the main canvas on Linux.

Text boxes in dialogs and the property manager, for example,
still receive IME composition.

Relates-To: https://gitlab.com/kicad/code/kicad/-/issues/9882
2024-08-14 14:28:54 +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
Seth Hillbrand
c0d8d87364 Cleanup GetClampedCoords
Previous function would drop some KiROUND calls due to inability to
parse the () operator.  Using the _v template gets the constexpr check,
allowing us to avoid the conditional while running
2024-07-25 21:06:04 +02:00
Seth Hillbrand
368d98ef9e Add optional quiet param to KiRound 2024-07-25 21:05:49 +02:00
Seth Hillbrand
69849ba3ca Replace custom Clamp with std::clamp
Fixes bug in parser that had the elements in the wrong order due to our
custom version not matching the standard order
2024-07-25 19:17:17 +02:00
Seth Hillbrand
1be2d7f8b7 Optimize SEG::SquaredDistance
We don't actually need the closest point to figure out the distance.
Since this calculation is used everywhere, we see some non-negligible
gains by picking the length along the projection
2024-07-25 05:21:06 +02:00
Seth Hillbrand
433677fc21 Replace std::lexicographical_compare_three_way
On platforms that don't yet support the std:: version, we implement our
own, possibly slower, version of the 3-way compare
2024-07-24 18:03:29 +02:00
Seth Hillbrand
6ed537753c Avoid losing the last point when simplifying
line chains that are not closed should avoid simplifying between
beginning and end points.  Make sure that we keep the finishing point
for these chains

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

(cherry picked from commit b71eb1186f)
2024-07-20 13:03:44 -07:00
Alex Shvartzkop
63eac0382c Add bounds checking when slicing SHAPE_LINE_CHAIN from the middle of the last arc.
(and said arc is the last shape in the chain)

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18391
2024-07-19 01:56:44 +03:00
Alexander Rauth
9177e62718 correct polygon area calculation
When calculating a part of the polygon area and thus ending the polygon
at the specified vertex aEnd we  need to calculate and add the area below
the needed additional line from "aEnd" to "this" to close the resulting
partial polygon. As in this case VERTEX* p references "aEnd" after exiting
the do-while loop the correction  term in the if-statement was always
evaluated to zero. Change "aEnd" to "this" in the correction term.
2024-07-11 10:09:54 -07:00
Seth Hillbrand
77b1d367df Fixup copper connection wires
Use better check for ears, avoiding fracture points.
Be careful when insterting spikes to avoid changing indices for future
polys
2024-07-10 21:48:37 -07:00
Seth Hillbrand
845130ba9e ADDED: pcbnew fill avoids kissing fills
Previously, fills could end up just barely touching, leading to DRC
errors even if there was enough room to fill the remaining space.  This
was due to how we shrink/expand the zones to remove small features.  By
adding a zero-width line between points that should be connected, we
expand back to the correct width.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/14130
2024-07-10 18:34:41 -07:00
Jeff Young
0682987eb9 Cleanup atrophied code. 2024-07-08 14:27:25 +01:00
Alex Shvartzkop
8532e1f9ec Optimize optimizeZoneToZoneAnchors.
Only do tests between 3 polygon pairs with closest bbox centers.
Only do tests between 5 parts of line chain pairs with closest bbox centers.

Gets OptimizeRNEdges down to 350 ms

See https://gitlab.com/kicad/code/kicad/-/issues/18148
2024-07-03 16:27:03 +00:00
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