Skip to content

feat: expand configurable FixedPoint<I,F> across entire library and standardize Doxygen - #13

Open
robertoduarte wants to merge 2 commits into
mainfrom
feature/configurable-fxp-library-wide
Open

feat: expand configurable FixedPoint<I,F> across entire library and standardize Doxygen#13
robertoduarte wants to merge 2 commits into
mainfrom
feature/configurable-fxp-library-wide

Conversation

@robertoduarte

Copy link
Copy Markdown
Owner

Extend the configurable FixedPoint<I, F> template to all math types — vectors, matrices, planes, spheres, AABBs, frustums, and collision functions — so every geometric type is parameterized by integer/fractional bit widths and can operate in any fixed-point format.

Geometric type templation:

  • Vector2<I,F> and Vector3<I,F> replace the monomorphic Vector2D/Vector3D structs. Vector3 no longer inherits from Vector2; both are standalone with their own X/Y(/Z) members, eliminating slicing issues and simplifying template parameterization.

  • Matrix3x3<I,F> and Matrix4x3<I,F> replace Matrix33/Matrix43. Matrix4x3 no longer inherits from Matrix3x3; it composes a 3x3 rotation block and a separate translation row, avoiding diamond-inheritance problems when both are parameterized.

  • PlaneX<I,F>, SphereX<I,F>, AABBX<I,F>, FrustumX<I,F>, and Collision functions are all templated. Bare aliases (Vector2D, Vector3D, Matrix33, AABB, Sphere, Plane, Frustum) are preserved as synonyms for the default Q16.16 format.

Hardware abstraction layer:

  • Extract all SH-2 inline assembly from fxp.hpp into new hardware.hpp (DIVU registers, 64-bit MAC multiplication, xtrct extraction, arithmetic shifts) with constexpr fallbacks for compile-time evaluation. Math files now contain only portable C++ logic.

  • Extract integer square root implementations into new integer.hpp (FastSqrt32/FastSqrt64), used by FixedPoint::Sqrt and vector Length().

  • Add new constmath.hpp with constexpr-only math functions (Sqrt, Sin, Cos, Tan, Atan, Atan2) for compile-time contexts where hardware intrinsics are unavailable.

FixedPoint changes:

  • Add InternalSqrtFrom64: format-agnostic 64-bit sqrt for vector Length() using MAC register output (hi/lo pair), replacing per-vector inline asm.

  • Add ConvertUnchecked: silent conversion overload for cases where the caller knows the value fits, bypassing the [[deprecated]] warning.

  • Add ParallelDiv API: free function + proxy type that overlaps CPU work with the hardware DIVU, replacing the deprecated AsyncDivSet/Get pair.

  • Change RawValue() to return by value instead of const ref for register passing on SH-2.

  • Annotate all operators with [[gnu::always_inline]] for consistent codegen.

  • Rename format aliases to include explicit bit layout: Fxp16->Fxp16_16, Fxp8->Fxp24_8, Fxp24->Fxp8_24.

  • Add FixedPointType concept for SFINAE/constraint use.

Trigonometry rewrite:

  • Restructure LookupCache with explicit mask/shift template params.
  • Move table generation to detail namespace with MakeLookupTable helper.
  • Rebuild Sin/Tan/Atan2 tables with format-aware entry types.
  • Make all functions constexpr-compatible via constmath fallbacks.
  • Simplify Precision enum (remove Accurate/Fast/Turbo modes from most functions; TurboLength kept as a named method on vectors).

Doxygen standardization:

Test suite reorganization:

  • Split multi-format tests into dedicated test_constmath.hpp, test_integer.hpp, test_utils.hpp.
  • Merge test_aabb_edge_cases.cpp into test_aabb.hpp and delete the standalone file.
  • Update all test files to use new templated type names.

…tandardize Doxygen

Extend the configurable FixedPoint<I, F> template to all math types — vectors, matrices, planes, spheres, AABBs, frustums, and collision functions — so every geometric type is parameterized by integer/fractional bit widths and can operate in any fixed-point format.

Geometric type templation:

- Vector2<I,F> and Vector3<I,F> replace the monomorphic Vector2D/Vector3D structs. Vector3 no longer inherits from Vector2; both are standalone with their own X/Y(/Z) members, eliminating slicing issues and simplifying template parameterization.

- Matrix3x3<I,F> and Matrix4x3<I,F> replace Matrix33/Matrix43. Matrix4x3 no longer inherits from Matrix3x3; it composes a 3x3 rotation block and a separate translation row, avoiding diamond-inheritance problems when both are parameterized.

- PlaneX<I,F>, SphereX<I,F>, AABBX<I,F>, FrustumX<I,F>, and Collision functions are all templated. Bare aliases (Vector2D, Vector3D, Matrix33, AABB, Sphere, Plane, Frustum) are preserved as synonyms for the default Q16.16 format.

Hardware abstraction layer:

- Extract all SH-2 inline assembly from fxp.hpp into new hardware.hpp (DIVU registers, 64-bit MAC multiplication, xtrct extraction, arithmetic shifts) with constexpr fallbacks for compile-time evaluation. Math files now contain only portable C++ logic.

- Extract integer square root implementations into new integer.hpp (FastSqrt32/FastSqrt64), used by FixedPoint::Sqrt and vector Length().

- Add new constmath.hpp with constexpr-only math functions (Sqrt, Sin, Cos, Tan, Atan, Atan2) for compile-time contexts where hardware intrinsics are unavailable.

FixedPoint changes:

- Add InternalSqrtFrom64: format-agnostic 64-bit sqrt for vector Length() using MAC register output (hi/lo pair), replacing per-vector inline asm.

- Add ConvertUnchecked: silent conversion overload for cases where the caller knows the value fits, bypassing the [[deprecated]] warning.

- Add ParallelDiv API: free function + proxy type that overlaps CPU work with the hardware DIVU, replacing the deprecated AsyncDivSet/Get pair.

- Change RawValue() to return by value instead of const ref for register passing on SH-2.

- Annotate all operators with [[gnu::always_inline]] for consistent codegen.

- Rename format aliases to include explicit bit layout: Fxp16->Fxp16_16, Fxp8->Fxp24_8, Fxp24->Fxp8_24.

- Add FixedPointType concept for SFINAE/constraint use.

Trigonometry rewrite:

- Restructure LookupCache with explicit mask/shift template params.
- Move table generation to detail namespace with MakeLookupTable helper.
- Rebuild Sin/Tan/Atan2 tables with format-aware entry types.
- Make all functions constexpr-compatible via constmath fallbacks.
- Simplify Precision enum (remove Accurate/Fast/Turbo modes from most functions; TurboLength kept as a named method on vectors).

Doxygen standardization:

- Apply uniform Doxygen across all impl/ files with @brief, @details, @param, @return, @note, /**< and @name groups for consistent API documentation.

Test suite reorganization:

- Split multi-format tests into dedicated test_constmath.hpp, test_integer.hpp, test_utils.hpp.
- Merge test_aabb_edge_cases.cpp into test_aabb.hpp and delete the standalone file.
- Update all test files to use new templated type names.
@robertoduarte
robertoduarte requested review from ReyeMe and willll July 1, 2026 21:38
…al Dot overflow

Extract32: replace logical shifts (shlr) with ArithmeticShiftRight in the shift>16 branch. The previous shlr instructions zero-filled the sign bit after xtrct, corrupting negative fixed-point products (e.g. -0.333 became +255.7). This was the root cause of catastrophic normalization errors for vectors with negative components, which made 3D objects invisible when the camera viewed them from certain angles.

Also fix consteval Dot product in Vector2D and Vector3D to use int64_t intermediate accumulation, preventing overflow in compile-time constant expressions.

@ReyeMe ReyeMe left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few documentation comments are missing, otherwise looks good

Comment thread impl/trigonometry.hpp
// Sin table — 64 entries, 10-bit interpolation, 8.24 internal format
// ================================================================

struct SinSpec

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing documentation of the struct and its members

Comment thread impl/trigonometry.hpp
SinSpec::interpolationMask,
SinSpec::extractShift>;

constexpr SinEntry BuildSinEntry(int index)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing documentation

Comment thread impl/trigonometry.hpp
// Range: 0 to 0x3C00 (0° to 84.375°), step = 1024 raw units
// ================================================================

struct Tan1Spec

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing documentation of the struct and its members

Comment thread impl/trigonometry.hpp
Tan1Spec::interpolationMask,
Tan1Spec::extractShift>;

constexpr Tan1Entry BuildTan1Entry(int index)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing documentation

Comment thread impl/trigonometry.hpp
};
}

inline constexpr auto tanTable1 = MakeLookupTable<Tan1Entry, Tan1Spec::entryCount, BuildTan1Entry>();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing documentation

Comment thread impl/trigonometry.hpp
};
}

inline constexpr auto tanTable5 = MakeLookupTable<Tan5Entry, Tan5Spec::entryCount, BuildTan5Entry>();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing documentation

Comment thread impl/trigonometry.hpp
// Maps ratio [0, 1] to angle [0, π/4] in turns
// ================================================================

struct Atan2Spec

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing documentation of the struct and its members

Comment thread impl/trigonometry.hpp
Atan2Spec::interpolationMask,
Atan2Spec::extractShift>;

constexpr Atan2Entry BuildAtan2Entry(int index)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing documentation

Comment thread impl/trigonometry.hpp
return { value, static_cast<uint16_t>(multiplicand) };
}

inline constexpr auto atan2Table = MakeLookupTable<Atan2Entry, Atan2Spec::entryCount, BuildAtan2Entry>();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing documentation

Comment thread impl/trigonometry.hpp
*/
class Trigonometry final
{
private:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private members are missing documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants