Cocos AIR math
Stop once you can answer the task. Do not read another same-topic reference for the same question.
Scope: Mutable value types, matrix/quaternion transforms, colors, easing and random utilities.
Environment: use package imports in apps; source paths require an AIR checkout. See context.
Quick Start
For complete setup and teardown, read Quick Start.
Siblings: direct dependencies; reuse loaded skills.
Triggers
- Normalize vectors or compute angles
- Build matrices or read transforms back
- Convert quaternion and Euler rotations
- Test points and rectangles
- Parse colors or convert byte channels
- Interpolate values or choose easing curves
- Generate deterministic random values
- Round texture sizes or encode half floats
Exact API and symptom mappings: triggers.
Contracts
Static math operations use the out-first convention; avoid mutating frozen constants. Matrices are column-major and child world transforms compose parent world with child local.
Read references/contracts.md only when the task needs exact option rules, limits, error behavior or source annotations. Prefer the topic references below for a narrower question.
Common Mistakes
- [HIGH] Never mutate frozen vector constants.
- [HIGH] Copy vectors before mutating them for independent owners.
- [MEDIUM] Static operations write to supplied output objects.
- [MEDIUM] Color channels use bytes; angle APIs differ in units.
Read relevant wrong/right examples before implementation.
Reference map
- Compute with value types? - Mutation, color and bounds
- Transform order wrong? - Matrices and quaternion units
- Curves or random values? - Easing, bits and half floats