-
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.
Add keyboard controls for angle graphs
- Loading branch information
1 parent
b8a342c
commit ec33ba9
Showing
21 changed files
with
505 additions
and
129 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,5 @@ | ||
--- | ||
"@khanacademy/perseus": minor | ||
--- | ||
|
||
Add keyboard controls to Mafs angle graphs |
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
69 changes: 69 additions & 0 deletions
69
packages/perseus/src/widgets/interactive-graphs/graphs/angle.test.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import {getAngleSideConstraint} from "./angle"; | ||
|
||
import type {vec} from "mafs"; | ||
|
||
function closeTo(x: number) { | ||
return expect.closeTo(x, 6); | ||
} | ||
|
||
describe("getAngleSideConstraint", () => { | ||
it("prevents vertical movement given a vertical side of an angle", () => { | ||
const side: vec.Vector2 = [0, 5]; | ||
const vertex: vec.Vector2 = [0, 0]; | ||
const snapDegrees = 45; | ||
|
||
const constraint = getAngleSideConstraint(side, vertex, snapDegrees); | ||
|
||
expect(constraint).toEqual({ | ||
up: side, | ||
down: side, | ||
left: [closeTo(-5), 5], | ||
right: [closeTo(5), 5], | ||
}); | ||
}); | ||
|
||
it("prevents horizontal movement given a horizontal side of an angle", () => { | ||
const side: vec.Vector2 = [5, 0]; | ||
const vertex: vec.Vector2 = [0, 0]; | ||
const snapDegrees = 45; | ||
|
||
const constraint = getAngleSideConstraint(side, vertex, snapDegrees); | ||
|
||
expect(constraint).toEqual({ | ||
up: [5, closeTo(5)], | ||
down: [5, closeTo(-5)], | ||
left: side, | ||
right: side, | ||
}); | ||
}); | ||
|
||
it("assigns the correct points to 'left' and 'right' when the side is pointing down", () => { | ||
const side: vec.Vector2 = [0, -5]; | ||
const vertex: vec.Vector2 = [0, 0]; | ||
const snapDegrees = 45; | ||
|
||
const constraint = getAngleSideConstraint(side, vertex, snapDegrees); | ||
|
||
expect(constraint).toEqual({ | ||
up: side, | ||
down: side, | ||
left: [closeTo(-5), -5], | ||
right: [closeTo(5), -5], | ||
}); | ||
}); | ||
|
||
it("assigns the correct points to 'up' and 'down' when the side is pointing left", () => { | ||
const side: vec.Vector2 = [-5, 0]; | ||
const vertex: vec.Vector2 = [0, 0]; | ||
const snapDegrees = 45; | ||
|
||
const constraint = getAngleSideConstraint(side, vertex, snapDegrees); | ||
|
||
expect(constraint).toEqual({ | ||
up: [-5, closeTo(5)], | ||
down: [-5, closeTo(-5)], | ||
left: side, | ||
right: side, | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.