-
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.
Merge branch 'main' into sr-linear-interactive-elements
- Loading branch information
Showing
223 changed files
with
2,415 additions
and
3,708 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
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.
Oops, something went wrong.