Skip to content

Commit

Permalink
remove isClosed
Browse files Browse the repository at this point in the history
  • Loading branch information
OrionReed committed Dec 1, 2024
1 parent 62454dc commit 0f3ee9f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/distanceField/distance-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ export class DistanceField extends HTMLElement {
};
}

addShape(points: Vector2[], isClosed = true) {
addShape(points: Vector2[]) {
// Transform each point from screen coordinates to field coordinates
const transformedPoints = points.map((point) => this.transformToFieldCoordinates(point));
this.fields.addShape(transformedPoints, isClosed);
this.fields.addShape(transformedPoints);
this.renderDistanceField();
}

Expand Down Expand Up @@ -176,16 +176,16 @@ export class DistanceField extends HTMLElement {
];

if (index < this.fields.shapes.length) {
this.updateShape(index, points, true);
this.updateShape(index, points);
} else {
this.addShape(points, true);
this.addShape(points);
}
};

updateShape(index: number, points: Vector2[], isClosed = true) {
updateShape(index: number, points: Vector2[]) {
// Transform each point from screen coordinates to field coordinates
const transformedPoints = points.map((point) => this.transformToFieldCoordinates(point));
this.fields.updateShape(index, transformedPoints, isClosed);
this.fields.updateShape(index, transformedPoints);
this.renderDistanceField();
}
}
14 changes: 6 additions & 8 deletions src/distanceField/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export class Fields {
shapes: Array<{
points: Vector2[];
color: number;
isClosed: boolean;
}> = [];

constructor(resolution: number) {
Expand Down Expand Up @@ -40,9 +39,9 @@ export class Fields {
return this.colorField[x][y];
}

addShape(points: Vector2[], isClosed: boolean = true) {
addShape(points: Vector2[]) {
const color = Math.floor(Math.random() * 255);
this.shapes.push({ points, color, isClosed });
this.shapes.push({ points, color });
this.updateFields();
console.log(this.shapes);
}
Expand Down Expand Up @@ -129,10 +128,9 @@ export class Fields {
};

for (const shape of this.shapes) {
const { points, color, isClosed } = shape;
const length = isClosed ? points.length : points.length - 1;
const { points, color } = shape;

for (let i = 0; i < length; i++) {
for (let i = 0; i < points.length; i++) {
const start = points[i];
const end = points[(i + 1) % points.length];
drawLine(start, end, color);
Expand Down Expand Up @@ -240,10 +238,10 @@ export class Fields {
canvas.putImageData(imageData, 0, 0);
}

updateShape(index: number, points: Vector2[], isClosed: boolean = true) {
updateShape(index: number, points: Vector2[]) {
if (index >= 0 && index < this.shapes.length) {
const existingColor = this.shapes[index].color;
this.shapes[index] = { points, color: existingColor, isClosed };
this.shapes[index] = { points, color: existingColor };
this.updateFields();
}
}
Expand Down

0 comments on commit 0f3ee9f

Please sign in to comment.