-
-
Notifications
You must be signed in to change notification settings - Fork 86
Open
Description
Relevant sub-area for this feature?
Math
Feature details
Feature description
In many programs a value starts again at zero if it gets larger than a max value or appears at max value when it goes below zero. Provide a function that does the wrapping as a single function.
/**
* Wraps a value at 0 and max to constrain value between zero and max.
* @param value The value to wrap
* @param max The maximum value (excluded)
* @return The toroidally wrapped value
float wrap(float value, float max) {
if (value < 0) {
return value + max;
} else if (value >= max) {
return value - max;
}
return value;
}
Benefits
This would reduce code sizes and make these toroidal worlds easier to understand.
Would you like to help implement this feature?
Yes, I’d like to help with this
Metadata
Metadata
Assignees
Labels
No labels