Skip to content

feat(motion): add interpolate and mapRange helper#689

Open
realtushartyagi wants to merge 1 commit into
Karanjot786:mainfrom
realtushartyagi:feat/interpolate-maprange
Open

feat(motion): add interpolate and mapRange helper#689
realtushartyagi wants to merge 1 commit into
Karanjot786:mainfrom
realtushartyagi:feat/interpolate-maprange

Conversation

@realtushartyagi
Copy link
Copy Markdown

@realtushartyagi realtushartyagi commented Jun 4, 2026

Description

Adds mapRange and interpolate helpers to @termuijs/motion for mapping values between numeric ranges, with support for clamping, extrapolation, descending ranges, and safe handling of zero-width input ranges.

Related Issue

Closes #493

Which package(s)?

@termuijs/motion

Type of Change

  • 🐛 Bug fix (type:bug)
  • ✨ Feature (type:feature)
  • 📝 Docs (type:docs)
  • 🧪 Tests (type:testing)
  • ♻️ Refactor (type:refactor)
  • 🎨 Design / UX (type:design)
  • ♿ Accessibility (type:accessibility)
  • ⚡ Performance (type:performance)
  • 🔧 DevOps / CI (type:devops)
  • 🔒 Security (type:security)

Checklist

  • ⭐ You starred the repo. The needs-star check blocks your merge otherwise.
  • Tests pass locally: bun vitest run
  • Build passes: bun run build
  • Typecheck passes: bun run typecheck
  • You read CONTRIBUTING.md.
  • Your PR title follows type: short description.
  • Widget state mutators call markDirty() (if your change affects rendering).
  • No new any types without an inline comment explaining why.
  • No unrelated refactors bundled into this PR.

GSSoC 2026 Participation

  • You are a GSSoC 2026 contributor.
  • Your GSSoC profile: https://gssoc.girlscript.org/profile/f49aa65e-aab2-4e9f-99d6-2174f339ecfe

Screenshots / Recordings (UI changes)

(N/A - Pure mathematical utility functions with no UI)

Notes for the Reviewer

  • Added tests for range mapping, clamping, extrapolation, descending ranges, and zero-width inputs.
  • Verified interpolate delegates to mapRange.
  • Functions are pure and immutable.

Summary by CodeRabbit

  • New Features

    • Added numeric interpolation utilities to the motion package for mapping and transforming values between ranges with optional clamping support.
  • Tests

    • Added comprehensive test coverage for interpolation utilities, including edge cases and clamping behavior.

Copilot AI review requested due to automatic review settings June 4, 2026 09:22
@github-actions github-actions Bot added type:feature +10 pts. New feature. and removed type:feature +10 pts. New feature. labels Jun 4, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4943610e-7192-4c19-9fad-b1b1d390a7b8

📥 Commits

Reviewing files that changed from the base of the PR and between c36cc8c and a6f6d6d.

📒 Files selected for processing (3)
  • packages/motion/src/index.ts
  • packages/motion/src/interpolate.test.ts
  • packages/motion/src/interpolate.ts

📝 Walkthrough

Walkthrough

This PR adds numeric interpolation utilities to the @termuijs/motion package. The implementation introduces mapRange to transform values between numeric ranges and interpolate as a tuple-based convenience wrapper, both with optional clamping behavior. Tests validate midpoint mapping, default clamping, unclamped extrapolation, zero-width input handling, and descending output ranges.

Changes

Interpolation Helpers

Layer / File(s) Summary
Core interpolation implementation
packages/motion/src/interpolate.ts
InterpolateOptions with optional clamp flag, mapRange transforms values between input/output numeric ranges with optional clamping and zero-width guards, interpolate delegates to mapRange using tuple ranges.
Test coverage
packages/motion/src/interpolate.test.ts
Vitest suite covering midpoint mapping, default clamping behavior, unclamped extrapolation with clamp: false, zero-width input ranges, descending ranges, and tuple-based interpolation.
Public API export
packages/motion/src/index.ts
Package entry point re-exports mapRange, interpolate, and InterpolateOptions type.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

type:feature, type:testing, area:motion, level:beginner

Suggested reviewers

  • Karanjot786

Poem

🐰 From zero to one, the ranges align,
Mapping each value through numbers divine.
Clamp or extrapolate, the choice is yours true,
Now every motion can interpolate too! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(motion): add interpolate and mapRange helper' directly and concisely summarizes the main change—adding two new helper functions to the motion package.
Description check ✅ Passed The description covers all required template sections: clear problem statement, linked issue, affected package, type of change, completed checklist, and GSSoC participation with reviewer notes.
Linked Issues check ✅ Passed The PR fully implements all requirements from issue #493: mapRange and interpolate functions with correct signatures, clamping support, zero-width input handling, descending range support, and comprehensive test coverage.
Out of Scope Changes check ✅ Passed All changes are confined to packages/motion as required: new interpolate.ts implementation, interpolate.test.ts with comprehensive tests, and index.ts exports only. No modifications to other packages or unrelated code.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the type:testing +10 pts. Tests. label Jun 4, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds numeric interpolation utilities to @termuijs/motion, including a low-level range mapper and a tuple-based convenience wrapper, and exposes them via the package entrypoint with accompanying Vitest coverage.

Changes:

  • Added mapRange and interpolate helpers with optional clamping behavior.
  • Added Vitest tests covering default clamping, extrapolation, descending output ranges, and zero-width input ranges.
  • Exported the new helpers and option type from packages/motion/src/index.ts.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/motion/src/interpolate.ts Introduces mapRange and interpolate implementations and option type.
packages/motion/src/interpolate.test.ts Adds unit tests validating interpolation behavior and clamping.
packages/motion/src/index.ts Re-exports the new helpers/types from the package entrypoint.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +36 to +37
export { mapRange, interpolate } from './interpolate.js';
export type { InterpolateOptions } from './interpolate.js';
@github-actions github-actions Bot added the type:feature +10 pts. New feature. label Jun 4, 2026
@Karanjot786 Karanjot786 added gssoc:approved Approved PR. Earns +50 base points. quality:clean x 1.2 multiplier. Clean implementation. level:intermediate +35 pts. Moderate task. labels Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved PR. Earns +50 base points. level:intermediate +35 pts. Moderate task. quality:clean x 1.2 multiplier. Clean implementation. type:feature +10 pts. New feature. type:testing +10 pts. Tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(motion): add interpolate and mapRange helper

3 participants