Skip to content

Commit 0d4c035

Browse files
committed
move animation code into internal dir
1 parent 52451b4 commit 0d4c035

File tree

11 files changed

+30
-34
lines changed

11 files changed

+30
-34
lines changed

animate/util.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

animate/animate/types.ts renamed to internal/animate/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Shape} from "../bezier/types";
1+
import {Shape} from "../shape/types";
22

33
export interface EasingFunc {
44
(progress: number): number;

animate/canvas/draw.ts renamed to internal/canvas/draw.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {Coord, Point, Shape} from "../bezier/types";
2-
import {expandHandle} from "../bezier/util";
1+
import {Coord, Shape} from "../shape/types";
2+
import {expandHandle} from "../shape/util";
33

44
const pointSize = 2;
55
const infoSpacing = 20;

internal/math/geometry.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
import {deg} from "./unit";
2+
import {Coord} from "../shape/types";
23

34
export interface Point {
45
x: number;
56
y: number;
67
}
78

89
// Calculates distance between two points.
9-
export const distance = (p1: Point, p2: Point): number => {
10-
return Math.sqrt((p1.x - p2.x) ** 2 + (p1.y - p2.y) ** 2);
10+
export const distance = (a: Point, b: Point): number => {
11+
return Math.sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2);
1112
};
1213

13-
// Calculates the angle of the line from p1 to p2 in degrees.
14-
export const angle = (p1: Point, p2: Point): number => {
15-
return deg(Math.atan2(p2.y - p1.y, p2.x - p1.x));
14+
// Calculates the angle of the line from a to b in degrees.
15+
export const angle = (a: Point, b: Point): number => {
16+
return deg(Math.atan2(b.y - a.y, b.x - a.x));
17+
};
18+
19+
export const split = (percentage: number, a: number, b: number): number => {
20+
return a + percentage * (b - a);
21+
};
22+
23+
export const splitLine = (percentage: number, a: Coord, b: Coord): Coord => {
24+
return {
25+
x: split(percentage, a.x, b.x),
26+
y: split(percentage, a.y, b.y),
27+
};
1628
};

animate/bezier/interpolate.ts renamed to internal/shape/interpolate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Shape} from "./types";
2-
import {split, splitLine} from "../util";
2+
import {split, splitLine} from "../math/geometry";
33

44
const interpolateAngle = (percentage: number, a: number, b: number): number => {
55
const tau = Math.PI * 2;

animate/bezier/prepare.ts renamed to internal/shape/prepare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {copyPoint, length, reverse, shift, split} from "./util";
22
import {Point, Shape} from "./types";
3-
import {distance} from "../util";
3+
import {distance} from "../math/geometry";
44

55
const optimizeOrder = (a: Shape, b: Shape): Shape => {
66
const count = a.length;
File renamed without changes.

animate/bezier/util.ts renamed to internal/shape/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Coord, Handle, Point, Shape} from "./types";
2-
import {distance, splitLine} from "../util";
2+
import {distance, splitLine} from "../math/geometry";
33

44
export const copyPoint = (p: Point): Point => ({
55
x: p.x,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"build": "npm run clean && rollup -c rollup.config.ts",
1313
"clean": "trash '**/*.js' '**/*.js.map' '**/*.d.ts' '!**/node_modules/**/*'",
1414
"fmt": "prettier --list-different --write --ignore-path .gitignore '**/*.{js,ts}'",
15-
"dev:animate": "parcel animate/index.html --open",
15+
"anim": "parcel testing/animate.html --open",
1616
"test": "jest"
1717
},
1818
"devDependencies": {

animate/index.html renamed to testing/animate.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</head>
1919

2020
<body>
21-
<script src="./test.ts"></script>
21+
<script src="./animate.ts"></script>
2222
</body>
2323

2424
</html>

0 commit comments

Comments
 (0)