Skip to content

Commit f1e0744

Browse files
committed
standardize options variable naming
1 parent ac8f194 commit f1e0744

File tree

4 files changed

+45
-45
lines changed

4 files changed

+45
-45
lines changed

internal/animate/prepare.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from "../util";
1313
import {Point} from "../types";
1414

15-
// OPT extract optimization logic
15+
// TODO OPT extract optimization logic
1616
const optimizeOrder = (a: Point[], b: Point[]): Point[] => {
1717
const count = a.length;
1818

@@ -40,7 +40,7 @@ const optimizeOrder = (a: Point[], b: Point[]): Point[] => {
4040
return shift(minOffset, minOffsetBase);
4141
};
4242

43-
// OPT allow extra division
43+
// TODO OPT allow extra division
4444
export const divide = (count: number, points: Point[]): Point[] => {
4545
if (points.length < 3) throw new Error("not enough points");
4646
if (count < points.length) throw new Error("cannot remove points");
@@ -65,7 +65,7 @@ export const divide = (count: number, points: Point[]): Point[] => {
6565
return out;
6666
};
6767

68-
// OPT disable
68+
// TODO OPT disable
6969
const fixAnglesWith = (fixee: Point[], fixer: Point[]): Point[] => {
7070
return mapPoints(fixee, ({index, curr, prev, next}) => {
7171
if (curr.handleIn.length === 0 && coordEqual(prev(), curr)) {
@@ -78,7 +78,7 @@ const fixAnglesWith = (fixee: Point[], fixer: Point[]): Point[] => {
7878
});
7979
};
8080

81-
// OPT disable
81+
// TODO OPT disable
8282
const fixAnglesSelf = (points: Point[]): Point[] => {
8383
return mapPoints(points, ({curr, prev, next}) => {
8484
const angle = angleOf(prev(), next());

internal/render/svg.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,40 +37,40 @@ export const renderPath = (points: Point[]): string => {
3737
};
3838

3939
// Renders the input points to an editable data structure which can be rendered to svg.
40-
export const renderEditable = (points: Point[], opt: RenderOptions): XmlElement => {
41-
const stroke = opt.stroke || (opt.guides ? "black" : "none");
42-
const strokeWidth = opt.strokeWidth || (opt.guides ? 1 : 0);
40+
export const renderEditable = (points: Point[], options: RenderOptions): XmlElement => {
41+
const stroke = options.stroke || (options.guides ? "black" : "none");
42+
const strokeWidth = options.strokeWidth || (options.guides ? 1 : 0);
4343

4444
const xmlRoot = xml("svg");
45-
xmlRoot.attributes.width = opt.width;
46-
xmlRoot.attributes.height = opt.height;
47-
xmlRoot.attributes.viewBox = `0 0 ${opt.width} ${opt.height}`;
45+
xmlRoot.attributes.width = options.width;
46+
xmlRoot.attributes.height = options.height;
47+
xmlRoot.attributes.viewBox = `0 0 ${options.width} ${options.height}`;
4848
xmlRoot.attributes.xmlns = "http://www.w3.org/2000/svg";
4949

5050
const xmlContentGroup = xml("g");
51-
xmlContentGroup.attributes.transform = opt.transform || "";
51+
xmlContentGroup.attributes.transform = options.transform || "";
5252

5353
const xmlBlobPath = xml("path");
5454
xmlBlobPath.attributes.stroke = stroke;
5555
xmlBlobPath.attributes["stroke-width"] = strokeWidth;
56-
xmlBlobPath.attributes.fill = opt.fill || "none";
56+
xmlBlobPath.attributes.fill = options.fill || "none";
5757
xmlBlobPath.attributes.d = renderPath(points);
5858

5959
xmlContentGroup.children.push(xmlBlobPath);
6060
xmlRoot.children.push(xmlContentGroup);
6161

6262
// Render guides if configured to do so.
63-
if (opt.guides) {
64-
const color = opt.stroke || "black";
65-
const size = opt.strokeWidth || 1;
63+
if (options.guides) {
64+
const color = options.stroke || "black";
65+
const size = options.strokeWidth || 1;
6666

6767
// Bounding box.
68-
if (opt.boundingBox) {
68+
if (options.boundingBox) {
6969
const xmlBoundingRect = xml("rect");
7070
xmlBoundingRect.attributes.x = 0;
7171
xmlBoundingRect.attributes.y = 0;
72-
xmlBoundingRect.attributes.width = opt.width;
73-
xmlBoundingRect.attributes.height = opt.height;
72+
xmlBoundingRect.attributes.width = options.width;
73+
xmlBoundingRect.attributes.height = options.height;
7474
xmlBoundingRect.attributes.fill = "none";
7575
xmlBoundingRect.attributes.stroke = color;
7676
xmlBoundingRect.attributes["stroke-width"] = 2 * size;

legacy/blobs.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,47 +41,47 @@ export interface BlobOptions extends PathOptions {
4141
}
4242

4343
// Generates an svg document string containing a randomized blob.
44-
const blobs = (opt: BlobOptions): string => {
45-
return blobs.editable(opt).render();
44+
const blobs = (options: BlobOptions): string => {
45+
return blobs.editable(options).render();
4646
};
4747

4848
// Generates a randomized blob as an editable data structure which can be rendered to an svg document.
49-
blobs.editable = (opt: BlobOptions): XmlElement => {
50-
if (!opt) {
49+
blobs.editable = (options: BlobOptions): XmlElement => {
50+
if (!options) {
5151
throw new Error("no options specified");
5252
}
5353

5454
// Random number generator.
55-
const rgen = rand(opt.seed || String(Date.now()));
55+
const rgen = rand(options.seed || String(Date.now()));
5656

57-
if (!opt.size) {
57+
if (!options.size) {
5858
throw new Error("no size specified");
5959
}
6060

61-
if (!opt.stroke && !opt.color) {
61+
if (!options.stroke && !options.color) {
6262
throw new Error("no color or stroke specified");
6363
}
6464

65-
if (opt.complexity <= 0 || opt.complexity > 1) {
65+
if (options.complexity <= 0 || options.complexity > 1) {
6666
throw new Error("complexity out of range ]0,1]");
6767
}
6868

69-
if (opt.contrast < 0 || opt.contrast > 1) {
69+
if (options.contrast < 0 || options.contrast > 1) {
7070
throw new Error("contrast out of range [0,1]");
7171
}
7272

73-
const count = 3 + Math.floor(14 * opt.complexity);
74-
const offset = (): number => (1 - 0.8 * opt.contrast * rgen()) / Math.E;
73+
const count = 3 + Math.floor(14 * options.complexity);
74+
const offset = (): number => (1 - 0.8 * options.contrast * rgen()) / Math.E;
7575

7676
const points = mapPoints(genBlob(count, offset), ({curr}) => {
7777
// Scale.
78-
curr.x *= opt.size;
79-
curr.y *= opt.size;
80-
curr.handleIn.length *= opt.size;
81-
curr.handleOut.length *= opt.size;
78+
curr.x *= options.size;
79+
curr.y *= options.size;
80+
curr.handleIn.length *= options.size;
81+
curr.handleOut.length *= options.size;
8282

8383
// Flip around x-axis.
84-
curr.y = opt.size - curr.y;
84+
curr.y = options.size - curr.y;
8585
curr.handleIn.angle *= -1;
8686
curr.handleOut.angle *= -1;
8787

@@ -90,13 +90,13 @@ blobs.editable = (opt: BlobOptions): XmlElement => {
9090

9191
return renderEditable(points, {
9292
closed: true,
93-
width: opt.size,
94-
height: opt.size,
95-
fill: opt.color,
96-
transform: `rotate(${rgen() * (360 / count)},${opt.size / 2},${opt.size / 2})`,
97-
stroke: opt.stroke && opt.stroke.color,
98-
strokeWidth: opt.stroke && opt.stroke.width,
99-
guides: opt.guides,
93+
width: options.size,
94+
height: options.size,
95+
fill: options.color,
96+
transform: `rotate(${rgen() * (360 / count)},${options.size / 2},${options.size / 2})`,
97+
stroke: options.stroke && options.stroke.color,
98+
strokeWidth: options.stroke && options.stroke.width,
99+
guides: options.guides,
100100
});
101101
};
102102

public/gen.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export interface Blob {
1212
points: Point[];
1313
}
1414

15-
export const gen = (opt: GenOptions): Blob => {
16-
const rgen = rand(String(opt.seed));
15+
export const gen = (options: GenOptions): Blob => {
16+
const rgen = rand(String(options.seed));
1717

1818
// Scale of random movement increases as randomness approaches infinity.
1919
// randomness = 0 -> rangeStart = 1
@@ -23,11 +23,11 @@ export const gen = (opt: GenOptions): Blob => {
2323
// randomness = 20 -> rangeStart = 0.3333
2424
// randomness = 50 -> rangeStart = 0.1667
2525
// randomness = 100 -> rangeStart = 0.0909
26-
const rangeStart = 1 / (1 + Math.abs(opt.randomness) / 10);
26+
const rangeStart = 1 / (1 + Math.abs(options.randomness) / 10);
2727

2828
return {
2929
points: genBlob(
30-
3 + Math.abs(opt.extraPoints),
30+
3 + Math.abs(options.extraPoints),
3131
() => rangeStart + rgen() * (1 - rangeStart),
3232
),
3333
};

0 commit comments

Comments
 (0)