Skip to content

Add additional math methods#140

Open
tychedelia wants to merge 3 commits intoprocessing:mainfrom
tychedelia:feature/135-math-methods
Open

Add additional math methods#140
tychedelia wants to merge 3 commits intoprocessing:mainfrom
tychedelia:feature/135-math-methods

Conversation

@tychedelia
Copy link
Copy Markdown
Member

@tychedelia tychedelia changed the title Feature/135 math methods Add additional math methods Apr 25, 2026
return (value - start) / (stop - start)


def remap(value, start1, stop1, start2, stop2):
Copy link
Copy Markdown

@SableRaf SableRaf Apr 25, 2026

Choose a reason for hiding this comment

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

Not a blocker but we could potentially add the optional 6th argument from p5.js's version of the map() function: map(value, start1, stop1, start2, stop2, [withinBounds]) where withinBounds is a boolean which (if true) makes the function constrain the return value to the newly mapped range.

@SableRaf
Copy link
Copy Markdown

SableRaf commented Apr 25, 2026

Could we explicitly address the tradeoffs before making a decision on map() vs remap()?

From issue #131 it seems like there are at least two possible directions:

  1. Keep map() for Processing compatibility, possibly by dispatching based on arguments like Processing.py does.
  2. Use remap() to avoid shadowing Python’s built-in map(), like py5 does (see @hx2A's comment on 131)

Note: we should document this type of decisions on GitHub, since not everyone is on Discord and messages there are not publicly available without an account.

@SableRaf SableRaf self-requested a review April 25, 2026 06:18
@@ -0,0 +1,69 @@
"""Processing math methods and vector/quaternion types."""
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This PR implements the following functions from Processing4:

sin(), cos(), tan(), asin(), acos(), atan(), atan2(), sqrt(), exp(), log(), ceil(), floor(), degrees(), radians(), sq(), pow(), constrain(), lerp(), norm(), map(), mag(), dist()

It's currently missing:

@@ -0,0 +1,69 @@
"""Processing math methods and vector/quaternion types."""
from .mewnala import math as _native_math
from math import (
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do all of these methods behave like their Processing equivalent?

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.

Add math methods sin(), cos(), tan(), abs() etc.

2 participants