mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This PR uses a new algorithm that approximates the superellipse curve with two conic curves, instead of one cubic curves. This algorithm works much better at very large ratio. Fixes https://github.com/flutter/flutter/issues/179875 . A new playground is added in this PR to show enlarged corner of a rounded superellipse at very large ratio and compares its path version and filled version. <details> <summary> For comparison: The best result possible with one cubic curve </summary> As the following video shows, the flat segment of the superellipse curve is the hardest to approximate, since most of its curvature happens near the right end. The best that a single cubic curve can do is close to a straight line. https://github.com/user-attachments/assets/2ed1666d-f96c-4465-9d5c-1f8f4a660bba Although the largest deviation is only ~1e-6, the "feeling" from the lack of curvature is sensible as shown in the following screenshot. <img width="476" height="543" alt="image" src="https://github.com/user-attachments/assets/6e6b96ed-80b3-487c-b621-3cddd4537ec0" /> </details> **Result after this PR:** https://github.com/user-attachments/assets/d0012e62-f61f-4d69-95a5-27646c0bb750 The following screenshot shows the reproduction app as commented in https://github.com/flutter/flutter/issues/179875#issuecomment-3672426282 after the PR: <img width="476" height="543" alt="image" src="https://github.com/user-attachments/assets/d93b83be-a9fc-4b25-aca2-0e2c3f9a7e56" /> For comparison, the following screenshot shows the same shape drawn as filled: <img width="476" height="543" alt="image" src="https://github.com/user-attachments/assets/bf94a20a-278b-42a2-9162-5aa4a61915af" /> **Before the PR:** <img width="1024" height="796" alt="image" src="https://github.com/user-attachments/assets/053cc229-01f1-4181-97a6-48b96bf16fcf" /> Also, a new golden test: <img width="2400" height="1800" alt="image" src="https://github.com/user-attachments/assets/6e741066-89a3-4282-bdc2-fa02b1eea14d" /> ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md