-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Summary: This looks like a lot, but it's basically just moving one file and updating imports. Issue: LEMS-2737 ## Test plan: - No functionality should change, just moving types Author: handeyeco Reviewers: handeyeco, jeremywiebe, Myranae Required Reviewers: Approved By: jeremywiebe Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x) Pull Request URL: #2101
- Loading branch information
Showing
184 changed files
with
1,680 additions
and
1,644 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
"@khanacademy/perseus": major | ||
"@khanacademy/kmath": minor | ||
"@khanacademy/perseus-core": minor | ||
"@khanacademy/perseus-score": minor | ||
"@khanacademy/perseus-dev-ui": patch | ||
"@khanacademy/math-input": patch | ||
"@khanacademy/perseus-editor": patch | ||
--- | ||
|
||
Move scorers and validators to `perseus-score` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import type {SineCoefficient} from "./geometry"; | ||
import type {Coord} from "@khanacademy/perseus-core"; | ||
|
||
export type NamedSineCoefficient = { | ||
amplitude: number; | ||
angularFrequency: number; | ||
phase: number; | ||
verticalOffset: number; | ||
}; | ||
|
||
// TODO: there's another, very similar getSinusoidCoefficients function | ||
// they should probably be merged | ||
export function getSinusoidCoefficients( | ||
coords: ReadonlyArray<Coord>, | ||
): SineCoefficient { | ||
// It's assumed that p1 is the root and p2 is the first peak | ||
const p1 = coords[0]; | ||
const p2 = coords[1]; | ||
|
||
// Resulting coefficients are canonical for this sine curve | ||
const amplitude = p2[1] - p1[1]; | ||
const angularFrequency = Math.PI / (2 * (p2[0] - p1[0])); | ||
const phase = p1[0] * angularFrequency; | ||
const verticalOffset = p1[1]; | ||
|
||
return [amplitude, angularFrequency, phase, verticalOffset]; | ||
} | ||
|
||
export type QuadraticCoefficient = [number, number, number]; | ||
|
||
// TODO: there's another, very similar getQuadraticCoefficients function | ||
// they should probably be merged | ||
export function getQuadraticCoefficients( | ||
coords: ReadonlyArray<Coord>, | ||
): QuadraticCoefficient { | ||
const p1 = coords[0]; | ||
const p2 = coords[1]; | ||
const p3 = coords[2]; | ||
|
||
const denom = (p1[0] - p2[0]) * (p1[0] - p3[0]) * (p2[0] - p3[0]); | ||
if (denom === 0) { | ||
// Many of the callers assume that the return value is always defined. | ||
// @ts-expect-error - TS2322 - Type 'undefined' is not assignable to type 'QuadraticCoefficient'. | ||
return; | ||
} | ||
const a = | ||
(p3[0] * (p2[1] - p1[1]) + | ||
p2[0] * (p1[1] - p3[1]) + | ||
p1[0] * (p3[1] - p2[1])) / | ||
denom; | ||
const b = | ||
(p3[0] * p3[0] * (p1[1] - p2[1]) + | ||
p2[0] * p2[0] * (p3[1] - p1[1]) + | ||
p1[0] * p1[0] * (p2[1] - p3[1])) / | ||
denom; | ||
const c = | ||
(p2[0] * p3[0] * (p2[0] - p3[0]) * p1[1] + | ||
p3[0] * p1[0] * (p3[0] - p1[0]) * p2[1] + | ||
p1[0] * p2[0] * (p1[0] - p2[0]) * p3[1]) / | ||
denom; | ||
return [a, b, c]; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import type {Coord} from "@khanacademy/perseus-core"; | ||
|
||
export type QuadraticCoords = [Coord, Coord, Coord]; |
3 changes: 2 additions & 1 deletion
3
packages/math-input/src/components/key-handlers/key-translator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import deepClone from "./deep-clone"; | ||
|
||
describe("deepClone", () => { | ||
it("does nothing to a primitive", () => { | ||
expect(deepClone(3)).toBe(3); | ||
}); | ||
|
||
it("copies an array", () => { | ||
const input = [1, 2, 3]; | ||
|
||
const result = deepClone(input); | ||
|
||
expect(result).toEqual(input); | ||
expect(result).not.toBe(input); | ||
}); | ||
|
||
it("recursively clones array elements", () => { | ||
const input = [[1]]; | ||
|
||
const result = deepClone(input); | ||
|
||
expect(result).toEqual(input); | ||
expect(result[0]).not.toBe(input[0]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// TODO(benchristel): in the future, we may want to make deepClone work for | ||
// Record<string, Cloneable> as well. Currently, it only does arrays. | ||
type Cloneable = | ||
| null | ||
| undefined | ||
| boolean | ||
| string | ||
| number | ||
| Cloneable[] | ||
| readonly Cloneable[]; | ||
function deepClone<T extends Cloneable>(obj: T): T { | ||
if (Array.isArray(obj)) { | ||
return obj.map(deepClone) as T; | ||
} | ||
return obj; | ||
} | ||
|
||
export default deepClone; |
Oops, something went wrong.