feat: implement essential numeric and logical builtin functions#27
Conversation
…#12) Adds 13 WGSL builtin functions: Numeric functions: - dot: Dot product for Vec{2,3,4}f/i/u - normalize: Unit vector for Vec{2,3,4}f - cross: Cross product for Vec3f - clamp: Value clamping for f32/i32/u32 and vectors - mix: Linear interpolation for f32 and Vec{2,3,4}f - floor: Floor for f32 and Vec{2,3,4}f - ceil: Ceiling for f32 and Vec{2,3,4}f - exp: Natural exponentiation for f32 and Vec{2,3,4}f - exp2: Base-2 exponentiation for f32 and Vec{2,3,4}f - degrees: Radians to degrees for f32 and Vec{2,3,4}f Logical functions: - all: Returns true if all components are true (Vec{2,3,4}b) - any: Returns true if any component is true (Vec{2,3,4}b) - select: Conditional select for all scalar and vector types Closes #12
There was a problem hiding this comment.
Pull request overview
This PR implements 13 essential numeric and logical builtin functions for WGSL, addressing Issue #12. The implementation adds dot product, vector normalization, cross product, clamping, linear interpolation, floor/ceiling operations, exponential functions, radians-to-degrees conversion, and logical operations (all, any, select).
Key Changes
- Added 10 numeric functions:
dot,normalize,cross,clamp,mix,floor,ceil,exp,exp2, anddegrees - Added 3 logical functions:
all,any, andselect - Added 13 sanity tests covering basic functionality of all new functions
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/wgsl-rs/src/std/numeric_builtin_functions.rs | Implements 13 new builtin functions following the trait-per-function pattern, adds sanity tests, and updates documentation table to mark functions as implemented |
| SESSION.md | Documents the implementation work including function list, type support matrix, and verification steps |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The documentation incorrectly stated 'e^e' which was confusing since 'e' was used for both the mathematical constant and the input variable. Changed to 'e raised to the power of the input' for clarity.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
* feat: implement essential numeric and logical builtin functions (issue #12) Adds 13 WGSL builtin functions: Numeric functions: - dot: Dot product for Vec{2,3,4}f/i/u - normalize: Unit vector for Vec{2,3,4}f - cross: Cross product for Vec3f - clamp: Value clamping for f32/i32/u32 and vectors - mix: Linear interpolation for f32 and Vec{2,3,4}f - floor: Floor for f32 and Vec{2,3,4}f - ceil: Ceiling for f32 and Vec{2,3,4}f - exp: Natural exponentiation for f32 and Vec{2,3,4}f - exp2: Base-2 exponentiation for f32 and Vec{2,3,4}f - degrees: Radians to degrees for f32 and Vec{2,3,4}f Logical functions: - all: Returns true if all components are true (Vec{2,3,4}b) - any: Returns true if any component is true (Vec{2,3,4}b) - select: Conditional select for all scalar and vector types Closes #12 * better select can use boolean vectors too * better select can use boolean vectors too * docs: fix exp function documentation to clarify e^x notation The documentation incorrectly stated 'e^e' which was confusing since 'e' was used for both the mathematical constant and the input variable. Changed to 'e raised to the power of the input' for clarity. * simplifications * deleted SelectCondition * pr fixup
Summary
Implements Issue #12 - Essential Numeric and Logical Builtin Functions (Priority 1)
Adds 13 WGSL builtin functions following the existing trait-per-function pattern.
Numeric Functions (10)
dot- Dot product for Vec{2,3,4}f/i/unormalize- Unit vector for Vec{2,3,4}fcross- Cross product for Vec3f onlyclamp- Value clamping for f32/i32/u32 and all vector typesmix- Linear interpolation for f32 and Vec{2,3,4}ffloor- Floor for f32 and Vec{2,3,4}fceil- Ceiling for f32 and Vec{2,3,4}fexp- Natural exponentiation (e^x) for f32 and Vec{2,3,4}fexp2- Base-2 exponentiation (2^x) for f32 and Vec{2,3,4}fdegrees- Radians to degrees for f32 and Vec{2,3,4}fLogical Functions (3)
all- Returns true if all components are true (Vec{2,3,4}b)any- Returns true if any component is true (Vec{2,3,4}b)select- Conditional select for all scalar and vector typesTesting
Closes #12