feat(libSceFreeTypeOt): implement ft_corner_is_flat and ft_corner_orientation #11426

Merged
iAbdulrrahman merged 1 commit from upstream-pr/11426 into main 2026-10-28 14:55:53 +00:00
iAbdulrrahman commented 2026-10-26 13:08:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by iAbdulrrahman on 2026-10-26T13:08:16Z.


What

Implement FreeType corner orientation and flatness algorithms for libSceFreeTypeOt (ft_corner_orientation and ft_corner_is_flat) based on FreeType 2.13.3 (ftcalc.c).

Tested

Built with CMake relinker configuration and executed guest_freetype_corner_tests covering orientation directions, collinearity, large 64-bit coordinates, flat and non-flat angles, dominant vectors, zero vectors, full-range identical vectors, and full-range perpendicular / near-perpendicular vectors under signed/unsigned and 128-bit boundaries.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5017950073 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11426). Originally posted by [iAbdulrrahman](https://github.com/iAbdulrrahman) on 2026-10-26T13:08:16Z. --- ### What Implement FreeType corner orientation and flatness algorithms for `libSceFreeTypeOt` (`ft_corner_orientation` and `ft_corner_is_flat`) based on FreeType 2.13.3 (`ftcalc.c`). ### Tested Built with CMake relinker configuration and executed `guest_freetype_corner_tests` covering orientation directions, collinearity, large 64-bit coordinates, flat and non-flat angles, dominant vectors, zero vectors, full-range identical vectors, and full-range perpendicular / near-perpendicular vectors under signed/unsigned and 128-bit boundaries. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-26 13:15:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T13:15:11Z.

Review: APPROVED


Reviewed the implementation against the linked FreeType 2.13.3 ftcalc.c source: the orientation cross-product/sign and FT_HYPOT corner-flatness comparison match the reference algorithm. I also ran tools/nid_names.py for both names; it maps ft_corner_is_flat to P6WOAeb0lJ8 and ft_corner_orientation to XGVABnpNksQ, matching the replaced exports. The reported focused test covers the core direction, collinearity, flatness, and degenerate-vector cases; hosted policy checks pass. No title/PS5 runtime call or console-version equivalence is established, as the debt entry states.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5652537582 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11426#pullrequestreview-5652537582). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T13:15:11Z. **Review:** APPROVED --- Reviewed the implementation against the linked FreeType 2.13.3 `ftcalc.c` source: the orientation cross-product/sign and `FT_HYPOT` corner-flatness comparison match the reference algorithm. I also ran `tools/nid_names.py` for both names; it maps `ft_corner_is_flat` to `P6WOAeb0lJ8` and `ft_corner_orientation` to `XGVABnpNksQ`, matching the replaced exports. The reported focused test covers the core direction, collinearity, flatness, and degenerate-vector cases; hosted policy checks pass. No title/PS5 runtime call or console-version equivalence is established, as the debt entry states.
MarcZX10 commented 2026-10-26 13:54:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T13:54:19Z.

Review: CHANGES_REQUESTED


The flatness implementation has undefined behavior for values within its declared std::int64_t input range. I reproduced signed overflow with UBSan using the exact calculation from this PR and ft_corner_is_flat_nid_postfix(INT64_MAX, 0, 1, 0): in_x + out_x overflows at ax. The later inDist + outDist - hypotDist expression can also overflow for large magnitudes. The new tests described as large 64-bit coordinates use 1e9, so they do not exercise 64-bit boundaries.

Please make these intermediates overflow-defined (or explicitly reject out-of-range inputs if that matches the console contract) and add boundary tests that run under UBSan. I could not build this test target with the local ANYPS5_RELINKER_ONLY=ON configuration because that mode returns before adding core/libs; the standalone UBSan reproduction did confirm the overflow.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5653056968 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11426#pullrequestreview-5653056968). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T13:54:19Z. **Review:** CHANGES_REQUESTED --- The flatness implementation has undefined behavior for values within its declared `std::int64_t` input range. I reproduced signed overflow with UBSan using the exact calculation from this PR and `ft_corner_is_flat_nid_postfix(INT64_MAX, 0, 1, 0)`: `in_x + out_x` overflows at `ax`. The later `inDist + outDist - hypotDist` expression can also overflow for large magnitudes. The new tests described as large 64-bit coordinates use `1e9`, so they do not exercise 64-bit boundaries. Please make these intermediates overflow-defined (or explicitly reject out-of-range inputs if that matches the console contract) and add boundary tests that run under UBSan. I could not build this test target with the local `ANYPS5_RELINKER_ONLY=ON` configuration because that mode returns before adding `core/libs`; the standalone UBSan reproduction did confirm the overflow.
MarcZX10 commented 2026-10-26 14:12:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T14:12:20Z.

Review: CHANGES_REQUESTED


The new unsigned intermediates remove signed-overflow UB, but they still wrap and misclassify valid full-range inputs. I compiled the updated calculation under UBSan and ran ft_corner_is_flat(INT64_MAX, INT64_MAX, INT64_MAX, INT64_MAX): it returns 0. These vectors point in exactly the same direction, so FreeType’s flatness criterion returns 1 (the distance deficit is zero). The unsigned inDist + outDist wraps here, and the conversion to ax/ay also loses the mathematical sum. Please use overflow-safe/wider arithmetic or constrain the supported input range to the actual console contract, and add this same-direction boundary case plus a near-perpendicular boundary case. This is a defined-result correctness issue, separate from the previous UBSan overflow.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5653330559 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11426#pullrequestreview-5653330559). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T14:12:20Z. **Review:** CHANGES_REQUESTED --- The new unsigned intermediates remove signed-overflow UB, but they still wrap and misclassify valid full-range inputs. I compiled the updated calculation under UBSan and ran `ft_corner_is_flat(INT64_MAX, INT64_MAX, INT64_MAX, INT64_MAX)`: it returns 0. These vectors point in exactly the same direction, so FreeType’s flatness criterion returns 1 (the distance deficit is zero). The unsigned `inDist + outDist` wraps here, and the conversion to `ax`/`ay` also loses the mathematical sum. Please use overflow-safe/wider arithmetic or constrain the supported input range to the actual console contract, and add this same-direction boundary case plus a near-perpendicular boundary case. This is a defined-result correctness issue, separate from the previous UBSan overflow.
MarcZX10 commented 2026-10-26 16:13:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T16:13:04Z.

Review: DISMISSED


Re-reviewed exact head 6465f72851f0. The new 128-bit arithmetic fixes the same-direction INT64_MAX failure I reported earlier; I compiled the exact two function bodies and the current regression test source in a standalone C++20 harness with UBSan, and the test program passes. Current-main conventions and git diff --check pass, the merge preview is clean, and no intervening main change touches this PR's files. I did not build the full CMake target.

Two repository-rule items remain before approval:

  1. The branch is based on bf77a9e9cba4, while live main is da89f18ea7c1. CONTRIBUTING requires branches to stay current; please sync to live main.
  2. The overlap check still reports the shared docs/dev/debt/libSceFreeTypeOt.md line with open PRs #9792, #9802, #9924, #10178 and #10897. I understand these add independent exports, but the checklist still says Depends on: none and I found no agreement on the debt-line merge order. CONTRIBUTING asks authors to agree which overlapping PR lands first and declare that order. Please coordinate with those authors and record the agreed order or reconciliation in the checklist.

The earlier arithmetic finding is resolved; this request is only for branch freshness and overlap coordination.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5655220770 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11426#pullrequestreview-5655220770). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T16:13:04Z. **Review:** DISMISSED --- Re-reviewed exact head `6465f72851f0`. The new 128-bit arithmetic fixes the same-direction `INT64_MAX` failure I reported earlier; I compiled the exact two function bodies and the current regression test source in a standalone C++20 harness with UBSan, and the test program passes. Current-main conventions and `git diff --check` pass, the merge preview is clean, and no intervening `main` change touches this PR's files. I did not build the full CMake target. Two repository-rule items remain before approval: 1. The branch is based on `bf77a9e9cba4`, while live `main` is `da89f18ea7c1`. CONTRIBUTING requires branches to stay current; please sync to live `main`. 2. The overlap check still reports the shared `docs/dev/debt/libSceFreeTypeOt.md` line with open PRs #9792, #9802, #9924, #10178 and #10897. I understand these add independent exports, but the checklist still says `Depends on: none` and I found no agreement on the debt-line merge order. CONTRIBUTING asks authors to agree which overlapping PR lands first and declare that order. Please coordinate with those authors and record the agreed order or reconciliation in the checklist. The earlier arithmetic finding is resolved; this request is only for branch freshness and overlap coordination.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!11426
No description provided.