From 468c27735707362d94cd3becf816cc143cb1311c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 21:09:47 -0800 Subject: [PATCH] Fix linesweeper numeric bounds and sweep work accounting --- vendor/linesweeper/README.craft.md | 3 + vendor/linesweeper/SOURCE.json | 27 ++--- vendor/linesweeper/docs/sweep.typ | 8 +- vendor/linesweeper/src/arbitrary.rs | 18 ++- vendor/linesweeper/src/curve/line.rs | 37 +++++- vendor/linesweeper/src/curve/mod.rs | 74 +++++++----- vendor/linesweeper/src/geom.rs | 60 +++++++++- vendor/linesweeper/src/lib.rs | 53 ++------- vendor/linesweeper/src/order.rs | 105 ++++++++++++++++- vendor/linesweeper/src/position.rs | 41 ++++++- vendor/linesweeper/src/segments.rs | 60 ++++++++-- vendor/linesweeper/src/sweep/output_event.rs | 47 +++++++- vendor/linesweeper/src/sweep/sweep_line.rs | 67 +++++++++-- vendor/linesweeper/src/topology.rs | 114 +++++++++++++++++-- vendor/linesweeper/src/treevec.rs | 4 +- 15 files changed, 579 insertions(+), 139 deletions(-) diff --git a/vendor/linesweeper/README.craft.md b/vendor/linesweeper/README.craft.md index d265e25ee7..d3c6f7f0f6 100644 --- a/vendor/linesweeper/README.craft.md +++ b/vendor/linesweeper/README.craft.md @@ -15,6 +15,9 @@ holds `upstream_revision`. `local_patches` describes each local change. | File | Change | |---|---| +| `src/arbitrary.rs`, `src/geom.rs`, `src/position.rs`, `src/curve/mod.rs`, `src/curve/line.rs` | Numeric helpers reject invalid float bounds and retain extreme quadratic roots, conservative slope bounds, small affine offsets, exact mapped endpoints, and finite midpoint heights. Disjoint height ranges have an empty curve order. | +| `src/order.rs`, `src/sweep/output_event.rs`, `src/topology.rs` | Mutable reversed comparisons retain edits until eviction or an arena change. Output events use total floating-point ordering, including NaNs and signed zero. Bounded output checks merged winding storage and rejects size overflow. | +| `src/segments.rs`, `src/sweep/sweep_line.rs`, `src/treevec.rs`, `docs/sweep.typ` | An iterator panic rolls back a batch's unentered suffix. Sweep work counts actual tree-search predicates. Ordinary touches do not hash intervening spans. Reverse iterators use the shared inline stack. The crossing-height proof requires finite denominator additions. | | `src/lib.rs`, `src/topology.rs`, `src/segments.rs` | `binary_op_accuracy` returns the checked automatic accuracy, including for open paths. `binary_op` and `Topology::from_paths_with_automatic_limits` compute accuracy from monotonic pieces before preparing sweep metadata, then sort accepted input once. The accuracy uses the retained segments' coordinate scale, including their curve control points. `automatic_accuracy_checks_control_point_scale` checks both argument orders and a wider-feature control. `automatic_accuracy_ignores_discarded_horizontal_handles` checks that a retraced horizontal curve does not raise the floor. `automatic_boolean_reuses_the_prepared_segment_events` uses the shared test comparison counter to check one input sort for ordinary and bounded operations. `automatic_accuracy_does_not_sort_events`, `automatic_feature_rejection_does_not_sort_events`, and `automatic_accuracy_does_not_prepare_sweep_metadata` check that accuracy queries and rejected features do not sort events or prepare sweep metadata. `automatic_accuracy_accepts_open_paths` checks an open accuracy query and the topology constructor's closure check. | | `src/curve/line.rs` | Vertical lines keep their exact endpoint x coordinate. `coincident_vertical_lines_keep_their_exact_x` compares coincident lines at x = 0.1 with tolerance 1e-18. | | `src/sweep/sweep_line.rs` | Sweep-order checks accept an `Ish` interval at its boundary, including a zero-height touch. The `invalid_order` test checks a reversed crossing before, at and after that boundary. `work_limit_counts_position_searches_by_their_probes` uses 100 and 200 rectangles with `slow-asserts`, and 2,000 and 4,000 otherwise. Both configurations check the same work-count growth and work-limit behavior. | diff --git a/vendor/linesweeper/SOURCE.json b/vendor/linesweeper/SOURCE.json index 37d8e54ace..d33f27f53a 100644 --- a/vendor/linesweeper/SOURCE.json +++ b/vendor/linesweeper/SOURCE.json @@ -8,6 +8,7 @@ "upstream_revision": "824b0791a750f7b27b8edcbb6c6244d0e629875e", "upstream_directory": "", "local_patches": [ + "Numeric helpers reject invalid float bounds and retain extreme quadratic roots, conservative slope bounds, small affine offsets, and exact mapped endpoints. Curve comparisons return an empty order for disjoint height ranges. Mutable reversed cache entries retain edits until eviction or an arena change. Output events have total floating-point ordering, including NaNs and signed zero. Bounded topology output accounts for merged winding storage and rejects size overflow. Batch insertion rolls back its unentered suffix if its iterator panics. Sweep work counts actual tree-search predicates; ordinary touches do not hash the intervening span. Reverse iterators use the shared inline stack. The crossing-height proof explicitly assumes finite denominator additions.", "`binary_op_accuracy` in `src/lib.rs` returns the checked automatic accuracy, including for open paths. `binary_op` and `Topology::from_paths_with_automatic_limits` in `src/topology.rs` compute accuracy from monotonic pieces before preparing sweep metadata, then sort accepted input once. The accuracy uses the retained segments' coordinate scale, including their curve control points. `automatic_accuracy_checks_control_point_scale` checks both argument orders and a wider-feature control; `automatic_accuracy_ignores_discarded_horizontal_handles` checks that a retraced horizontal curve does not raise the floor. `automatic_boolean_reuses_the_prepared_segment_events` uses the shared test comparison counter from `src/segments.rs` to check one input sort for ordinary and bounded operations. `automatic_accuracy_does_not_sort_events`, `automatic_feature_rejection_does_not_sort_events`, and `automatic_accuracy_does_not_prepare_sweep_metadata` check that accuracy queries and rejected features do not sort events or prepare sweep metadata. `automatic_accuracy_accepts_open_paths` checks an open accuracy query and the topology constructor's closure check.", "Sweep-order checks in `src/sweep/sweep_line.rs` accept closed `Ish` intervals, including zero-height touches. The position-search work test uses 100 and 200 rectangles with `slow-asserts` and keeps 2,000 and 4,000 without that feature; both configurations retain the same work-count and work-limit assertions.", "`SegmentOrder::position` finds a segment by binary search over a key on each sweep-line entry instead of scanning the line. The order of the line and the index returned do not change.", @@ -103,7 +104,7 @@ { "path": "benches/linebender_logo.rs", "source_sha256": "d10867f43439d37f0e1da5d30eaed9ab3bfbe655ed47212f65dc20ab4db65cb3", "source_git_blob": null, "sha256": "d10867f43439d37f0e1da5d30eaed9ab3bfbe655ed47212f65dc20ab4db65cb3" }, { "path": "benches/painted_dreams.rs", "source_sha256": "073008db93840d380710e13ed3ae38e08cb823f10c12e5f838dac1ccf37eaecf", "source_git_blob": null, "sha256": "073008db93840d380710e13ed3ae38e08cb823f10c12e5f838dac1ccf37eaecf" }, { "path": "benches/synthetic.rs", "source_sha256": "7ce59bef2e1c4f28b00cb89feb15bc71ca4b098a8d27e7b02ea699aca9bcc810", "source_git_blob": null, "sha256": "7ce59bef2e1c4f28b00cb89feb15bc71ca4b098a8d27e7b02ea699aca9bcc810" }, - { "path": "docs/sweep.typ", "source_sha256": "4766082c8672a7bb4356b5581043489c13b4e3fb8931ba3a5f0a473fab0172f3", "source_git_blob": null, "sha256": "92acd363839a2af87750f1459fb74d40867bc08a4e6283e6f0608447d15d6d7b" }, + { "path": "docs/sweep.typ", "source_sha256": "4766082c8672a7bb4356b5581043489c13b4e3fb8931ba3a5f0a473fab0172f3", "source_git_blob": null, "sha256": "679ddf9c11eec7883661bde12c14fd0dce3eed634d690a1945fb4386dfad70f4" }, { "path": "examples/boolean_op.rs", "source_sha256": "3b38a1ccda7e736cce4b191a3a45ab4824c4c365190e3eb637b2fb39b5996c9f", "source_git_blob": null, "sha256": "7b4f4fc94d3b1fd9b9ee06622b2e8c38bd6c85697d21505b09765139283df576" }, { "path": "examples/bus.rs", "source_sha256": "e206a08be73899f564188052c8ecc15526b54606e52ee2935a64ce6b5723da33", "source_git_blob": null, "sha256": "cadc2829c1f4dde6948e0246286a07e0c1cf6bb71960859a3f2b77020cd84691" }, { "path": "examples/curve_metrics.rs", "source_sha256": "0db6a5327fd2119a03a9a66624fea3e04b6bbb519655667ad30487aee6c787d2", "source_git_blob": null, "sha256": "18bf2447d7338113b578964b359ee5c4f706be570721abec049ea01d13705ea1" }, @@ -112,19 +113,19 @@ { "path": "proptest-regressions/sweep/sweep_line.txt", "source_sha256": "f5311edf1c0c4d1574bb7b24ed1d1c66106d9949214014d0a8479f685938dc98", "source_git_blob": null, "sha256": "f5311edf1c0c4d1574bb7b24ed1d1c66106d9949214014d0a8479f685938dc98" }, { "path": "proptest-regressions/sweep/weak_ordering.txt", "source_sha256": "b5b183ab470399c15246457d8a1a35cafb49fee120d6777dfdd563bfdbadda52", "source_git_blob": null, "sha256": "b5b183ab470399c15246457d8a1a35cafb49fee120d6777dfdd563bfdbadda52" }, { "path": "proptest-regressions/topology.txt", "source_sha256": "49ff0b5b370f082984276d5312f03b1fc96ef0dd218f9efd7b084b11abbb9d19", "source_git_blob": null, "sha256": "49ff0b5b370f082984276d5312f03b1fc96ef0dd218f9efd7b084b11abbb9d19" }, - { "path": "src/arbitrary.rs", "source_sha256": "9c3753a40cfea2528a546295d39e0513537db5a3411a931fccea063873d95750", "source_git_blob": null, "sha256": "e7e8b418663092423f41d17d60607eaddf7834cbc4ae1ea7cd7541c603215303" }, - { "path": "src/curve/line.rs", "source_sha256": "07aebead4b0050410a3f9f28b66062b6016c115df58e2b2669470263cd352f3e", "source_git_blob": null, "sha256": "01f8d679628c4400dcee1528d426ef371213843a28745fa9e74784d1ff336e5a" }, - { "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "16189bba88d1f8c83133a2abfd231d257c73b2d43404d84d45f7bce5bdf56ba6" }, + { "path": "src/arbitrary.rs", "source_sha256": "9c3753a40cfea2528a546295d39e0513537db5a3411a931fccea063873d95750", "source_git_blob": null, "sha256": "188cca0f6b4d40539e0d5ae9b38d72a109ac297aeaac69dd43bbbafa038da17a" }, + { "path": "src/curve/line.rs", "source_sha256": "07aebead4b0050410a3f9f28b66062b6016c115df58e2b2669470263cd352f3e", "source_git_blob": null, "sha256": "d7f9c100f483eb4307f55ae5e3841cc6bb14544bbb0326f6c03c2f297e3b5e39" }, + { "path": "src/curve/mod.rs", "source_sha256": "36a8dbe96ac1d3bec307dc63b504206ec7fdfc11d10799fbb1a8990c29b8c5f2", "source_git_blob": null, "sha256": "20c73c9f08ec9967408d7acadb97e2092a13459fe1adcc68e08868d72c2f24c7" }, { "path": "src/curve/split_quad.rs", "source_sha256": "b8aae4ce7c16fa623724f667e1058130a9c7eed693b5b01e8b9e16632b8ec45f", "source_git_blob": null, "sha256": "b8aae4ce7c16fa623724f667e1058130a9c7eed693b5b01e8b9e16632b8ec45f" }, { "path": "src/curve/transverse.rs", "source_sha256": "be9c695531f4cb0fe73af13e78040b51b9476c193d84562e701aadd07b3fd06e", "source_git_blob": null, "sha256": "e1b8658f2b6e0e502bc81d16c393a16a426b6cc1572477ca809ca861fc005de9" }, { "path": "src/generators.rs", "source_sha256": "cc9f2441546db9204219294c354449809dda77dffad06fec8a30f45df01e6fef", "source_git_blob": null, "sha256": "24b25da4c07a9361b72b324564e2aaa4c2dd9f7d9a6e27dfb1cb1b3d08104edf" }, - { "path": "src/geom.rs", "source_sha256": "9878ffa6d4a13fa2c9149741c137205ca01acb626a5b9f86a3db75cf91b63a08", "source_git_blob": null, "sha256": "67437cea1121c132ec5edd0fe3d1a8384d570a0d5a28e62bc41c5150fccf4961" }, - { "path": "src/lib.rs", "source_sha256": "761c153c3b5c449569ff85c571344b9252ea64f7f0b0424fb4819041b03d13c6", "source_git_blob": null, "sha256": "e6a2fd934d4f578b7a2d8fa7f2033c6c68f13af82191d91440b6cd9efec5dcea" }, + { "path": "src/geom.rs", "source_sha256": "9878ffa6d4a13fa2c9149741c137205ca01acb626a5b9f86a3db75cf91b63a08", "source_git_blob": null, "sha256": "b80ff5363060e2e1d1603566df7c517e1881c1904201fc037ab674b59d99da8e" }, + { "path": "src/lib.rs", "source_sha256": "761c153c3b5c449569ff85c571344b9252ea64f7f0b0424fb4819041b03d13c6", "source_git_blob": null, "sha256": "c6cc6ac747eb4865378da59e79790baa1df867d7ae00ab339d39fa706a347aad" }, { "path": "src/num.rs", "source_sha256": "39ff85da50c500ce91cf6dea81aedc0dcca1db5e7d0506696dde2da118e93a2a", "source_git_blob": null, "sha256": "39ff85da50c500ce91cf6dea81aedc0dcca1db5e7d0506696dde2da118e93a2a" }, - { "path": "src/order.rs", "source_sha256": "7e5b04eae8af134abb032e995f1d3c2ac473822923dfee8d463d9ade6ffeb596", "source_git_blob": null, "sha256": "9f852574f5f5d663962129f492731b119d9feb9dba6887bf2dd6b4bc20c75343" }, + { "path": "src/order.rs", "source_sha256": "7e5b04eae8af134abb032e995f1d3c2ac473822923dfee8d463d9ade6ffeb596", "source_git_blob": null, "sha256": "316b6cc99a15fa82063ec27ef14e3cbad8c7f380c82d750cebc89953c848ac67" }, { "path": "src/perturbation.rs", "source_sha256": "fa274a822bbdf65f8e53e403eef78034dd87964b3f1d3134a064df4ec8cef9c5", "source_git_blob": null, "sha256": "5030efede9c94b5837f70f2eb3e5447dec772ea1aac3800d162d2fb26da0b929" }, - { "path": "src/position.rs", "source_sha256": "dfa70840805ecccf5b7eb6122921e46ca60c24cb7b3c17f3b55ffc2549368ab0", "source_git_blob": null, "sha256": "d6cea464a362b3e60a41a67f955ab3eb785f476198e58dce55e74ffa8294fed6" }, - { "path": "src/segments.rs", "source_sha256": "379f9455120492d237cb5a62b3fc06da018a72e2eb75bbfcd61b4cce501d9bbc", "source_git_blob": null, "sha256": "7ed68d66b693bd466f9f427120b6c86ad2b72edea6729243a2631b0672397a38" }, + { "path": "src/position.rs", "source_sha256": "dfa70840805ecccf5b7eb6122921e46ca60c24cb7b3c17f3b55ffc2549368ab0", "source_git_blob": null, "sha256": "86106cea0fe52d6421b5a53720f267271eb04027686c76955b8c77fa14fa1f43" }, + { "path": "src/segments.rs", "source_sha256": "379f9455120492d237cb5a62b3fc06da018a72e2eb75bbfcd61b4cce501d9bbc", "source_git_blob": null, "sha256": "047adf1bfa7ba73eae668d327ef49395c4b7251923799778fcb79afb0ad7a824" }, { "path": "src/snapshots/linesweeper__tests__empty_horizontals.snap", "source_sha256": "e319881853e889badf6524f19af4cd6f112e8dd71bdc516826f4463134a82244", "source_git_blob": null, "sha256": "e319881853e889badf6524f19af4cd6f112e8dd71bdc516826f4463134a82244" }, { "path": "src/snapshots/linesweeper__tests__two_squares.snap", "source_sha256": "01961e0311a5af3b8f13eb52a2a7112560c47cf86771c04e40475dc6f15a0846", "source_git_blob": null, "sha256": "01961e0311a5af3b8f13eb52a2a7112560c47cf86771c04e40475dc6f15a0846" }, { "path": "src/snapshots/linesweeper__topology__tests__diamond.snap", "source_sha256": "cfaefd620a0a3d1376861bca09cd7c658ef00a32635b88f1b259a9b39cd15502", "source_git_blob": null, "sha256": "ee40ad81bbb17f73ac710806aac9c8060e47a3843219dac82c0c0cc9ce18a412" }, @@ -137,16 +138,16 @@ { "path": "src/snapshots/linesweeper__topology__tests__square_with_double_back.snap", "source_sha256": "b6709e07eb96d1148269caa9ea39663bb432524e892fffe10f784fa44edb29e0", "source_git_blob": null, "sha256": "2223a32b4b5ce6bc701c4e816664675a74ab7db67c74f078eb2c146e8804fbfa" }, { "path": "src/snapshots/linesweeper__topology__tests__squares_with_gaps.snap", "source_sha256": "52a5e09ecd081f7ace976692a5d5e3549210441f78ad1dc25cd98a4d9d5dceb6", "source_git_blob": null, "sha256": "0d50f2771f16c5e70e9c2d19e24bae9dd6f7add9caa4a04185478ce69d5c67a8" }, { "path": "src/sweep/mod.rs", "source_sha256": "467f783e605be9c5959b10adc3ff53966ca0e95599b3b509bfacb154e82b9257", "source_git_blob": null, "sha256": "467f783e605be9c5959b10adc3ff53966ca0e95599b3b509bfacb154e82b9257" }, - { "path": "src/sweep/output_event.rs", "source_sha256": "220dc6847871ffcd0f782122b55db0a47522866892fb0fb5dd4255cea975fc83", "source_git_blob": null, "sha256": "5084b0fd79462aa64f29acffe7b777c1cb44b209f10fdbd874ed1d197a03cf05" }, + { "path": "src/sweep/output_event.rs", "source_sha256": "220dc6847871ffcd0f782122b55db0a47522866892fb0fb5dd4255cea975fc83", "source_git_blob": null, "sha256": "066cfd6a028c8494cfe2a40c0e2b44557d6e85a305d9a2e83bde0623c513c45d" }, { "path": "src/sweep/range.rs", "source_sha256": "924274de47783179f52cea99b370297e8c8d5f05500df4a6ff31e9b927dadd06", "source_git_blob": null, "sha256": "d81d938f94aecd68b2f2fd2d8c76c1f3ccb459f1b96bcac054937e1ba9b16164" }, { "path": "src/sweep/snapshots/linesweeper__sweep__sweep_line__tests__conservative_line_order.snap", "source_sha256": "236d020f646edc3ab199888fd52a0e7d9939bbb1d8b13b6fed52ce508c0e6667", "source_git_blob": null, "sha256": "236d020f646edc3ab199888fd52a0e7d9939bbb1d8b13b6fed52ce508c0e6667" }, { "path": "src/sweep/snapshots/linesweeper__sweep__sweep_line__tests__regression_position_state.snap", "source_sha256": "be9535fe81604b59e369e6e2c61a67e0203429166dd23e51cd90c644fa3e09db", "source_git_blob": null, "sha256": "be9535fe81604b59e369e6e2c61a67e0203429166dd23e51cd90c644fa3e09db" }, { "path": "src/sweep/snapshots/linesweeper__sweep__sweep_line__tests__square.snap", "source_sha256": "b35c3e6a38d5ecdd8acf315ba0b0bd6485cd8b40193fdd76bd446bdfdb6eda77", "source_git_blob": null, "sha256": "b35c3e6a38d5ecdd8acf315ba0b0bd6485cd8b40193fdd76bd446bdfdb6eda77" }, { "path": "src/sweep/snapshots/linesweeper__sweep__sweep_line__tests__square_and_diamond.snap", "source_sha256": "3f01a76fb7ff4aef0fd55fd869602d4a2b69fff1bd65632f406b275b5d6af600", "source_git_blob": null, "sha256": "3f01a76fb7ff4aef0fd55fd869602d4a2b69fff1bd65632f406b275b5d6af600" }, { "path": "src/sweep/snapshots/linesweeper__sweep__sweep_line__tests__two_squares.snap", "source_sha256": "79e3c95e563a66c0ce244125470a106a18dfe29f276b732defd305406c873c7e", "source_git_blob": null, "sha256": "79e3c95e563a66c0ce244125470a106a18dfe29f276b732defd305406c873c7e" }, - { "path": "src/sweep/sweep_line.rs", "source_sha256": "822b261f682911ea0c0370eaf17d9201a1e639b315359dcb6a3b877a229816e3", "source_git_blob": null, "sha256": "27af10727faf392f22bffd9fe2015c91233d5243fb7a96266b3ea64079cf3eab" }, - { "path": "src/topology.rs", "source_sha256": "9c9b48bc3853884425127e2d64e8ed957ba0d27e1696e2c457e95282e52d6a5b", "source_git_blob": null, "sha256": "a35ae6ead2d8d9fd7e82969a34dd595b9cf5671d92a1a7afccc23b1cd65ab548" }, - { "path": "src/treevec.rs", "source_sha256": "d88b9fbf02fa9f318560e1d483d465555f2b696ae12c00f8e4f5b71ea6779445", "source_git_blob": null, "sha256": "84fe3b5dddccb3b5c6c2897f4e9fb1dd122d29c242b0575425e5165766c9a3f9" }, + { "path": "src/sweep/sweep_line.rs", "source_sha256": "822b261f682911ea0c0370eaf17d9201a1e639b315359dcb6a3b877a229816e3", "source_git_blob": null, "sha256": "c0332f0b665fb2b37451afcbab0e96bfd7ba3e4c4db33010f8b8571e230715e4" }, + { "path": "src/topology.rs", "source_sha256": "9c9b48bc3853884425127e2d64e8ed957ba0d27e1696e2c457e95282e52d6a5b", "source_git_blob": null, "sha256": "aa95cc45cb14a18dbcf36b8153d9fbd712b783a59cafce6feccae37351831bc2" }, + { "path": "src/treevec.rs", "source_sha256": "d88b9fbf02fa9f318560e1d483d465555f2b696ae12c00f8e4f5b71ea6779445", "source_git_blob": null, "sha256": "e2ccc6bb0f936ac6c6fd09077164a7c5757edb970c1adeea54b3f2f2f2eb6e78" }, { "path": "src/typed_vec.rs", "source_sha256": "3e9a2675b8a40d8fc4df0575bd9d0d16b5604d18e9b78638dd5a612b28fc4c30", "source_git_blob": null, "sha256": "3e9a2675b8a40d8fc4df0575bd9d0d16b5604d18e9b78638dd5a612b28fc4c30" }, { "path": "tests/fonts.rs", "source_sha256": "081604ebf560a19ff0427efd9a17eaaa0a3b46ad0bf58323fd6e21b6c0764400", "source_git_blob": null, "sha256": "081604ebf560a19ff0427efd9a17eaaa0a3b46ad0bf58323fd6e21b6c0764400" }, { "path": "tests/paperjs.rs", "source_sha256": "6ff2a3178f13cde3d7304101ae592ae32b4b2734069f5fc56a532a4883d9f782", "source_git_blob": null, "sha256": "f98edbb322355ce6d2e318b73d27777cbe25413708a06429d03eddada91c7908" }, diff --git a/vendor/linesweeper/docs/sweep.typ b/vendor/linesweeper/docs/sweep.typ index 5555759a76..26cd607231 100644 --- a/vendor/linesweeper/docs/sweep.typ +++ b/vendor/linesweeper/docs/sweep.typ @@ -720,7 +720,8 @@ Next, let's analyze the computation of the $y$ intersection point. #lemma[ Suppose we have two segments $alpha$ and $beta$. Set $y_0 = y_0(alpha) or y_0(beta)$ and $y_1 = y_1(alpha) and y_1(beta)$ (these can be computed exactly). Suppose that we can compute $alpha(y)$ and $beta(y)$ to additive accuracy $epsilon$, -and assume that $beta(y_0) - alpha(y_0) >= 0$ and +and assume that the floating-point additions forming the denominator below are finite, +that $beta(y_0) - alpha(y_0) >= 0$, and $ alpha(y_1) - beta(y_1) > 16/3 (epsilon + 2 epsilon_0 M). $ @@ -802,7 +803,8 @@ Putting all this together (and handling the "chamfers" yet): // Craft patch (ratio lemma): M is a floating-point number, and the proof shows the ratio lemma's assumptions hold. #lemma[ Assume $M$ is a floating-point number, all line segments are inside the square $[-M/2, M/2]^2$, -and take $delta = 64 epsilon_0 M$. If $epsilon_0 <= 1/4$ then +and take $delta = 64 epsilon_0 M$. Assume also that the floating-point additions forming the crossing +denominator in @lem-intersection-height-error are finite. If $epsilon_0 <= 1/4$ then - We can compute $x$ coordinates of line segments to additive accuracy $delta/8$. - If $alpha$ $(3 delta)/4$-crosses $beta$, we can compute a crossing height $hat(y)$ such @@ -820,6 +822,8 @@ can compute the horizontal coordinate with error at most $(6 epsilon_0 + 4 epsil this is at most $7 epsilon_0 M <= delta/8$. This proves the first claim. For the second claim, we apply @lem-intersection-height-error with $epsilon = (6 epsilon_0 + 4 epsilon_0^2) M$. +Its denominator additions are finite by the additional assumption. The coordinate bound alone does +not imply this: each horizontal difference can be as large as $M$, and their sum can be as large as $2 M$. With this $epsilon$, $epsilon + 2 epsilon_0 M) <= 9 epsilon_0 M$ and so $16/3 (epsilon + 2 epsilon_0 M) <= 48 epsilon_0 M = (3 delta)/4$. Thus, if $alpha$ $(3 delta)/4$-crosses $beta$ then the assumptions of @lem-intersection-height-error are satisfied (and in the conclusion, $4 (epsilon + 2 epsilon_0) M <= 36 epsilon_0 M = (9 delta) /16 $. diff --git a/vendor/linesweeper/src/arbitrary.rs b/vendor/linesweeper/src/arbitrary.rs index 4cc4f00ebf..806cdc60b0 100644 --- a/vendor/linesweeper/src/arbitrary.rs +++ b/vendor/linesweeper/src/arbitrary.rs @@ -6,13 +6,13 @@ use polycool::Quadratic; use crate::geom; -/// Generate an arbitrary float in some range. +/// Generates a float between finite, strictly increasing bounds. Invalid bounds return an error. pub fn float_in_range( start: f64, end: f64, u: &mut Unstructured<'_>, ) -> Result { - if start >= end { + if !start.is_finite() || !end.is_finite() || start >= end { return Err(arbitrary::Error::EmptyChoose); } let num: u32 = u.arbitrary()?; @@ -145,6 +145,20 @@ pub fn quadratic(size: f64, u: &mut Unstructured<'_>) -> Result CurveOrder { let dy = y1 - y0; if dy.is_finite() { y0 + dy * t + } else if (0.0..=1.0).contains(&t) { + y0 * (1.0 - t) + y1 * t + } else if t < 0.0 { + f64::NEG_INFINITY + } else if t > 1.0 { + f64::INFINITY } else { - // The range is more than f64::MAX tall, so step half of it twice. - let half_step = (y1 * 0.5 - y0 * 0.5) * t; - y0 + half_step + half_step + f64::NAN } }; let z0 = height_at(t0); @@ -160,6 +164,18 @@ fn intersect_lines_unscaled(l0: Line, l1: Line, tolerance: f64) -> CurveOrder { mod tests { use super::*; + #[test] + fn affine_endpoints_crossing_preserves_an_uneven_overflowing_span() { + let a = 2f64.powi(1023); + let b = a.next_up(); + let fixed = Line::new((0.0, -a), (0.0, b)); + let moving = Line::new((-1.0, -a), (1.0, b)); + let crossing = a.midpoint(-b).abs(); + let order = intersect_lines(fixed, moving, 0.0); + assert_eq!(order.order_at(crossing * 0.5), Order::Right); + assert_eq!(order.order_at(crossing * 1.5), Order::Left); + } + #[test] fn simple_intersection() { let l0 = Line::new((0.0, 0.0), (0.0, 1.0)); @@ -287,6 +303,21 @@ mod tests { assert_eq!(order.cmps[0].end, h); } + #[test] + fn subnormal_sloped_lines_keep_interior_overlap_coordinates() { + let h = 1e-310; + let sloped = Line::new((0.0, 0.0), (4.0, h)); + let (x0, x1) = super::line_at_ys(sloped, h * 0.25, h * 0.75); + assert!((x0 - 1.0).abs() < 1e-12, "{x0}"); + assert!((x1 - 3.0).abs() < 1e-12, "{x1}"); + let other = Line::new((5.0, h * 0.25), (6.0, h * 0.75)); + let order = intersect_lines(sloped, other, 1e-6); + assert_eq!(order.start, h * 0.25); + assert_eq!(order.cmps.len(), 1); + assert_eq!(order.cmps[0].order, Order::Left); + assert_eq!(order.cmps[0].end, h * 0.75); + } + #[test] fn close_near_endpoint() { let l0 = Line::new((0.0, 0.0), (0.0, 1.0)); diff --git a/vendor/linesweeper/src/curve/mod.rs b/vendor/linesweeper/src/curve/mod.rs index e4a71ef508..d1bf5318a6 100644 --- a/vendor/linesweeper/src/curve/mod.rs +++ b/vendor/linesweeper/src/curve/mod.rs @@ -135,7 +135,7 @@ impl Iterator for CurveOrderIter<'_, T> { // TODO: we've grown a weird set of convenience methods. Design them better. impl CurveOrder { - fn new(start: f64) -> Self { + pub(crate) fn new(start: f64) -> Self { CurveOrder { start, cmps: SmallVec::new(), @@ -222,6 +222,13 @@ impl CurveOrder { out.metrics.entries.clone_from(&self.metrics.entries); } + pub(crate) fn is_flip_of(&self, other: &CurveOrder) -> bool { + self.start == other.start + && self.metrics == other.metrics + && self.cmps.len() == other.cmps.len() + && self.cmps.iter().zip(&other.cmps).all(|(a, b)| *a == b.flip()) + } + /// Imagine that our curve is to the left of the other curve at height `y`. /// What's the next height at which they touch? /// @@ -752,7 +759,7 @@ fn balance_quadratic(c: f64, b: f64, a: f64) -> (f64, f64, f64) { pub(crate) fn quadratic_signs(q: Quadratic) -> (bool, f64, f64) { let &[c, b, a] = q.coeffs(); let (c, b, a) = balance_quadratic(c, b, a); - let disc = b * b - 4.0 * a * c; + let disc = b * b - 4.0 * (a * c); // The handling of b here is a little confusing, and it has to do with how // the "roots" come out in the linear case. If a is zero, and b is not we // find roots at `-a.signum() * b.signum() * f64::INFINITY` and something @@ -1485,7 +1492,7 @@ fn max_slope(c: CubicBez) -> f64 { let mut ret = 0.0f64; for (a, b) in [(c.p0, c.p1), (c.p1, c.p2), (c.p2, c.p3)] { let dy = b.y - a.y; - if dy.is_nan() || dy <= 0.0 { + if !dy.is_finite() || dy <= 0.0 { return f64::INFINITY; } ret = ret.max((b.x - a.x).abs() / dy); @@ -1977,9 +1984,9 @@ fn order_from_precomputed_approx( if y1 - y0 < ish_tolerance { return None; } - let y_mid = (y0 + y1) / 2.0; - let orig_y_mid0 = (cubic0.c.p0.y + cubic0.c.p3.y) / 2.0; - let orig_y_mid1 = (cubic1.c.p0.y + cubic1.c.p3.y) / 2.0; + let y_mid = y0.midpoint(y1); + let orig_y_mid0 = cubic0.c.p0.y.midpoint(cubic0.c.p3.y); + let orig_y_mid1 = cubic1.c.p0.y.midpoint(cubic1.c.p3.y); let ep0 = cubic0.approx.shift_y(orig_y_mid0 - y_mid); let ep1 = cubic1.approx.shift_y(orig_y_mid1 - y_mid); // An almost-horizontal approximation carries the end x values of its whole @@ -3499,17 +3506,14 @@ mod test { fn crossing_cubics_order_does_not_depend_on_metrics() { let order = crossing_cubics_order(); let intervals: Vec<_> = order.iter().collect(); - let expected = [ - (0.0, 0.4999997495377526, Order::Left), - (0.4999997495377526, 0.5000002504622474, Order::Ish), - (0.5000002504622474, 1.0, Order::Right), - ]; - assert_eq!(intervals.len(), expected.len()); - for ((start, end, o), (exp_start, exp_end, exp_o)) in intervals.into_iter().zip(expected) { - assert!((start - exp_start).abs() < 1e-12); - assert!((end - exp_end).abs() < 1e-12); - assert_eq!(o, exp_o); - } + assert_eq!(intervals.iter().map(|entry| entry.2).collect::>(), [Order::Left, Order::Ish, Order::Right]); + assert_eq!(intervals.first().unwrap().0, 0.0); + assert_eq!(intervals.last().unwrap().1, 1.0); + assert!(intervals.iter().all(|(start, end, _)| start < end)); + assert!(intervals.windows(2).all(|pair| pair[0].1 == pair[1].0)); + assert_eq!(order.order_at(0.25), Order::Left); + assert_eq!(order.order_at(0.5), Order::Ish); + assert_eq!(order.order_at(0.75), Order::Right); } #[test] @@ -3525,20 +3529,12 @@ mod test { #[test] fn crossing_cubics_metrics_record_the_recursion_depth() { let order = crossing_cubics_order(); - let expected = [ - (0.41461454805348563, 0), - (0.49927444265135257, 1), - (0.4999997495377526, 2), - (0.5000002504622474, 2), - (0.5007255573486473, 2), - (0.5853854519465145, 1), - (1.0, 0), - ]; - assert_eq!(order.metrics.entries.len(), expected.len()); - for (entry, (end, depth)) in order.metrics.entries.iter().zip(expected) { - assert!((entry.end - end).abs() < 1e-12, "{entry:?}"); - assert_eq!(entry.depth, depth, "{entry:?}"); - } + let entries = &order.metrics.entries; + assert!(!entries.is_empty()); + assert!(entries.iter().all(|entry| entry.end > 0.0 && entry.end <= 1.0)); + assert!(entries.windows(2).all(|pair| pair[0].end <= pair[1].end)); + assert_eq!(entries.last().unwrap().end, 1.0); + assert!(entries.iter().any(|entry| entry.depth > 0)); } // TODO: improve this test @@ -3576,6 +3572,22 @@ mod test { assert_eq!(order.order_at(1.5), Order::Left); } + #[test] + fn extreme_numeric_quadratic_discriminant_keeps_large_coefficient_roots() { + let q = Quadratic::new([-2f64.powi(-29), 0.0, 2f64.powi(1023)]); + let (positive, left, right) = quadratic_signs(q); + let expected = 2f64.powi(-526); + assert!(positive); + assert!((left / expected + 1.0).abs() < 1e-12, "{left}"); + assert!((right / expected - 1.0).abs() < 1e-12, "{right}"); + } + + #[test] + fn extreme_numeric_overflowing_control_leg_has_unbounded_slope() { + let c = CubicBez::new((0.0, -1e308), (0.0, -9e307), (1.0, 9e307), (1.0, 1e308)); + assert!(max_slope(c).is_infinite()); + } + // Craft patch (quadratic scale) test: the cubic with y = [0, -s, -2s, s] // turns at t = 0.5 for every scale s. #[test] diff --git a/vendor/linesweeper/src/geom.rs b/vendor/linesweeper/src/geom.rs index 0510da5c9c..2794462bfc 100644 --- a/vendor/linesweeper/src/geom.rs +++ b/vendor/linesweeper/src/geom.rs @@ -490,11 +490,31 @@ impl Segment { // long, work with half of each height, and take the // weighted sum of the x coordinates. let dy = p1.y - p0.y; - let t = if dy.is_finite() { - (y - p0.y) / dy - } else { - (y * 0.5 - p0.y * 0.5) / (p1.y * 0.5 - p0.y * 0.5) - }; + if !dy.is_finite() { + if y == p0.y { + return p0.x; + } + if y == p1.y { + return p1.x; + } + let half_y = p1.y * 0.5 - p0.y * 0.5; + let half_x = p1.x * 0.5 - p0.x * 0.5; + let slope = half_x / half_y; + if !slope.is_normal() { + let t = (y * 0.5 - p0.y * 0.5) / half_y; + return (1.0 - t) * p0.x + t * p1.x; + } + let middle = p0.y.midpoint(p1.y); + let (anchor_y, anchor_x) = if y < p0.y.midpoint(middle) { + (p0.y, p0.x) + } else if y > middle.midpoint(p1.y) { + (p1.y, p1.x) + } else { + (middle, p0.x.midpoint(p1.x)) + }; + return (y - anchor_y).mul_add(slope, anchor_x); + } + let t = (y - p0.y) / dy; let dx = p1.x - p0.x; if dx.is_finite() { p0.x + t * dx @@ -573,6 +593,36 @@ impl Segment { mod tests { use super::*; + #[test] + fn affine_endpoints_line_height_keeps_a_small_nonzero_offset() { + let line = Segment::straight(Point::new(-1e308, -1e308), Point::new(1e308, 1e308)); + assert!((line.at_y(1.0) - 1.0).abs() <= 8.0 * f64::EPSILON); + assert!(line.upper(1.0, 0.0) >= 1.0); + assert!(line.lower(-1.0, 0.0) <= -1.0); + } + + #[test] + fn extreme_line_height_preserves_a_tiny_horizontal_span() { + let line = Segment::straight(Point::new(0.0, -1e308), Point::new(1e-20, 1e308)); + for (y, expected) in [(-1e308, 0.0), (-5e307, 2.5e-21), (0.0, 5e-21), (5e307, 7.5e-21), (1e308, 1e-20)] { + let actual = line.at_y(y); + assert!((actual - expected).abs() <= 1e-35, "at {y}: {actual}, expected {expected}"); + } + } + + #[test] + fn extreme_line_height_preserves_uneven_endpoint_coordinates() { + for line in [ + Segment::straight(Point::new(1.0, -1e308), Point::new(1e308, 1e308)), + Segment::straight(Point::new(-1e308, -1e308), Point::new(-1.0, 1e308)), + ] { + assert_eq!(line.at_y(line.start().y), line.start().x); + assert_eq!(line.at_y(line.end().y), line.end().x); + assert!(line.lower(line.start().y, 0.0) <= line.start().x); + assert!(line.upper(line.end().y, 0.0) >= line.end().x); + } + } + // Craft patch (horizontal line bounds) #[test] fn horizontal_line_bounds_cover_both_endpoints() { diff --git a/vendor/linesweeper/src/lib.rs b/vendor/linesweeper/src/lib.rs index 50eead5d85..ae667e4efe 100644 --- a/vendor/linesweeper/src/lib.rs +++ b/vendor/linesweeper/src/lib.rs @@ -19,7 +19,6 @@ pub mod topology; pub mod generators; pub use geom::{Point, Segment}; -use kurbo::Shape; pub use segments::{SegIdx, Segments}; // pub so that we can use it in fuzz tests, but it's really private @@ -205,38 +204,6 @@ fn automatic_accuracy(paths: &[&kurbo::BezPath]) -> Result { for path in paths { check_coordinates(path)?; } - // Find the extremal values, to figure out how much precision we can support. - // Craft patch (leading ClosePath): `BezPath::bounding_box` panics on a leading ClosePath. - let bounding_box = |path: &kurbo::BezPath| { - if matches!(path.elements().first(), Some(kurbo::PathEl::ClosePath)) { - kurbo::segments(segments::skip_leading_close_paths(path.iter())) - .map(|seg| kurbo::ParamCurveExtrema::bounding_box(&seg)) - .reduce(|a, b| a.union(b)) - .unwrap_or_default() - } else { - path.bounding_box() - } - }; - let bbox = paths - .iter() - .map(|path| bounding_box(path)) - .reduce(|a, b| a.union(b)) - .unwrap_or_default(); - let min = bbox.min_x().min(bbox.min_y()); - let max = bbox.max_x().max(bbox.max_y()); - if min.is_infinite() || max.is_infinite() { - return Err(Error::Infinity); - } - // If there was any NaN in the input, it should have propagated to the min and max. - if min.is_nan() || max.is_nan() { - return Err(Error::NaN); - } - - // TODO: we did some analysis for error bounds in the case of polylines. - // Think more about what makes sense for curves. - let m_2 = min.abs().max(max.abs()); - let eps = m_2 * (f64::EPSILON * 64.0); - let eps = eps.max(MIN_AUTO_EPS); let max_coord = paths .iter() .flat_map(|path| kurbo::segments(segments::skip_leading_close_paths(path.iter()))) @@ -250,7 +217,7 @@ fn automatic_accuracy(paths: &[&kurbo::BezPath]) -> Result { .max(seg.end().y.abs()) }) .fold(0.0, f64::max); - let eps = eps.max(curve::resolution_floor(max_coord)); + let eps = MIN_AUTO_EPS.max(curve::resolution_floor(max_coord)); debug_assert!(eps.is_finite()); // Craft patch (far-point eps). @@ -458,14 +425,14 @@ mod tests { #[test] fn automatic_accuracy_ignores_discarded_horizontal_handles() { let flat = BezPath::from_svg("M0 0 C1e14 0 1e14 0 0 0 Z").unwrap(); - let square = kurbo::Rect::new(0.0, 0.0, 5.0, 5.0).to_path(0.1); - for (a, b) in [(&flat, &square), (&square, &flat)] { - assert!(binary_op_accuracy(a, b).is_ok()); - let contours = binary_op(a, b, FillRule::NonZero, BinaryOp::Union).unwrap(); - assert_eq!( - contours.contours().map(|c| c.path.area()).sum::(), - 25.0 - ); + for size in [1.0, 5.0] { + let square = kurbo::Rect::new(0.0, 0.0, size, size).to_path(0.1); + let expected = binary_op_accuracy(&square, &BezPath::new()).unwrap(); + for (a, b) in [(&flat, &square), (&square, &flat)] { + assert_eq!(binary_op_accuracy(a, b).unwrap(), expected); + let contours = binary_op(a, b, FillRule::NonZero, BinaryOp::Union).unwrap(); + assert_eq!(contours.contours().map(|c| c.path.area()).sum::(), size * size); + } } } @@ -508,7 +475,7 @@ mod tests { ); } use insta::assert_ron_snapshot; - use kurbo::BezPath; + use kurbo::{BezPath, Shape}; use super::*; diff --git a/vendor/linesweeper/src/order.rs b/vendor/linesweeper/src/order.rs index 27825f61d1..75b6a8fe5c 100644 --- a/vendor/linesweeper/src/order.rs +++ b/vendor/linesweeper/src/order.rs @@ -19,6 +19,8 @@ pub struct ComparisonCache { // direction flips it into `flipped`. inner: FxHashMap<(SegIdx, SegIdx), CurveOrder>, flipped: Option, + flipped_key: Option<(SegIdx, SegIdx)>, + edited_flipped: FxHashMap<(SegIdx, SegIdx), CurveOrder>, // Craft patch (comparison cache size): `evict_ended` scans the cache once // it holds this many pairs. next_purge: usize, @@ -49,6 +51,8 @@ impl ComparisonCache { ComparisonCache { inner: FxHashMap::default(), flipped: None, + flipped_key: None, + edited_flipped: FxHashMap::default(), next_purge: MIN_PURGE, accuracy, tolerance, @@ -69,6 +73,8 @@ impl ComparisonCache { ComparisonCache { inner: FxHashMap::default(), flipped: None, + flipped_key: None, + edited_flipped: FxHashMap::default(), next_purge: MIN_PURGE, accuracy, tolerance, @@ -80,6 +86,7 @@ impl ComparisonCache { /// Compares two segments, returning their order. /// /// Returns `None` if either segment is horizontal. + /// Edits to the returned order persist until its pair is evicted or the arena changes. pub fn compare_segments( &mut self, segments: &Segments, @@ -91,7 +98,30 @@ impl ComparisonCache { if segments[i].is_horizontal() || segments[j].is_horizontal() { return None; } - Some(self.compare_non_horizontal_segments(segments, i, j)) + self.compare_non_horizontal_segments(segments, i, j); + if i.0 < j.0 { + self.inner.get_mut(&(i, j)) + } else { + let key = (j, i); + if self.edited_flipped.contains_key(&key) { + self.edited_flipped.get_mut(&key) + } else { + self.flipped_key = Some(key); + self.flipped.as_mut() + } + } + } + + fn save_flipped_edits(&mut self) { + let Some(key) = self.flipped_key.take() else { + return; + }; + if self.flipped.as_ref().zip(self.inner.get(&key)) + .is_some_and(|(reverse, forward)| !reverse.is_flip_of(forward)) + && let Some(reverse) = self.flipped.take() + { + self.edited_flipped.insert(key, reverse); + } } /// Compares two segments that are not horizontal, returning their order. @@ -112,7 +142,11 @@ impl ComparisonCache { let arena = segments.arena_id(); if self.arena != Some(arena) { self.inner.clear(); + self.edited_flipped.clear(); + self.flipped_key = None; self.arena = Some(arena); + } else { + self.save_flipped_edits(); } let (i, j, flipped) = if i.0 < j.0 { @@ -121,6 +155,10 @@ impl ComparisonCache { (j, i, true) }; + if flipped && let Some(order) = self.edited_flipped.get_mut(&(i, j)) { + return order; + } + let stored = match self.inner.entry((i, j)) { Entry::Occupied(o) => o.into_mut(), Entry::Vacant(v) => { @@ -147,11 +185,16 @@ impl ComparisonCache { if self.inner.len() < self.next_purge { return; } + self.save_flipped_edits(); self.inner .retain(|(i, j), _| segments[*i].end().y >= y && segments[*j].end().y >= y); + self.edited_flipped.retain(|key, _| self.inner.contains_key(key)); if self.inner.len() * 4 < self.inner.capacity() { self.inner.shrink_to_fit(); } + if self.edited_flipped.len() * 4 < self.edited_flipped.capacity() { + self.edited_flipped.shrink_to_fit(); + } self.next_purge = self.inner.len().saturating_mul(2).max(MIN_PURGE); } @@ -179,6 +222,7 @@ impl ComparisonCache { f: impl FnOnce(&CurveOrder) -> R, ) -> R { self.calls = self.calls.saturating_add(1); + self.save_flipped_edits(); let (i, j, flipped) = if i.0 < j.0 { (i, j, false) } else { @@ -186,6 +230,11 @@ impl ComparisonCache { }; // Comparisons cached for another arena do not describe this one. + if self.arena == Some(segments.arena_id()) && flipped + && let Some(order) = self.edited_flipped.get(&(i, j)) + { + return f(order); + } let stored = (self.arena == Some(segments.arena_id())) .then(|| self.inner.get(&(i, j))) .flatten(); @@ -293,6 +342,10 @@ fn compute(segments: &Segments, i: SegIdx, j: SegIdx, tolerance: f64, accuracy: // that are not horizontal. debug_assert!(!segi.is_horizontal() && !segj.is_horizontal()); + if segi.start().y.max(segj.start().y) > segi.end().y.min(segj.end().y) { + return CurveOrder::new(segi.start().y.max(segj.start().y)); + } + let forward = if let (Some(l0), Some(l1)) = (segi.as_kurbo_line(), segj.as_kurbo_line()) { curve::line::intersect_lines(l0, l1, tolerance) } else { @@ -312,7 +365,7 @@ mod tests { use crate::{ SegIdx, Segments, - curve::{CurveOrder, Order}, + curve::{CurveOrder, MetricsEntry, Order}, }; use super::{ComparisonCache, far_apart_margin, full_comparison, order_if_far_apart}; @@ -604,6 +657,44 @@ mod tests { ); } + #[test] + fn comparison_contract_disjoint_cubics_have_empty_orders() { + let mut segments = Segments::default(); + for y in [0.0, 2.0] { + let mut path = BezPath::new(); + path.move_to((0.0, y)); + path.curve_to((0.1, y + 0.25), (-0.1, y + 0.75), (0.0, y + 1.0)); + segments.add_non_closed_bez_path(&path).unwrap(); + } + let mut cache = ComparisonCache::new(0.01, 0.005); + for (a, b) in [(0, 1), (1, 0)] { + assert!(cache.compare_segments(&segments, SegIdx(a), SegIdx(b)).unwrap().iter().next().is_none()); + } + } + + #[test] + fn mutable_reverse_comparisons_keep_their_edits() { + let mut segments = Segments::default(); + for x in [0.0, 1.0, 2.0] { + let mut path = BezPath::new(); + path.move_to((x, 0.0)); + path.line_to((x, 1.0)); + segments.add_non_closed_bez_path(&path).unwrap(); + } + let mut cache = ComparisonCache::new(0.01, 0.005); + let forward = cache.compare_segments(&segments, SegIdx(0), SegIdx(1)).unwrap().clone(); + let reverse = cache.compare_segments(&segments, SegIdx(1), SegIdx(0)).unwrap(); + reverse.metrics.entries.push(MetricsEntry { end: 0.5, depth: 7 }); + let expected = reverse.metrics.clone(); + let mut cloned = cache.clone(); + assert_eq!(cache.compare_segments(&segments, SegIdx(0), SegIdx(1)).unwrap().metrics, forward.metrics); + cache.compare_segments(&segments, SegIdx(2), SegIdx(0)).unwrap(); + assert_eq!(cache.compare_segments(&segments, SegIdx(1), SegIdx(0)).unwrap().metrics, expected); + assert_eq!(cloned.compare_segments(&segments, SegIdx(1), SegIdx(0)).unwrap().metrics, expected); + let other_arena = segments.clone(); + assert_eq!(cache.compare_segments(&other_arena, SegIdx(1), SegIdx(0)).unwrap().metrics, forward.metrics); + } + #[test] fn horizontal_and_cubic() { let mut segments = Segments::default(); @@ -728,6 +819,16 @@ mod tests { std::mem::size_of::() ); } + for i in segments.indices() { + for j in segments.indices() { + if i != j { + cmp_cache.compare_segments(&segments, i, j).unwrap(); + } + } + } + cmp_cache.save_flipped_edits(); + assert_eq!(cmp_cache.inner.len(), n * (n - 1) / 2); + assert!(cmp_cache.edited_flipped.is_empty()); } #[test] diff --git a/vendor/linesweeper/src/position.rs b/vendor/linesweeper/src/position.rs index 5e0f4a7d72..cc479d141e 100644 --- a/vendor/linesweeper/src/position.rs +++ b/vendor/linesweeper/src/position.rs @@ -319,8 +319,34 @@ fn settled_range( /// The increasing map of heights that takes `from0` to `to0` and `from1` to `to1`, or /// `None` when either range is empty or the map is not finite. fn height_map(from0: f64, from1: f64, to0: f64, to1: f64) -> Option f64> { - let scale = (to1 - to0) / (from1 - from0); - (from0 < from1 && to0 < to1 && scale.is_finite()).then_some(move |y| to0 + (y - from0) * scale) + let from_span = from1 - from0; + let to_span = to1 - to0; + let scale = if from_span.is_finite() && to_span.is_finite() { + to_span / from_span + } else { + (to1 * 0.5 - to0 * 0.5) / (from1 * 0.5 - from0 * 0.5) + }; + let middle = from0.midpoint(from1); + (from0 < from1 && to0 < to1 && scale.is_finite()).then_some(move |y: f64| { + if y == from0 { + to0 + } else if y == from1 { + to1 + } else if scale == 0.0 { + let t = if from_span.is_finite() { + (y - from0) / from_span + } else { + (y * 0.5 - from0 * 0.5) / (from1 * 0.5 - from0 * 0.5) + }; + to0 * (1.0 - t) + to1 * t + } else if y < from0.midpoint(middle) { + (y - from0).mul_add(scale, to0) + } else if y > middle.midpoint(from1) { + (y - from1).mul_add(scale, to1) + } else { + (y - middle).mul_add(scale, to0.midpoint(to1)) + } + }) } /// Cuts `c` between the points nearest `p0` and `p3`, searching from `t0` and `t3`, and @@ -698,7 +724,7 @@ mod tests { use crate::{Segments, sweep::Correctness, topology::Topology}; - use super::{PositionedOutputSeg, horizontal_error_weight}; + use super::{PositionedOutputSeg, height_map, horizontal_error_weight, settled_cubic}; #[test] fn error_weight() { @@ -953,6 +979,15 @@ mod tests { } } + #[test] + fn affine_endpoints_flat_handles_keep_the_exact_target_height() { + let curve = CubicBez::new((0.0, -1.0), (1.0, 1.0), (2.0, 1.0), (3.0, 1.0)); + let end = Point::new(10.0, -1e-20); + let placed = settled_cubic(curve, 0.0, 1.0, curve.p0, end).unwrap(); + assert!(placed.p2.y <= placed.p3.y, "{placed:?}"); + assert_eq!(height_map(-1.0, 1.0, -1.0, end.y).unwrap()(1.0), end.y); + } + // Craft patch (flat-end shear): the union of a shape with a copy moved by // less than `eps` stays on the two shapes, and keeps their area. #[test] diff --git a/vendor/linesweeper/src/segments.rs b/vendor/linesweeper/src/segments.rs index 7c7af1e23a..24e696a031 100644 --- a/vendor/linesweeper/src/segments.rs +++ b/vendor/linesweeper/src/segments.rs @@ -476,18 +476,32 @@ impl Segments { must_be_closed: bool, ) -> Result<(), NonClosedPath> { let old_len = self.segs.len(); + struct UnenteredBatch<'a> { + arena: &'a mut Segments, + start: usize, + complete: bool, + } + impl Drop for UnenteredBatch<'_> { + fn drop(&mut self) { + if !self.complete { + self.arena.truncate_unentered(self.start); + } + } + } + let mut batch = UnenteredBatch { arena: self, start: old_len, complete: false }; let mut result = Ok(()); for p in ps { - let path_start = self.segs.len(); - result = self.add_path_without_updating_enter_exit(p, must_be_closed); + let path_start = batch.arena.segs.len(); + result = batch.arena.add_path_without_updating_enter_exit(p, must_be_closed); if result.is_err() { // The failing path's segments are removed, so none is left // linked to an index past the end of the arena. - self.truncate_unentered(path_start); + batch.arena.truncate_unentered(path_start); break; } } - self.update_enter_exit(old_len); + batch.arena.update_enter_exit(old_len); + batch.complete = true; result } @@ -602,13 +616,7 @@ impl Segments { // above. `enter` and `exit` are left alone, so this is only for segments // that `update_enter_exit` has not seen yet. fn truncate(&mut self, len: usize) { - self.segs.inner.truncate(len); - self.horizontal_decomps.inner.truncate(len); - self.contour_prev.inner.truncate(len); - self.contour_next.inner.truncate(len); - self.orientation.inner.truncate(len); - self.split_from_predecessor.inner.truncate(len); - self.input_segs.inner.truncate(len); + self.truncate_unentered(len); } /// Construct a segment arena from a single closed polyline. @@ -845,6 +853,36 @@ mod tests { ); } + #[test] + fn batch_iterator_panic_preserves_the_existing_arena() { + for closed in [false, true] { + let paths = grid_paths(4, true); + let mut arena = Segments::default(); + arena.add_bez_path(&paths[0]).unwrap(); + let expected = arena.clone(); + let mut count = 0; + let iter = std::iter::from_fn(|| { + count += 1; + assert_ne!(count, 3, "iterator panic after two paths"); + Some(&paths[count]) + }); + let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { + if closed { + arena.add_bez_paths(iter).unwrap(); + } else { + arena.add_non_closed_bez_paths(iter).unwrap(); + } + })); + assert!(result.is_err()); + assert_same_arena(&expected, &arena); + assert_eq!(arena.input_segs, expected.input_segs); + assert_eq!(arena.split_from_predecessor, expected.split_from_predecessor); + arena.check_invariants(); + arena.add_bez_path(&paths[3]).unwrap(); + arena.check_invariants(); + } + } + type Events = Vec<(f64, SegIdx)>; // The entrance and exit order that sorting every entry in index order diff --git a/vendor/linesweeper/src/sweep/output_event.rs b/vendor/linesweeper/src/sweep/output_event.rs index 987ac528cd..a67be48e71 100644 --- a/vendor/linesweeper/src/sweep/output_event.rs +++ b/vendor/linesweeper/src/sweep/output_event.rs @@ -13,13 +13,14 @@ use crate::{SegIdx, num::CheapOrderedFloat}; /// it intersects the sweep-line (i.e. [`OutputEvent::smaller_x`]). /// Events with the same horizontal range are ordered by segment and then by /// their other fields, so two events compare equal only when they are equal. +/// NaN coordinates use total floating-point order; signed zeros compare equal. /// /// The two points, `x0` and `x1`, are in sweep-line order. This doesn't /// necessarily mean that `x0` is smaller than `x1`! Instead, it means that /// when traversing the segment in sweep-line order (i.e. in increasing `y`, /// and increasing `x` if the segment is horizontal) then it visits `x0` /// before `x1`. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug)] pub struct OutputEvent { /// The first horizontal coordinate on this sweep-line that we'd hit if /// we were traversing the segment in sweep-line orientation. @@ -47,6 +48,20 @@ pub struct OutputEvent { impl Eq for OutputEvent {} +impl PartialEq for OutputEvent { + fn eq(&self, other: &Self) -> bool { + self.cmp(other).is_eq() + } +} + +fn coordinate_order(a: f64, b: f64) -> std::cmp::Ordering { + if a == b { + std::cmp::Ordering::Equal + } else { + a.total_cmp(&b) + } +} + impl OutputEvent { /// The smallest `x` coordinate at which the line segment touches the sweep-line. pub fn smaller_x(&self) -> f64 { @@ -106,9 +121,11 @@ impl OutputEvent { // ordered by segment and then by the other fields, so `cmp` agrees with `==`. impl Ord for OutputEvent { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - self.cmp_x(other) + coordinate_order(self.smaller_x(), other.smaller_x()) + .then_with(|| coordinate_order(self.larger_x(), other.larger_x())) .then_with(|| self.seg_idx.cmp(&other.seg_idx)) - .then_with(|| CheapOrderedFloat::from(self.x0).cmp(&CheapOrderedFloat::from(other.x0))) + .then_with(|| coordinate_order(self.x0, other.x0)) + .then_with(|| coordinate_order(self.x1, other.x1)) .then_with(|| self.connected_above.cmp(&other.connected_above)) .then_with(|| self.connected_below.cmp(&other.connected_below)) .then_with(|| self.sweep_idx.cmp(&other.sweep_idx)) @@ -128,6 +145,30 @@ mod tests { use super::*; + #[test] + fn comparison_contract_public_events_order_nan_coordinates_consistently() { + let values = [ + -f64::NAN, + f64::NEG_INFINITY, + -1.0, + -0.0, + 0.0, + 1.0, + f64::INFINITY, + f64::NAN, + f64::from_bits(f64::NAN.to_bits() + 1), + ]; + let events: Vec<_> = values.into_iter().map(|x| OutputEvent::new(SegIdx(0), x, true, 2.0, true, Some(0), Some(0))).collect(); + for a in &events { + assert_eq!(a, &a.clone()); + for b in &events { + assert_eq!(a == b, a.cmp(b).is_eq()); + assert_eq!(a.cmp(b), b.cmp(a).reverse()); + } + } + assert_eq!(events.iter().cloned().collect::>().len(), 8); + } + // Craft patch (output event order) #[test] fn events_on_different_segments_with_the_same_range_are_not_equal() { diff --git a/vendor/linesweeper/src/sweep/sweep_line.rs b/vendor/linesweeper/src/sweep/sweep_line.rs index e077d708fb..9fd40009a1 100644 --- a/vendor/linesweeper/src/sweep/sweep_line.rs +++ b/vendor/linesweeper/src/sweep/sweep_line.rs @@ -413,6 +413,8 @@ pub struct Sweeper<'a> { touch_scans: rustc_hash::FxHashSet<(SegIdx, bool)>, #[cfg(test)] touch_scan_count: usize, + #[cfg(test)] + repeat_span_visits: u64, // Craft patch (work limit): the most work that `next_line` lets the sweep // do, and whether it stopped there. The work is the segment comparisons, // which the two caches count, plus `position_checks`: the segment positions @@ -473,6 +475,8 @@ impl<'segs> Sweeper<'segs> { touch_scans: rustc_hash::FxHashSet::default(), #[cfg(test)] touch_scan_count: 0, + #[cfg(test)] + repeat_span_visits: 0, work_limit: None, stopped_at_work_limit: false, position_checks: 0, @@ -557,9 +561,8 @@ impl<'segs> Sweeper<'segs> { /// Finds `seg_idx` on the sweep line, counting the entries the binary search probes. fn find_position(&mut self, seg_idx: SegIdx) -> Option { - let pos = self.line.position(seg_idx); - let probes = usize::BITS - self.line.segs.len().leading_zeros(); - self.segments_passed = self.segments_passed.saturating_add(u64::from(probes)); + let (pos, probes) = self.line.position_with_probes(seg_idx); + self.segments_passed = self.segments_passed.saturating_add(probes); pos } @@ -629,16 +632,25 @@ impl<'segs> Sweeper<'segs> { // from one of those positions to the other, in order. The hash keeps each // key the same size however many segments lie between the pair. The // position searches and the segments hashed count toward the work limit. + #[cfg(test)] fn repeat_key(&mut self, left: SegIdx, right: SegIdx) -> RepeatKey { - use std::hash::{Hash, Hasher}; - let left_pos = self.find_position(left); let right_pos = self.find_position(right); + self.repeat_key_at(left, right, left_pos, right_pos) + } + + fn repeat_key_at(&mut self, left: SegIdx, right: SegIdx, left_pos: Option, right_pos: Option) -> RepeatKey { + use std::hash::{Hash, Hasher}; + let mut hasher = std::collections::hash_map::DefaultHasher::new(); if let (Some(a), Some(b)) = (left_pos, right_pos) { let hashed = u64::try_from(a.abs_diff(b)).unwrap_or(u64::MAX).saturating_add(1); self.segments_passed = self.segments_passed.saturating_add(hashed); for entry in self.line.segs.range(a.min(b)..=a.max(b)) { + #[cfg(test)] + { + self.repeat_span_visits += 1; + } entry.seg.hash(&mut hasher); } } @@ -725,7 +737,9 @@ impl<'segs> Sweeper<'segs> { ); } let (left, right) = (intersection.left, intersection.right); - if !handled.insert(self.repeat_key(left, right)) { + let left_idx = self.find_position(left).unwrap(); + let right_idx = self.find_position(right).unwrap(); + if left_idx < right_idx && !handled.insert(self.repeat_key_at(left, right, Some(left_idx), Some(right_idx))) { let next_y = self .compare_segments(left, right) .iter() @@ -743,7 +757,7 @@ impl<'segs> Sweeper<'segs> { } continue; } - self.handle_intersection(left, right); + self.handle_intersection(left, right, left_idx, right_idx); self.check_invariants(); } @@ -1133,9 +1147,7 @@ impl<'segs> Sweeper<'segs> { self.segs_needing_positions.push(pos); } - fn handle_intersection(&mut self, left: SegIdx, right: SegIdx) { - let left_idx = self.find_position(left).unwrap(); - let right_idx = self.find_position(right).unwrap(); + fn handle_intersection(&mut self, left: SegIdx, right: SegIdx, left_idx: usize, right_idx: usize) { if left_idx < right_idx { // We're going to put `left_seg` after `right_seg` in the // sweep line, and while doing so we need to "push" along @@ -1854,9 +1866,18 @@ impl SegmentOrder { // // Craft patch (sweep position): a binary search over the keys replaces // the package's linear scan. + #[cfg(any(test, feature = "slow-asserts"))] fn position(&self, seg_idx: SegIdx) -> Option { + self.position_with_probes(seg_idx).0 + } + + fn position_with_probes(&self, seg_idx: SegIdx) -> (Option, u64) { let key = self.keys[seg_idx]; - let pos = self.segs.partition_point(|entry| entry.key < key); + let mut probes = 0u64; + let pos = self.segs.partition_point(|entry| { + probes = probes.saturating_add(1); + entry.key < key + }); let ret = self .segs .get(pos) @@ -1871,7 +1892,7 @@ impl SegmentOrder { .position(|x| x.seg == seg_idx || x.old_seg == Some(seg_idx)) ); - ret + (ret, probes) } // Craft patch (sweep position): inserts an entry at the given index, @@ -3001,6 +3022,27 @@ mod tests { assert_eq!(sweep.repeat_key(d, a).4, first.4); } + #[test] + fn position_work_counts_every_tree_predicate_probe() { + let xs: Vec<_> = (0..1024).map(|n| (f64::from(n), f64::from(n))).collect(); + let segs = mk_segs(&xs); + let mut sweep = Sweeper::new(&segs, 0.1); + for (pos, seg) in segs.indices().enumerate() { + sweep.line.insert(pos, SegmentOrderEntry::new(seg, &segs, 0.1)); + } + for seg in segs.indices() { + let key = sweep.line.keys[seg]; + let mut probes = 0u64; + let expected = sweep.line.segs.partition_point(|entry| { + probes += 1; + entry.key < key + }); + let before = sweep.segments_passed; + assert_eq!(sweep.find_position(seg), Some(expected)); + assert_eq!(sweep.segments_passed - before, probes, "segment {seg:?}"); + } + } + // Wide, flat shapes (x up to 1e12, y below 1e-3) whose sweep delays an // intersection to exactly the end of one of its segments. Handling the // delayed event there used to panic in `CurveOrder::entry_at`. @@ -3089,6 +3131,7 @@ mod tests { while sweep.next_line(&mut bufs).is_some() { lines += 1; } + assert_eq!(sweep.repeat_span_visits, 0, "ordinary coincident touches must not hash intervening spans"); assert!( sweep.touch_scan_count <= 2 * segs.len() * lines, "{} touch scans for {} segments on {lines} sweep lines", diff --git a/vendor/linesweeper/src/topology.rs b/vendor/linesweeper/src/topology.rs index 5b0f82f2be..1a1ddf0abd 100644 --- a/vendor/linesweeper/src/topology.rs +++ b/vendor/linesweeper/src/topology.rs @@ -65,6 +65,7 @@ thread_local! { /// The number of path elements that `contours_for_positions` has run winding tests over /// on this thread, to find the piece that holds a loop split off a contour walk. static CONTAINER_TEST_ELEMENTS: std::cell::Cell = const { std::cell::Cell::new(0) }; + static OUTPUT_UNITS_BEFORE_MERGE: std::cell::Cell = const { std::cell::Cell::new(0) }; } /// Winding numbers for binary set operations. @@ -191,9 +192,12 @@ impl OutputLimit { let Some(limit) = self.limit else { return true; }; - let units = 1usize - .saturating_add(windings.clockwise.storage_units()) - .saturating_add(windings.counter_clockwise.storage_units()); + let Some(units) = 1usize + .checked_add(windings.clockwise.storage_units()) + .and_then(|units| units.checked_add(windings.counter_clockwise.storage_units())) + else { + return false; + }; match self.used.checked_add(units) { Some(used) if used <= limit => { self.used = used; @@ -202,6 +206,21 @@ impl OutputLimit { _ => false, } } + + fn replace_winding(&mut self, before: &W, after: &W) -> bool { + let Some(limit) = self.limit else { + return true; + }; + let used = self.used.checked_sub(before.storage_units()) + .and_then(|used| used.checked_add(after.storage_units())); + match used { + Some(used) if used <= limit => { + self.used = used; + true + } + _ => false, + } + } } impl HalfSegmentWindingNumbers { @@ -862,7 +881,11 @@ impl Topology { #[cfg(feature = "slow-asserts")] ret.check_invariants(); - ret.merge_coincident(); + #[cfg(test)] + OUTPUT_UNITS_BEFORE_MERGE.with(|count| count.set(output.used)); + if !ret.merge_coincident(&mut output) { + return Err(crate::Error::WorkLimitExceeded); + } #[cfg(feature = "slow-asserts")] ret.check_invariants(); @@ -1251,7 +1274,7 @@ impl Topology { /// makes it a little bit tricky is that (except for horizontal segments) /// we don't know whether two segments are coincident until we've processed /// their second endpoint. - fn merge_coincident(&mut self) { + fn merge_coincident(&mut self, output: &mut OutputLimit) -> bool { // `scan_west` stays as built, because `build_scan_line_orders` reads it. This copy // is pointed past deleted segments as the loop finds them. let mut live_west = self.scan_west.clone(); @@ -1299,6 +1322,12 @@ impl Topology { // All output segments are in sweep line order, so if they're // coincident then they'd better both be first halves. debug_assert!(cw_nbr.first_half); + if !output.replace_winding( + &self.winding[cw_nbr.idx].counter_clockwise, + &self.winding[idx].counter_clockwise, + ) { + return false; + } self.delete(idx); self.winding[cw_nbr.idx].counter_clockwise = self.winding[idx].counter_clockwise.clone(); @@ -1308,6 +1337,7 @@ impl Topology { } } } + true } /// Returns the nearest segment west of `seg` that is not deleted, following @@ -3421,14 +3451,19 @@ mod tests { #[test] fn merge_only_pieces_of_one_input_curve() { + use kurbo::Shape as _; + // Two arches whose right legs agree to within about 1e-6. The legs are deleted as // coincident, and the left end of one arch meets a piece of the other at a simple point. // The shape's area is about 0.000962; merging across the two curves gave a contour // of area 900. let path = "M0,100 C20,0 80,0 100,100 \ C79.99999708333333,0 20.000011666666666,0 -0.000026249999999999998,100 Z"; - let area = contour_area_sum(path, 1e-6); - assert!(area < 0.002, "area {area}"); + let bez = BezPath::from_svg(path).unwrap(); + let top = Topology::from_path(&bez, 1e-6).unwrap(); + let contours = top.try_contours(|w| *w != 0).unwrap(); + let area: f64 = contours.contours().map(|c| c.path.area().abs()).sum(); + assert!((0.0005..0.002).contains(&area), "area {area}"); } #[test] @@ -4267,6 +4302,71 @@ mod tests { assert_eq!(result.err(), Some(crate::Error::WorkLimitExceeded)); } + #[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize)] + struct StoredTags(std::collections::BTreeMap); + + impl std::ops::Add for StoredTags { + type Output = Self; + + fn add(mut self, rhs: Self) -> Self { + self += rhs; + self + } + } + + impl std::ops::AddAssign for StoredTags { + fn add_assign(&mut self, rhs: Self) { + for (tag, value) in rhs.0 { + *self.0.entry(tag).or_default() += value; + } + self.0.retain(|_, value| *value != 0); + } + } + + impl super::WindingNumber for StoredTags { + type Tag = usize; + + fn single(tag: usize, positive: bool) -> Self { + Self([(tag, if positive { 1 } else { -1 })].into_iter().collect()) + } + + fn of_tag(&self, tag: usize) -> Self { + Self(self.0.get(&tag).map(|value| (tag, *value)).into_iter().collect()) + } + + fn storage_units(&self) -> usize { + self.0.len() + } + } + + #[test] + fn output_accounting_includes_winding_growth_when_coincident_edges_merge() { + let mut exercised_growth = false; + for reversed in [false, true] { + let paths: Vec<_> = [10.0, 20.0, 30.0].into_iter() + .map(|width| rect_bez_path(0.0, 0.0, width, 10.0, reversed)).collect(); + let tagged = || paths.iter().enumerate().map(|(tag, path)| (path, tag)); + let topology = Topology::::from_paths_with_limits(tagged(), 1e-6, u64::MAX, usize::MAX).unwrap(); + let before = super::OUTPUT_UNITS_BEFORE_MERGE.with(std::cell::Cell::get); + let stored: usize = topology.winding.inner.iter() + .map(|winding| 1 + winding.clockwise.0.len() + winding.counter_clockwise.0.len()).sum(); + if stored > before { + exercised_growth = true; + let limited = Topology::::from_paths_with_limits(tagged(), 1e-6, u64::MAX, before); + assert_eq!(limited.err(), Some(crate::Error::WorkLimitExceeded), "stored {stored}, budget {before}"); + } + } + assert!(exercised_growth); + } + + #[test] + fn output_accounting_rejects_an_overflowing_winding_storage_sum() { + let mut output = super::OutputLimit { used: 0, limit: Some(usize::MAX) }; + let winding = super::HalfSegmentWindingNumbers { clockwise: HugeWinding(1), counter_clockwise: HugeWinding(0) }; + assert!(!output.take(&winding)); + assert_eq!(output.used, 0); + } + fn run_perturbation(ps: Vec>) { let base = vec![vec![ p(0.0, 0.0), diff --git a/vendor/linesweeper/src/treevec.rs b/vendor/linesweeper/src/treevec.rs index 31336a75b4..ca2d8913a8 100644 --- a/vendor/linesweeper/src/treevec.rs +++ b/vendor/linesweeper/src/treevec.rs @@ -673,7 +673,7 @@ impl TreeVec { Node::Leaf { data } => RevIterInner::Simple(data[..end].iter()), Node::Internal { .. } => { let mut ret = RevTreeIter { - stack: Vec::new(), + stack: Stack::new(), leaf: [].iter(), remaining: end, }; @@ -876,7 +876,7 @@ enum RevIterInner<'a, T, const B: usize> { // The mirror image of `TreeIter`: the stack holds the children still to visit // on the left, and elements come off the back of each slice. struct RevTreeIter<'a, T, const B: usize> { - stack: Vec>>>, + stack: Stack>>>, leaf: std::slice::Iter<'a, T>, remaining: usize, }