Skip to content

Commit b04bb3f

Browse files
committed
🦄 refactor: convert to options constructors
1 parent 3374ae7 commit b04bb3f

File tree

128 files changed

+1940
-1073
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+1940
-1073
lines changed

packages/app/src/application.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ export class Application implements IApplication {
192192

193193
async newDocument(name: string): Promise<IDocument> {
194194
const document = new Document(this, name);
195-
const lightGray = new Material(document, "LightGray", 0xdedede);
196-
const deepGray = new Material(document, "DeepGray", 0x898989);
195+
const lightGray = new Material({ document, name: "LightGray", color: 0xdedede });
196+
const deepGray = new Material({ document, name: "DeepGray", color: 0x898989 });
197197
document.modelManager.materials.push(lightGray, deepGray);
198198
await this.createActiveView(document);
199199
return document;

packages/app/src/bodys/arc.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ import {
1313
type XYZ,
1414
} from "@chili3d/core";
1515

16+
export interface ArcOptions {
17+
document: IDocument;
18+
normal: XYZ;
19+
center: XYZ;
20+
start: XYZ;
21+
angle: number;
22+
}
23+
1624
@serializable(["document", "normal", "center", "start", "angle"])
1725
export class ArcNode extends ParameterShapeNode {
1826
override display(): I18nKeys {
@@ -48,12 +56,12 @@ export class ArcNode extends ParameterShapeNode {
4856
this.setPropertyEmitShapeChanged("angle", value);
4957
}
5058

51-
constructor(document: IDocument, normal: XYZ, center: XYZ, start: XYZ, angle: number) {
52-
super(document);
53-
this.setPrivateValue("normal", normal);
54-
this.setPrivateValue("center", center);
55-
this.setPrivateValue("start", start);
56-
this.setPrivateValue("angle", angle);
59+
constructor(options: ArcOptions) {
60+
super({ document: options.document });
61+
this.setPrivateValue("normal", options.normal);
62+
this.setPrivateValue("center", options.center);
63+
this.setPrivateValue("start", options.start);
64+
this.setPrivateValue("angle", options.angle);
5765
}
5866

5967
generateShape(): Result<IShape, string> {

packages/app/src/bodys/boolean.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import {
1111
serialze,
1212
} from "@chili3d/core";
1313

14+
export interface BooleanOptions {
15+
document: IDocument;
16+
booleanShape: IShape;
17+
}
18+
1419
@serializable(["document", "booleanShape"])
1520
export class BooleanNode extends ParameterShapeNode {
1621
override display(): I18nKeys {
@@ -22,9 +27,9 @@ export class BooleanNode extends ParameterShapeNode {
2227
return this.getPrivateValue("booleanShape");
2328
}
2429

25-
constructor(document: IDocument, shape: IShape) {
26-
super(document);
27-
this.setPrivateValue("booleanShape", shape);
30+
constructor(options: BooleanOptions) {
31+
super(options);
32+
this.setPrivateValue("booleanShape", options.booleanShape);
2833
}
2934

3035
override generateShape(): Result<IShape> {

packages/app/src/bodys/box.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ import {
1414
type XYZ,
1515
} from "@chili3d/core";
1616

17+
export interface BoxNodeOptions {
18+
document: IDocument;
19+
plane: Plane;
20+
dx: number;
21+
dy: number;
22+
dz: number;
23+
}
24+
1725
@serializable(["document", "plane", "dx", "dy", "dz"])
1826
export class BoxNode extends ParameterShapeNode {
1927
override display(): I18nKeys {
@@ -60,12 +68,12 @@ export class BoxNode extends ParameterShapeNode {
6068
this.setPropertyEmitShapeChanged("dz", dz);
6169
}
6270

63-
constructor(document: IDocument, plane: Plane, dx: number, dy: number, dz: number) {
64-
super(document);
65-
this.setPrivateValue("plane", plane);
66-
this.setPrivateValue("dx", dx);
67-
this.setPrivateValue("dy", dy);
68-
this.setPrivateValue("dz", dz);
71+
constructor(options: BoxNodeOptions) {
72+
super(options);
73+
this.setPrivateValue("plane", options.plane);
74+
this.setPrivateValue("dx", options.dx);
75+
this.setPrivateValue("dy", options.dy);
76+
this.setPrivateValue("dz", options.dz);
6977
}
7078

7179
generateShape(): Result<IShape> {

packages/app/src/bodys/circle.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ import {
1313
type XYZ,
1414
} from "@chili3d/core";
1515

16+
export interface CircleOptions {
17+
document: IDocument;
18+
normal: XYZ;
19+
center: XYZ;
20+
radius: number;
21+
}
22+
1623
@serializable(["document", "normal", "center", "radius"])
1724
export class CircleNode extends FacebaseNode {
1825
override display(): I18nKeys {
@@ -42,11 +49,11 @@ export class CircleNode extends FacebaseNode {
4249
return this.getPrivateValue("normal");
4350
}
4451

45-
constructor(document: IDocument, normal: XYZ, center: XYZ, radius: number) {
46-
super(document);
47-
this.setPrivateValue("normal", normal);
48-
this.setPrivateValue("center", center);
49-
this.setPrivateValue("radius", radius);
52+
constructor(options: CircleOptions) {
53+
super({ document: options.document });
54+
this.setPrivateValue("normal", options.normal);
55+
this.setPrivateValue("center", options.center);
56+
this.setPrivateValue("radius", options.radius);
5057
}
5158

5259
generateShape(): Result<IShape, string> {

packages/app/src/bodys/cone.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ import {
1313
type XYZ,
1414
} from "@chili3d/core";
1515

16+
export interface ConeNodeOptions {
17+
document: IDocument;
18+
normal: XYZ;
19+
center: XYZ;
20+
radius: number;
21+
dz: number;
22+
}
23+
1624
@serializable(["document", "normal", "center", "radius", "dz"])
1725
export class ConeNode extends ParameterShapeNode {
1826
override display(): I18nKeys {
@@ -51,12 +59,12 @@ export class ConeNode extends ParameterShapeNode {
5159
return this.getPrivateValue("normal");
5260
}
5361

54-
constructor(document: IDocument, normal: XYZ, center: XYZ, radius: number, dz: number) {
55-
super(document);
56-
this.setPrivateValue("normal", normal);
57-
this.setPrivateValue("center", center);
58-
this.setPrivateValue("radius", radius);
59-
this.setPrivateValue("dz", dz);
62+
constructor(options: ConeNodeOptions) {
63+
super(options);
64+
this.setPrivateValue("normal", options.normal);
65+
this.setPrivateValue("center", options.center);
66+
this.setPrivateValue("radius", options.radius);
67+
this.setPrivateValue("dz", options.dz);
6068
}
6169

6270
generateShape(): Result<IShape> {

packages/app/src/bodys/cylinder.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ import {
1313
type XYZ,
1414
} from "@chili3d/core";
1515

16+
export interface CylinderNodeOptions {
17+
document: IDocument;
18+
normal: XYZ;
19+
center: XYZ;
20+
radius: number;
21+
dz: number;
22+
}
23+
1624
@serializable(["document", "normal", "center", "radius", "dz"])
1725
export class CylinderNode extends ParameterShapeNode {
1826
override display(): I18nKeys {
@@ -51,12 +59,12 @@ export class CylinderNode extends ParameterShapeNode {
5159
return this.getPrivateValue("normal");
5260
}
5361

54-
constructor(document: IDocument, normal: XYZ, center: XYZ, radius: number, dz: number) {
55-
super(document);
56-
this.setPrivateValue("normal", normal);
57-
this.setPrivateValue("center", center);
58-
this.setPrivateValue("radius", radius);
59-
this.setPrivateValue("dz", dz);
62+
constructor(options: CylinderNodeOptions) {
63+
super(options);
64+
this.setPrivateValue("normal", options.normal);
65+
this.setPrivateValue("center", options.center);
66+
this.setPrivateValue("radius", options.radius);
67+
this.setPrivateValue("dz", options.dz);
6068
}
6169

6270
generateShape(): Result<IShape> {

packages/app/src/bodys/ellipse.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ import {
1313
type XYZ,
1414
} from "@chili3d/core";
1515

16+
export interface EllipseOptions {
17+
document: IDocument;
18+
normal: XYZ;
19+
center: XYZ;
20+
xvec: XYZ;
21+
majorRadius: number;
22+
minorRadius: number;
23+
}
24+
1625
@serializable(["document", "normal", "center", "xvec", "majorRadius", "minorRadius"])
1726
export class EllipseNode extends FacebaseNode {
1827
override display(): I18nKeys {
@@ -55,20 +64,13 @@ export class EllipseNode extends FacebaseNode {
5564
return this.getPrivateValue("xvec");
5665
}
5766

58-
constructor(
59-
document: IDocument,
60-
normal: XYZ,
61-
center: XYZ,
62-
xvec: XYZ,
63-
majorRadius: number,
64-
minorRadius: number,
65-
) {
66-
super(document);
67-
this.setPrivateValue("normal", normal);
68-
this.setPrivateValue("center", center);
69-
this.setPrivateValue("xvec", xvec);
70-
this.setPrivateValue("majorRadius", majorRadius);
71-
this.setPrivateValue("minorRadius", minorRadius);
67+
constructor(options: EllipseOptions) {
68+
super({ document: options.document });
69+
this.setPrivateValue("normal", options.normal);
70+
this.setPrivateValue("center", options.center);
71+
this.setPrivateValue("xvec", options.xvec);
72+
this.setPrivateValue("majorRadius", options.majorRadius);
73+
this.setPrivateValue("minorRadius", options.minorRadius);
7274
}
7375

7476
generateShape(): Result<IShape, string> {

packages/app/src/bodys/face.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import {
1414
serialze,
1515
} from "@chili3d/core";
1616

17+
export interface FaceOptions {
18+
document: IDocument;
19+
shapes: IEdge[] | IWire[];
20+
}
21+
1722
@serializable(["document", "shapes"])
1823
export class FaceNode extends ParameterShapeNode {
1924
override display(): I18nKeys {
@@ -28,9 +33,9 @@ export class FaceNode extends ParameterShapeNode {
2833
this.setPropertyEmitShapeChanged("shapes", values);
2934
}
3035

31-
constructor(document: IDocument, shapes: IEdge[] | IWire[]) {
32-
super(document);
33-
this.setPrivateValue("shapes", shapes);
36+
constructor(options: FaceOptions) {
37+
super(options);
38+
this.setPrivateValue("shapes", options.shapes);
3439
}
3540

3641
private isAllClosed(): boolean {

packages/app/src/bodys/fuse.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import {
1111
serialze,
1212
} from "@chili3d/core";
1313

14+
export interface FuseOptions {
15+
document: IDocument;
16+
bottom: IShape;
17+
top: IShape;
18+
}
19+
1420
@serializable(["document", "bottom", "top"])
1521
export class FuseNode extends ParameterShapeNode {
1622
override display(): I18nKeys {
@@ -33,10 +39,10 @@ export class FuseNode extends ParameterShapeNode {
3339
this.setPropertyEmitShapeChanged("top", value);
3440
}
3541

36-
constructor(document: IDocument, bottom: IShape, top: IShape) {
37-
super(document);
38-
this.setPrivateValue("bottom", bottom);
39-
this.setPrivateValue("top", top);
42+
constructor(options: FuseOptions) {
43+
super(options);
44+
this.setPrivateValue("bottom", options.bottom);
45+
this.setPrivateValue("top", options.top);
4046
}
4147

4248
override generateShape(): Result<IShape> {

0 commit comments

Comments
 (0)