Skip to content

Commit 8792feb

Browse files
committed
combine utils
1 parent e039a86 commit 8792feb

File tree

12 files changed

+95
-108
lines changed

12 files changed

+95
-108
lines changed

index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// https://www.blobmaker.app/
22

3-
import {rand} from "./internal/math/rand";
3+
import {rand} from "./internal/rand";
44
import {Shape} from "./internal/types";
5-
import {rad} from "./internal/math/unit";
6-
import {smooth} from "./internal/svg/smooth";
7-
import {renderEditable} from "./internal/svg/render";
5+
import {smooth, rad} from "./internal/util";
6+
import {renderEditable} from "./internal/render/svg";
87
import {XmlElement} from "./editable";
98

109
export interface PathOptions {

internal/shape/interpolate.ts renamed to internal/animate/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 "../math/geometry";
2+
import {split, splitLine} from "../util";
33

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

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

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

54
const optimizeOrder = (a: Shape, b: Shape): Shape => {
65
const count = a.length;
@@ -45,7 +44,7 @@ export const divideShape = (count: number, points: Shape): Shape => {
4544
const curr: Point = out[out.length - 1] || points[i];
4645
const next = points[(i + 1) % points.length];
4746
out.pop();
48-
out.push(...splitCurveBy(divisors[i], curr, next));
47+
out.push(...insertCount(divisors[i], curr, next));
4948
}
5049
const last = out.pop();
5150
out[0].handleIn = last!.handleIn;
@@ -91,14 +90,6 @@ const divideLengths = (lengths: number[], add: number): number[] => {
9190
return divisors;
9291
};
9392

94-
export const splitCurveBy = (count: number, a: Point, b: Point): Shape => {
95-
if (count < 2) return [a, b];
96-
const percentage = 1 / count;
97-
const [c, d, e] = split(percentage, a, b);
98-
if (count === 2) return [c, d, e];
99-
return [c, ...splitCurveBy(count - 1, d, e)];
100-
};
101-
10293
export const prepShapes = (a: Shape, b: Shape): [Shape, Shape] => {
10394
const points = Math.max(a.length, b.length);
10495
const aNorm = divideShape(points, a);

internal/math/geometry.ts

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

internal/math/unit.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.
File renamed without changes.

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

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

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

internal/svg/render.ts renamed to internal/render/svg.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import {loopAccess} from "./util";
21
import {xml, XmlElement} from "../../editable";
32
import {Shape} from "../types";
4-
import {expandHandle} from "../shape/util";
3+
import {expandHandle} from "../util";
54

65
export interface RenderOptions {
76
// Viewport size.
@@ -31,8 +30,8 @@ export const renderEditable = (points: Shape, opt: RenderOptions): XmlElement =>
3130
// Render path data attribute from points and handles.
3231
let path = `M${points[0].x},${points[0].y}`;
3332
for (let i = 0; i < points.length; i++) {
34-
const curr = loopAccess(points)(i);
35-
const next = loopAccess(points)(i + 1);
33+
const curr = points[i];
34+
const next = points[(i + 1) % points.length];
3635
const currControl = expandHandle(curr, curr.handleOut);
3736
const nextControl = expandHandle(next, next.handleIn);
3837
path += `C${currControl.x},${currControl.y},${nextControl.x},${nextControl.y},${next.x},${next.y}`;
@@ -80,8 +79,8 @@ export const renderEditable = (points: Shape, opt: RenderOptions): XmlElement =>
8079

8180
// Points and handles.
8281
for (let i = 0; i < points.length; i++) {
83-
const curr = loopAccess(points)(i);
84-
const next = loopAccess(points)(i + 1);
82+
const curr = points[i];
83+
const next = points[(i + 1) % points.length];
8584
const currControl = expandHandle(curr, curr.handleOut);
8685
const nextControl = expandHandle(next, next.handleIn);
8786

internal/svg/smooth.ts

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

internal/svg/util.ts

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

0 commit comments

Comments
 (0)