simulationjsv2 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -73,9 +73,9 @@ export declare class BezierCurve2d {
73
73
  export declare class CubicBezierCurve2d extends BezierCurve2d {
74
74
  private detail;
75
75
  private colors;
76
- constructor(points: [Vector2, Vector2, Vector2, Vector2], detail?: number, colors?: Color[]);
76
+ constructor(points: [Vector2, Vector2, Vector2, Vector2], detail?: number, colors?: (Color | null)[]);
77
77
  getDetail(): number | undefined;
78
- getColors(): Color[];
78
+ getColors(): (Color | null)[];
79
79
  }
80
80
  export declare class SplinePoint2d {
81
81
  private start;
@@ -90,7 +90,7 @@ export declare class SplinePoint2d {
90
90
  getControls(): readonly [Vector2 | null, Vector2];
91
91
  getRawControls(): [Vector2, Vector2];
92
92
  getDetail(): number | undefined;
93
- getColors(prevColor?: Color): Color[];
93
+ getColors(prevColor?: Color | null): (Color | null)[];
94
94
  getVectorArray(prevEnd: Vector2 | null, prevControl: Vector2 | null): readonly [Vector2, Vector2, Vector2, Vector2];
95
95
  }
96
96
  export declare class Spline2d extends SimulationElement {
package/dist/graphics.js CHANGED
@@ -524,14 +524,18 @@ export class SplinePoint2d {
524
524
  return this.detail;
525
525
  }
526
526
  getColors(prevColor) {
527
- const colors = [];
528
- if (prevColor)
529
- colors.push(prevColor);
527
+ const colors = [null, null];
530
528
  if (this.start && this.start.getColor()) {
531
- colors.push(this.start.getColor());
529
+ colors[0] = this.start.getColor();
532
530
  }
533
531
  if (this.end.getColor()) {
534
- colors.push(this.end.getColor());
532
+ colors[1] = this.end.getColor();
533
+ }
534
+ if (prevColor) {
535
+ colors.unshift(prevColor);
536
+ }
537
+ if (colors.at(-1) === null) {
538
+ colors.pop();
535
539
  }
536
540
  return colors;
537
541
  }
@@ -566,13 +570,13 @@ export class Spline2d extends SimulationElement {
566
570
  this.distance = 0;
567
571
  for (let i = 0; i < points.length; i++) {
568
572
  let prevControl = null;
569
- let prevColor = this.getColor();
573
+ let prevColor = null;
570
574
  if (i > 0) {
571
575
  prevControl = cloneBuf(points[i - 1].getRawControls()[1]);
572
576
  vec2.negate(prevControl, prevControl);
573
577
  const prevColors = points[i - 1].getColors();
574
578
  if (prevColors.at(-1)) {
575
- prevColor = prevColors.at(-1);
579
+ prevColor = prevColors.at(-1) || null;
576
580
  }
577
581
  }
578
582
  const bezierPoints = points[i].getVectorArray(i > 0 ? vector2FromVector3(points[i - 1].getEnd().getPos()) : null, prevControl);
@@ -620,7 +624,8 @@ export class Spline2d extends SimulationElement {
620
624
  const normal = vector2(-slope[1], slope[0]);
621
625
  vec2.normalize(normal, normal);
622
626
  vec2.scale(normal, this.width / 2, normal);
623
- const vertexColor = interpolateColors(this.curves[i].getColors(), currentInterpolation);
627
+ const colors = this.curves[i].getColors().map((c) => (c ? c : this.getColor()));
628
+ const vertexColor = interpolateColors(colors, currentInterpolation);
624
629
  const vertTop = vertex(point[0] + normal[0], point[1] + normal[1], 0, vertexColor);
625
630
  verticesTop.push(vertTop);
626
631
  const vertBottom = vertex(point[0] - normal[0], point[1] - normal[1], 0, vertexColor);
package/dist/utils.js CHANGED
@@ -301,6 +301,10 @@ export function continuousSplinePoint2d(end, control, detail) {
301
301
  return new SplinePoint2d(null, end, null, control, rawControls, detail);
302
302
  }
303
303
  export function interpolateColors(colors, t) {
304
+ if (colors.length === 0)
305
+ return color();
306
+ if (colors.length === 1)
307
+ return colors[0];
304
308
  const colorInterval = 1 / colors.length;
305
309
  let index = Math.floor(t / colorInterval);
306
310
  if (index === colors.length)
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Jackson Otto",
7
7
  "description": "A simple graphics library using WebGPU",
8
- "version": "0.1.9",
8
+ "version": "0.1.10",
9
9
  "exports": {
10
10
  ".": {
11
11
  "import": "./dist/index.js",