Skip to content

Find and replace all magic number node parameter indexes with ::INDEX const #1490

Description

@Keavon

The best option is to replace indices with symbols, but the purely index-oriented approach is described below.


The task here is to use various searching and go-to-references/implementations techniques to find as many magic number indexes as possible for node parameters, and replace them with their node parameter's ::INDEX constant.

For example, two parameters of the Stroke node:

  • graphene_std::vector::stroke::ColorInput::INDEX (equals 1)
  • graphene_std::vector::stroke::DashLengthsInput::<Vec<f64>>::INDEX (equals 8)

Since this ::INDEX system is newer, there are many places we have magic numbers for indexes like 1 and 8 lying around in the code. They are probably often used to generate values for specific function calls. For example, InputConnector::node is one such function that can have its usages searched to find plenty of examples where magic number indexes are passed in, that should be replaced by an ::INDEX const instead. In some cases, this could be indirect, like if that function is passed a variable set elsewhere. And there are likely other functions besides that one, too, that are receiving magic number indexes.

After those techniques are completed, a final check should be done by manually checking through the ~1.5k (perhaps less after the other replacements are completed) results from this project-wide search:

  • Enable regex but not word boundaries or capitalization
  • Query: (?<!\d|[a-z]|\.|\\|'|"|= ?|> |return |[-+/*%] ?|_|; |NodeId\(|box\[|bounds\[|points\[|points_viewport\[|locations\[|display_decimal_places\(|_vertical\[|_horizontal\[|segments\[|handles\[|corners\[|radii\[|default\(|\.skip\(|\.min\(|\.max\(|digit: |Step |Case |Test |", |Vec2::new\(|powi\(|\[\d\]\[|\.0\[|[\s(][a-z]\[)[1-3]?\d(?!\d|[a-z]|\.|'|"|_|;.| [<>=]| ?px|\]\[|\]\.)
  • Files to include: editor/**/*.rs, node-graph/**/*.rs
  • Files to exclude: document_migration.rs, document_node_definitions.rs

Activity

  1. added
    GrapheneInvolves the node graph system/engine used by Graphite
    on Dec 7, 2023
  2. Kakapio commented on Jan 19, 2024

    @Kakapio
  3. Keavon commented on Jan 22, 2024

    @Keavon
    Author
  4. moved this from Short-Term to Medium-Term in Task Boardon Jun 9, 2024
  5. added and removed
    GrapheneInvolves the node graph system/engine used by Graphite
    on Feb 10, 2026
  6. moved this from Medium-Term to Short-Term in Task Boardon Feb 10, 2026
  7. changed the title [-]Avoid using magic number indexes in the node system[/-] [+]Find and replace all magic number node parameter indexes with ::INDEX const[/+] on Feb 10, 2026
  8. 3 remaining items

  9. Keavon commented on Feb 23, 2026

    @Keavon
    MemberAuthor

    Also, see the note about AI usage I just added to the top of this issue description.

  10. added a commit that references this issue on Feb 25, 2026
    eeeafde
  11. Tyooughtul commented on Feb 25, 2026

    @Tyooughtul
    Image

    Hi@Keavon! I noticed that the test is failing, but I think it's unrelated to my PR for issue #1490. From what I can tell, it's a precision issue with the LUT in discrete_srgb.rs, the precomputed values don't exactly match the reference implementation due to floating-point rounding errors. I'd be happy to open a separate PR to fix this LUT issue if you'd like. Let me know what you think. Thanks!😊

  12. Keavon commented on Feb 25, 2026

    @Keavon
    MemberAuthor

    @Tyooughtul does the failure occur on the master branch? If so, that would indicate it is happening irrespective of your work in this branch. I'll take a look when you open a PR.

  13. added a commit that references this issue on Feb 25, 2026
    1be3fa4
  14. Tyooughtul commented on Feb 25, 2026

    @Tyooughtul
    Image it's true the error happens in the master branch
  15. added 5 commits that reference this issue on Feb 26, 2026
    d8474c4
    02b59b7
    945e712
    64be2d3
    8afb0ca
  16. added a commit that references this issue on Apr 20, 2026
    a68b239
  17. self-assigned this
    on Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

  • Status
    Short-Term

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions