Skip to content

Add toroidal wrap function #1205

@hkiel

Description

@hkiel

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions