@knowvah/dot-engine 2.6.1 → 2.6.2
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/common/pointset.d.ts +35 -0
- package/dist/common/pointset.d.ts.map +1 -0
- package/dist/index.js +73 -44
- package/dist/index.js.map +3 -3
- package/dist/layout/pack/poly-place.d.ts.map +1 -1
- package/dist/render.js +73 -44
- package/dist/render.js.map +3 -3
- package/package.json +2 -2
- package/src/common/pointset.ts +73 -0
- package/src/layout/pack/poly-place.ts +42 -47
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poly-place.d.ts","sourceRoot":"","sources":["../../../src/layout/pack/poly-place.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAGlD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"poly-place.d.ts","sourceRoot":"","sources":["../../../src/layout/pack/poly-place.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAGlD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAgC3C;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAgB9D;AA2RD;;;;;GAKG;AACH,wBAAgB,UAAU,CACxB,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,GACpD,KAAK,EAAE,GAAG,IAAI,CAkEhB"}
|
package/dist/render.js
CHANGED
|
@@ -34092,6 +34092,57 @@ function polyRects(ng, bbs, pinfo) {
|
|
|
34092
34092
|
return places;
|
|
34093
34093
|
}
|
|
34094
34094
|
|
|
34095
|
+
// src/common/pointset.ts
|
|
34096
|
+
function cmpPair(a, b) {
|
|
34097
|
+
if (a.x > b.x) return 1;
|
|
34098
|
+
if (a.x < b.x) return -1;
|
|
34099
|
+
if (a.y > b.y) return 1;
|
|
34100
|
+
if (a.y < b.y) return -1;
|
|
34101
|
+
return 0;
|
|
34102
|
+
}
|
|
34103
|
+
var PointSet = class {
|
|
34104
|
+
byX = /* @__PURE__ */ new Map();
|
|
34105
|
+
n = 0;
|
|
34106
|
+
/**
|
|
34107
|
+
* Insert (x, y). A duplicate keeps the point inserted first, as `dtinsert`
|
|
34108
|
+
* returns the existing object and the new one is freed.
|
|
34109
|
+
* @see lib/common/pointset.c:addPS
|
|
34110
|
+
*/
|
|
34111
|
+
addPS(x, y) {
|
|
34112
|
+
let col = this.byX.get(x);
|
|
34113
|
+
if (col === void 0) {
|
|
34114
|
+
col = /* @__PURE__ */ new Map();
|
|
34115
|
+
this.byX.set(x, col);
|
|
34116
|
+
}
|
|
34117
|
+
if (col.has(y)) return;
|
|
34118
|
+
col.set(y, { x, y });
|
|
34119
|
+
this.n++;
|
|
34120
|
+
}
|
|
34121
|
+
/** @see lib/common/pointset.c:inPS */
|
|
34122
|
+
inPS(pt) {
|
|
34123
|
+
return this.byX.get(pt.x)?.has(pt.y) ?? false;
|
|
34124
|
+
}
|
|
34125
|
+
/** @see lib/common/pointset.c:isInPS */
|
|
34126
|
+
isInPS(x, y) {
|
|
34127
|
+
return this.byX.get(x)?.has(y) ?? false;
|
|
34128
|
+
}
|
|
34129
|
+
/** @see lib/common/pointset.c:sizeOf */
|
|
34130
|
+
sizeOf() {
|
|
34131
|
+
return this.n;
|
|
34132
|
+
}
|
|
34133
|
+
/**
|
|
34134
|
+
* The points in dictionary order (`dtflatten` walks the ordered set).
|
|
34135
|
+
* @see lib/common/pointset.c:pointsOf
|
|
34136
|
+
*/
|
|
34137
|
+
pointsOf() {
|
|
34138
|
+
const pts = [];
|
|
34139
|
+
for (const col of this.byX.values()) {
|
|
34140
|
+
for (const p of col.values()) pts.push({ x: p.x, y: p.y });
|
|
34141
|
+
}
|
|
34142
|
+
return pts.sort(cmpPair);
|
|
34143
|
+
}
|
|
34144
|
+
};
|
|
34145
|
+
|
|
34095
34146
|
// src/layout/pack/poly-place.ts
|
|
34096
34147
|
var C_AVG = 100;
|
|
34097
34148
|
function grid(x, s) {
|
|
@@ -34103,21 +34154,6 @@ function cval2(v, s) {
|
|
|
34103
34154
|
function cell(p, s) {
|
|
34104
34155
|
return { x: cval2(p.x, s), y: cval2(p.y, s) };
|
|
34105
34156
|
}
|
|
34106
|
-
var PointSet = class {
|
|
34107
|
-
m = /* @__PURE__ */ new Map();
|
|
34108
|
-
add(x, y) {
|
|
34109
|
-
this.m.set(`${x},${y}`, { x, y });
|
|
34110
|
-
}
|
|
34111
|
-
has(p) {
|
|
34112
|
-
return this.m.has(`${p.x},${p.y}`);
|
|
34113
|
-
}
|
|
34114
|
-
points() {
|
|
34115
|
-
return [...this.m.values()];
|
|
34116
|
-
}
|
|
34117
|
-
get size() {
|
|
34118
|
-
return this.m.size;
|
|
34119
|
-
}
|
|
34120
|
-
};
|
|
34121
34157
|
function computeStep2(bbs, margin) {
|
|
34122
34158
|
const a = C_AVG * bbs.length - 1;
|
|
34123
34159
|
let b = 0;
|
|
@@ -34135,7 +34171,7 @@ function computeStep2(bbs, margin) {
|
|
|
34135
34171
|
function lineXDominant(st, ps) {
|
|
34136
34172
|
let d = st.ay - (st.ax >> 1);
|
|
34137
34173
|
for (; ; ) {
|
|
34138
|
-
ps.
|
|
34174
|
+
ps.addPS(st.x, st.y);
|
|
34139
34175
|
if (st.x === st.x2) return;
|
|
34140
34176
|
if (d >= 0) {
|
|
34141
34177
|
st.y += st.sy;
|
|
@@ -34148,7 +34184,7 @@ function lineXDominant(st, ps) {
|
|
|
34148
34184
|
function lineYDominant(st, ps) {
|
|
34149
34185
|
let d = st.ax - (st.ay >> 1);
|
|
34150
34186
|
for (; ; ) {
|
|
34151
|
-
ps.
|
|
34187
|
+
ps.addPS(st.x, st.y);
|
|
34152
34188
|
if (st.y === st.y2) return;
|
|
34153
34189
|
if (d >= 0) {
|
|
34154
34190
|
st.x += st.sx;
|
|
@@ -34180,7 +34216,7 @@ function fillLine(p, q, ps) {
|
|
|
34180
34216
|
}
|
|
34181
34217
|
function fillRect(LL, UR, ps) {
|
|
34182
34218
|
for (let x = LL.x; x <= UR.x; x++) {
|
|
34183
|
-
for (let y = LL.y; y <= UR.y; y++) ps.
|
|
34219
|
+
for (let y = LL.y; y <= UR.y; y++) ps.addPS(x, y);
|
|
34184
34220
|
}
|
|
34185
34221
|
}
|
|
34186
34222
|
function roundedCell(p, ssize) {
|
|
@@ -34232,7 +34268,7 @@ function genBox3(bb0, ssize, margin, center) {
|
|
|
34232
34268
|
const UR = roundedCell({ x: center.x + bbW + margin, y: center.y + bbH + margin }, ssize);
|
|
34233
34269
|
fillRect(LL, UR, ps);
|
|
34234
34270
|
return {
|
|
34235
|
-
cells: ps.
|
|
34271
|
+
cells: ps.pointsOf(),
|
|
34236
34272
|
perim: grid(bb0.ur.x - bb0.ll.x + 2 * margin, ssize) + grid(bb0.ur.y - bb0.ll.y + 2 * margin, ssize),
|
|
34237
34273
|
index: 0
|
|
34238
34274
|
};
|
|
@@ -34264,42 +34300,38 @@ function genPoly(root, g, bb, ssize, pinfo, center) {
|
|
|
34264
34300
|
};
|
|
34265
34301
|
for (const n of g.nodes.values()) coverNode(n, ctx);
|
|
34266
34302
|
return {
|
|
34267
|
-
cells: ps.
|
|
34303
|
+
cells: ps.pointsOf(),
|
|
34268
34304
|
perim: grid(bb.ur.x - bb.ll.x + 2 * pinfo.margin, ssize) + grid(bb.ur.y - bb.ll.y + 2 * pinfo.margin, ssize),
|
|
34269
34305
|
index: 0
|
|
34270
34306
|
};
|
|
34271
34307
|
}
|
|
34272
34308
|
function fits2(x, y, info, ctx) {
|
|
34273
34309
|
for (const c of info.cells) {
|
|
34274
|
-
if (ctx.ps.
|
|
34310
|
+
if (ctx.ps.isInPS(c.x + x, c.y + y)) return false;
|
|
34275
34311
|
}
|
|
34276
34312
|
const bb = ctx.bbs[info.index];
|
|
34277
34313
|
const LL = { x: cround(bb.ll.x), y: cround(bb.ll.y) };
|
|
34278
34314
|
ctx.places[info.index] = { x: Math.imul(ctx.step, x) - LL.x, y: Math.imul(ctx.step, y) - LL.y };
|
|
34279
|
-
for (const c of info.cells) ctx.ps.
|
|
34315
|
+
for (const c of info.cells) ctx.ps.addPS(c.x + x, c.y + y);
|
|
34280
34316
|
return true;
|
|
34281
34317
|
}
|
|
34282
|
-
function
|
|
34283
|
-
|
|
34284
|
-
|
|
34285
|
-
|
|
34286
|
-
|
|
34287
|
-
|
|
34288
|
-
|
|
34289
|
-
|
|
34290
|
-
|
|
34291
|
-
|
|
34292
|
-
|
|
34293
|
-
|
|
34294
|
-
|
|
34295
|
-
for (; x < bnd; x++) yield [x, y];
|
|
34296
|
-
for (; y < bnd; y++) yield [x, y];
|
|
34297
|
-
for (; x > -bnd; x--) yield [x, y];
|
|
34298
|
-
for (; y > 0; y--) yield [x, y];
|
|
34318
|
+
function leg(c, dx, dy, end, info, ctx) {
|
|
34319
|
+
for (; (dx !== 0 ? c.x : c.y) !== end; c.x += dx, c.y += dy) {
|
|
34320
|
+
if (fits2(c.x, c.y, info, ctx)) return true;
|
|
34321
|
+
}
|
|
34322
|
+
return false;
|
|
34323
|
+
}
|
|
34324
|
+
function ringWide(bnd, info, ctx) {
|
|
34325
|
+
const c = { x: 0, y: -bnd };
|
|
34326
|
+
return leg(c, 1, 0, bnd, info, ctx) || leg(c, 0, 1, bnd, info, ctx) || leg(c, -1, 0, -bnd, info, ctx) || leg(c, 0, -1, -bnd, info, ctx) || leg(c, 1, 0, 0, info, ctx);
|
|
34327
|
+
}
|
|
34328
|
+
function ringTall(bnd, info, ctx) {
|
|
34329
|
+
const c = { x: -bnd, y: 0 };
|
|
34330
|
+
return leg(c, 0, -1, -bnd, info, ctx) || leg(c, 1, 0, bnd, info, ctx) || leg(c, 0, 1, bnd, info, ctx) || leg(c, -1, 0, -bnd, info, ctx) || leg(c, 0, -1, 0, info, ctx);
|
|
34299
34331
|
}
|
|
34300
34332
|
function placeFixed(info, ctx, center) {
|
|
34301
34333
|
ctx.places[info.index] = { x: -center.x, y: -center.y };
|
|
34302
|
-
for (const c of info.cells) ctx.ps.
|
|
34334
|
+
for (const c of info.cells) ctx.ps.addPS(c.x, c.y);
|
|
34303
34335
|
}
|
|
34304
34336
|
function placeGraph2(i, info, ctx) {
|
|
34305
34337
|
const bb = ctx.bbs[info.index];
|
|
@@ -34311,10 +34343,7 @@ function placeGraph2(i, info, ctx) {
|
|
|
34311
34343
|
if (fits2(0, 0, info, ctx)) return;
|
|
34312
34344
|
const wide = Math.ceil(bb.ur.x - bb.ll.x) >= Math.ceil(bb.ur.y - bb.ll.y);
|
|
34313
34345
|
for (let bnd = 1; ; bnd++) {
|
|
34314
|
-
|
|
34315
|
-
for (const [x, y] of ring) {
|
|
34316
|
-
if (fits2(x, y, info, ctx)) return;
|
|
34317
|
-
}
|
|
34346
|
+
if (wide ? ringWide(bnd, info, ctx) : ringTall(bnd, info, ctx)) return;
|
|
34318
34347
|
}
|
|
34319
34348
|
}
|
|
34320
34349
|
function polyGraphs(gs, root, pinfo, bbs) {
|