processing / processing/processing4

Add toroidal wrap function

Open
#1,205 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
494
Forks
183
Avg merge
4h 39m
Merged PRs (30d)
3

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Processing core library's existing math entry points and any related wrapping logic. Define the toroidal wrap function described in the issue, then add or update coverage for values below zero, at or above the maximum, and values already in range.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.