Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move math functions to a math/ folder #1390

Merged
merged 15 commits into from
Jul 3, 2024
Merged

Move math functions to a math/ folder #1390

merged 15 commits into from
Jul 3, 2024

Conversation

benchristel
Copy link
Member

@benchristel benchristel commented Jul 3, 2024

Note to reviewers: it's going to be easiest to review this PR one commit
at a time!

This is the first part of a multi-part refactor. I am submitting this
intermediate PR to get feedback and hopefully avoid running into too many
merge conflicts.

In future PRs, I plan to:

  • move more functions into math/
  • reuse the existing functions in more places
  • re-export functions from kmath in math/index.ts, possibly
    wrapping them with more suitable type signatures
  • fix TODOs added in this PR.

Adding a math/ folder gives us a clear place to put new mathy functions,
and will help us locate and reuse the functions that already exist.

Issue: LEMS-2135

Test plan:

yarn test

@khan-actions-bot
Copy link
Contributor

khan-actions-bot commented Jul 3, 2024

Gerald

Required Reviewers
  • @Khan/perseus for changes to .changeset/loud-goats-grow.md, packages/perseus/src/widgets/interactive-graphs/axis-labels.tsx, packages/perseus/src/widgets/interactive-graphs/axis-ticks.tsx, packages/perseus/src/widgets/interactive-graphs/grid.tsx, packages/perseus/src/widgets/interactive-graphs/legacy-grid.tsx, packages/perseus/src/widgets/interactive-graphs/mafs-graph.tsx, packages/perseus/src/widgets/interactive-graphs/protractor.tsx, packages/perseus/src/widgets/interactive-graphs/utils.test.ts, packages/perseus/src/widgets/interactive-graphs/utils.ts, packages/perseus/src/widgets/interactive-graphs/graphs/circle.tsx, packages/perseus/src/widgets/interactive-graphs/graphs/polygon.tsx, packages/perseus/src/widgets/interactive-graphs/graphs/sinusoid.tsx, packages/perseus/src/widgets/interactive-graphs/graphs/use-draggable.ts, packages/perseus/src/widgets/interactive-graphs/locked-figures/locked-line.tsx, packages/perseus/src/widgets/interactive-graphs/locked-figures/locked-polygon.tsx, packages/perseus/src/widgets/interactive-graphs/math/box.test.ts, packages/perseus/src/widgets/interactive-graphs/math/box.ts, packages/perseus/src/widgets/interactive-graphs/math/clamp.ts, packages/perseus/src/widgets/interactive-graphs/math/coordinates.ts, packages/perseus/src/widgets/interactive-graphs/math/index.ts, packages/perseus/src/widgets/interactive-graphs/math/interval.test.ts, packages/perseus/src/widgets/interactive-graphs/math/interval.ts, packages/perseus/src/widgets/interactive-graphs/math/snap.test.ts, packages/perseus/src/widgets/interactive-graphs/math/snap.ts, packages/perseus/src/widgets/interactive-graphs/reducer/interactive-graph-reducer.ts, packages/perseus/src/widgets/interactive-graphs/graphs/components/arrowhead.tsx, packages/perseus/src/widgets/interactive-graphs/graphs/components/axis-tick-labels.tsx, packages/perseus/src/widgets/interactive-graphs/graphs/components/movable-line.test.tsx, packages/perseus/src/widgets/interactive-graphs/graphs/components/movable-line.tsx, packages/perseus/src/widgets/interactive-graphs/graphs/components/movable-point-view.tsx, packages/perseus/src/widgets/interactive-graphs/graphs/components/movable-point.tsx, packages/perseus/src/widgets/interactive-graphs/graphs/components/svg-line.tsx

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

Copy link
Contributor

github-actions bot commented Jul 3, 2024

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (8416af8) and published it to npm. You
can install it using the tag PR1390.

Example:

yarn add @khanacademy/perseus@PR1390

If you are working in Khan Academy's webapp, you can run:

./dev/tools/bump_perseus_version.sh -t PR1390

Copy link
Contributor

github-actions bot commented Jul 3, 2024

Size Change: +568 B (+0.07%)

Total Size: 850 kB

Filename Size Change
packages/perseus/dist/es/index.js 411 kB +568 B (+0.14%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 38.2 kB
packages/kmath/dist/es/index.js 4.26 kB
packages/math-input/dist/es/index.js 80.8 kB
packages/math-input/dist/es/strings.js 1.73 kB
packages/perseus-core/dist/es/index.js 906 B
packages/perseus-editor/dist/es/index.js 272 kB
packages/perseus-error/dist/es/index.js 866 B
packages/perseus-linter/dist/es/index.js 21.8 kB
packages/perseus/dist/es/strings.js 3.21 kB
packages/pure-markdown/dist/es/index.js 3.67 kB
packages/simple-markdown/dist/es/index.js 12.4 kB

compressed-size-action

Copy link

codecov bot commented Jul 3, 2024

Codecov Report

Attention: Patch coverage is 94.65241% with 10 lines in your changes missing coverage. Please review.

Project coverage is 70.82%. Comparing base (d229cea) to head (8416af8).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1390      +/-   ##
==========================================
+ Coverage   69.61%   70.82%   +1.20%     
==========================================
  Files         493      504      +11     
  Lines      104305   104589     +284     
  Branches     7511    10634    +3123     
==========================================
+ Hits        72612    74075    +1463     
+ Misses      31513    30514     -999     
+ Partials      180        0     -180     

Impacted file tree graph

Files Coverage Δ
...eus/src/widgets/interactive-graphs/axis-labels.tsx 100.00% <100.00%> (ø)
...s/src/widgets/interactive-graphs/graphs/circle.tsx 98.46% <100.00%> (ø)
...interactive-graphs/graphs/components/arrowhead.tsx 100.00% <100.00%> (ø)
...tive-graphs/graphs/components/axis-tick-labels.tsx 99.01% <100.00%> (-0.33%) ⬇️
...eractive-graphs/graphs/components/movable-line.tsx 100.00% <100.00%> (ø)
...ractive-graphs/graphs/components/movable-point.tsx 100.00% <100.00%> (ø)
.../interactive-graphs/graphs/components/svg-line.tsx 100.00% <100.00%> (ø)
.../src/widgets/interactive-graphs/graphs/polygon.tsx 97.61% <100.00%> (+0.81%) ⬆️
...src/widgets/interactive-graphs/graphs/sinusoid.tsx 100.00% <100.00%> (ø)
...widgets/interactive-graphs/graphs/use-draggable.ts 96.53% <100.00%> (+0.02%) ⬆️
... and 16 more

... and 148 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d229cea...8416af8. Read the comment docs.

]);
}

export function ensureValid(box: Box): Box {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the comments for the other functions. Perhaps we could have one here, too? Mostly because I don't know what setting the min/max values to the average does.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think ensureValid is the wrong abstraction. The behavior of setting the values to the average is specific to inset. The purpose of setting min and max to the average is that the center of the box should not be changed by inset.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've reworked this code. Let me know what you think!

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes a LOT more sense! Thank you!!

@khan-actions-bot khan-actions-bot requested a review from a team July 3, 2024 21:23
Copy link
Contributor

@mark-fitzgerald mark-fitzgerald left a comment

Choose a reason for hiding this comment

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

The singular-function files (i.e. clamp.ts and coordiantes.ts) feel a bit light to me, but I understand the intent. I think that the organization and comments and tests help greatly to make this more readable.

@benchristel benchristel merged commit 7e6ccf3 into main Jul 3, 2024
11 checks passed
@benchristel benchristel deleted the benc/math branch July 3, 2024 22:01
SonicScrewdriver added a commit that referenced this pull request Jul 8, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @khanacademy/[email protected]

### Minor Changes

- [#1384](#1384)
[`5de483386`](5de4833)
Thanks [@catandthemachines](https://github.com/catandthemachines)! -
Updating TabBar experience in to use arrow-key navigation to access the
other TabItems. This will ensure the Expression Widget in perseus has
proper keyboard navigation for users.

## @khanacademy/[email protected]

### Minor Changes

- [#1383](#1383)
[`4b56e10de`](4b56e10)
Thanks [@mark-fitzgerald](https://github.com/mark-fitzgerald)! - View
Locked Functions in the Interactive Graph


- [#1392](#1392)
[`b710d07db`](b710d07)
Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! -
Creation of new angle graph for Mafs interactive graph widget

### Patch Changes

- [#1390](#1390)
[`7e6ccf38d`](7e6ccf3)
Thanks [@benchristel](https://github.com/benchristel)! - Internal: Move
graphing-agnostic, mathy functions in the interactive graph code to a
math/ folder.

- Updated dependencies
\[[`5de483386`](5de4833)]:
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

- [#1383](#1383)
[`4b56e10de`](4b56e10)
Thanks [@mark-fitzgerald](https://github.com/mark-fitzgerald)! - View
Locked Functions in the Interactive Graph


- [#1390](#1390)
[`7e6ccf38d`](7e6ccf3)
Thanks [@benchristel](https://github.com/benchristel)! - Internal: Move
graphing-agnostic, mathy functions in the interactive graph code to a
math/ folder.


- [#1392](#1392)
[`b710d07db`](b710d07)
Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! -
Creation of new angle graph for Mafs interactive graph widget

- Updated dependencies
\[[`4b56e10de`](4b56e10),
[`7e6ccf38d`](7e6ccf3),
[`5de483386`](5de4833),
[`b710d07db`](b710d07)]:
    -   @khanacademy/[email protected]
    -   @khanacademy/[email protected]

## @khanacademy/[email protected]

### Patch Changes

- Updated dependencies
\[[`5de483386`](5de4833)]:
    -   @khanacademy/[email protected]
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.

3 participants