@slithy/prim-lib 0.3.0 → 0.3.1

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.
package/dist/index.d.ts CHANGED
@@ -38,6 +38,7 @@ interface Cfg {
38
38
  alpha: number;
39
39
  mutateAlpha: boolean;
40
40
  shapeTypes: Array<new (w: number, h: number) => ShapeInterface>;
41
+ shapeWeights?: number[];
41
42
  shapes: number;
42
43
  mutations: number;
43
44
  steps: number;
package/dist/index.js CHANGED
@@ -349,6 +349,16 @@ var Shape = class {
349
349
  }
350
350
  static create(cfg) {
351
351
  const ctors = cfg.shapeTypes;
352
+ const weights = cfg.shapeWeights;
353
+ if (weights && weights.length === ctors.length) {
354
+ const total = weights.reduce((sum, w) => sum + w, 0);
355
+ let r = Math.random() * total;
356
+ for (let i = 0; i < weights.length; i++) {
357
+ r -= weights[i];
358
+ if (r <= 0) return new ctors[i](cfg.width, cfg.height);
359
+ }
360
+ return new ctors[ctors.length - 1](cfg.width, cfg.height);
361
+ }
352
362
  const index = Math.floor(Math.random() * ctors.length);
353
363
  const ctor = ctors[index];
354
364
  return new ctor(cfg.width, cfg.height);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slithy/prim-lib",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Core engine for primitive-based image reconstruction.",
5
5
  "type": "module",
6
6
  "exports": {