@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
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set of points, compared exactly on their double coordinates.
|
|
3
|
+
*
|
|
4
|
+
* C keeps the points in an ordered cdt dictionary (`Dtoset`) under `cmppair`:
|
|
5
|
+
* x first, then y, plain double `<`/`>`, so -0 and 0 are one key. Here the
|
|
6
|
+
* dictionary is a two-level `Map` keyed on the coordinates themselves. Map
|
|
7
|
+
* keys use SameValueZero, which also makes -0 and 0 one key. A lookup
|
|
8
|
+
* allocates nothing; packing calls it once per cell per candidate position.
|
|
9
|
+
*
|
|
10
|
+
* @see lib/common/pointset.c
|
|
11
|
+
*/
|
|
12
|
+
import type { Point } from '../model/geom.js';
|
|
13
|
+
/** @see lib/common/pointset.h:PointSet */
|
|
14
|
+
export declare class PointSet {
|
|
15
|
+
private readonly byX;
|
|
16
|
+
private n;
|
|
17
|
+
/**
|
|
18
|
+
* Insert (x, y). A duplicate keeps the point inserted first, as `dtinsert`
|
|
19
|
+
* returns the existing object and the new one is freed.
|
|
20
|
+
* @see lib/common/pointset.c:addPS
|
|
21
|
+
*/
|
|
22
|
+
addPS(x: number, y: number): void;
|
|
23
|
+
/** @see lib/common/pointset.c:inPS */
|
|
24
|
+
inPS(pt: Point): boolean;
|
|
25
|
+
/** @see lib/common/pointset.c:isInPS */
|
|
26
|
+
isInPS(x: number, y: number): boolean;
|
|
27
|
+
/** @see lib/common/pointset.c:sizeOf */
|
|
28
|
+
sizeOf(): number;
|
|
29
|
+
/**
|
|
30
|
+
* The points in dictionary order (`dtflatten` walks the ordered set).
|
|
31
|
+
* @see lib/common/pointset.c:pointsOf
|
|
32
|
+
*/
|
|
33
|
+
pointsOf(): Point[];
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=pointset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pointset.d.ts","sourceRoot":"","sources":["../../src/common/pointset.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAW9C,0CAA0C;AAC1C,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAyC;IAC7D,OAAO,CAAC,CAAC,CAAK;IAEd;;;;OAIG;IACH,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI;IAWjC,sCAAsC;IACtC,IAAI,CAAC,EAAE,EAAE,KAAK,GAAG,OAAO;IAIxB,wCAAwC;IACxC,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO;IAIrC,wCAAwC;IACxC,MAAM,IAAI,MAAM;IAIhB;;;OAGG;IACH,QAAQ,IAAI,KAAK,EAAE;CAOpB"}
|
package/dist/index.js
CHANGED
|
@@ -38088,6 +38088,57 @@ function polyRects(ng, bbs, pinfo) {
|
|
|
38088
38088
|
return places;
|
|
38089
38089
|
}
|
|
38090
38090
|
|
|
38091
|
+
// src/common/pointset.ts
|
|
38092
|
+
function cmpPair(a, b) {
|
|
38093
|
+
if (a.x > b.x) return 1;
|
|
38094
|
+
if (a.x < b.x) return -1;
|
|
38095
|
+
if (a.y > b.y) return 1;
|
|
38096
|
+
if (a.y < b.y) return -1;
|
|
38097
|
+
return 0;
|
|
38098
|
+
}
|
|
38099
|
+
var PointSet = class {
|
|
38100
|
+
byX = /* @__PURE__ */ new Map();
|
|
38101
|
+
n = 0;
|
|
38102
|
+
/**
|
|
38103
|
+
* Insert (x, y). A duplicate keeps the point inserted first, as `dtinsert`
|
|
38104
|
+
* returns the existing object and the new one is freed.
|
|
38105
|
+
* @see lib/common/pointset.c:addPS
|
|
38106
|
+
*/
|
|
38107
|
+
addPS(x, y) {
|
|
38108
|
+
let col = this.byX.get(x);
|
|
38109
|
+
if (col === void 0) {
|
|
38110
|
+
col = /* @__PURE__ */ new Map();
|
|
38111
|
+
this.byX.set(x, col);
|
|
38112
|
+
}
|
|
38113
|
+
if (col.has(y)) return;
|
|
38114
|
+
col.set(y, { x, y });
|
|
38115
|
+
this.n++;
|
|
38116
|
+
}
|
|
38117
|
+
/** @see lib/common/pointset.c:inPS */
|
|
38118
|
+
inPS(pt) {
|
|
38119
|
+
return this.byX.get(pt.x)?.has(pt.y) ?? false;
|
|
38120
|
+
}
|
|
38121
|
+
/** @see lib/common/pointset.c:isInPS */
|
|
38122
|
+
isInPS(x, y) {
|
|
38123
|
+
return this.byX.get(x)?.has(y) ?? false;
|
|
38124
|
+
}
|
|
38125
|
+
/** @see lib/common/pointset.c:sizeOf */
|
|
38126
|
+
sizeOf() {
|
|
38127
|
+
return this.n;
|
|
38128
|
+
}
|
|
38129
|
+
/**
|
|
38130
|
+
* The points in dictionary order (`dtflatten` walks the ordered set).
|
|
38131
|
+
* @see lib/common/pointset.c:pointsOf
|
|
38132
|
+
*/
|
|
38133
|
+
pointsOf() {
|
|
38134
|
+
const pts = [];
|
|
38135
|
+
for (const col of this.byX.values()) {
|
|
38136
|
+
for (const p of col.values()) pts.push({ x: p.x, y: p.y });
|
|
38137
|
+
}
|
|
38138
|
+
return pts.sort(cmpPair);
|
|
38139
|
+
}
|
|
38140
|
+
};
|
|
38141
|
+
|
|
38091
38142
|
// src/layout/pack/poly-place.ts
|
|
38092
38143
|
var C_AVG = 100;
|
|
38093
38144
|
function grid(x, s) {
|
|
@@ -38099,21 +38150,6 @@ function cval2(v, s) {
|
|
|
38099
38150
|
function cell(p, s) {
|
|
38100
38151
|
return { x: cval2(p.x, s), y: cval2(p.y, s) };
|
|
38101
38152
|
}
|
|
38102
|
-
var PointSet = class {
|
|
38103
|
-
m = /* @__PURE__ */ new Map();
|
|
38104
|
-
add(x, y) {
|
|
38105
|
-
this.m.set(`${x},${y}`, { x, y });
|
|
38106
|
-
}
|
|
38107
|
-
has(p) {
|
|
38108
|
-
return this.m.has(`${p.x},${p.y}`);
|
|
38109
|
-
}
|
|
38110
|
-
points() {
|
|
38111
|
-
return [...this.m.values()];
|
|
38112
|
-
}
|
|
38113
|
-
get size() {
|
|
38114
|
-
return this.m.size;
|
|
38115
|
-
}
|
|
38116
|
-
};
|
|
38117
38153
|
function computeStep2(bbs, margin) {
|
|
38118
38154
|
const a = C_AVG * bbs.length - 1;
|
|
38119
38155
|
let b = 0;
|
|
@@ -38131,7 +38167,7 @@ function computeStep2(bbs, margin) {
|
|
|
38131
38167
|
function lineXDominant(st, ps) {
|
|
38132
38168
|
let d = st.ay - (st.ax >> 1);
|
|
38133
38169
|
for (; ; ) {
|
|
38134
|
-
ps.
|
|
38170
|
+
ps.addPS(st.x, st.y);
|
|
38135
38171
|
if (st.x === st.x2) return;
|
|
38136
38172
|
if (d >= 0) {
|
|
38137
38173
|
st.y += st.sy;
|
|
@@ -38144,7 +38180,7 @@ function lineXDominant(st, ps) {
|
|
|
38144
38180
|
function lineYDominant(st, ps) {
|
|
38145
38181
|
let d = st.ax - (st.ay >> 1);
|
|
38146
38182
|
for (; ; ) {
|
|
38147
|
-
ps.
|
|
38183
|
+
ps.addPS(st.x, st.y);
|
|
38148
38184
|
if (st.y === st.y2) return;
|
|
38149
38185
|
if (d >= 0) {
|
|
38150
38186
|
st.x += st.sx;
|
|
@@ -38176,7 +38212,7 @@ function fillLine(p, q, ps) {
|
|
|
38176
38212
|
}
|
|
38177
38213
|
function fillRect(LL, UR, ps) {
|
|
38178
38214
|
for (let x = LL.x; x <= UR.x; x++) {
|
|
38179
|
-
for (let y = LL.y; y <= UR.y; y++) ps.
|
|
38215
|
+
for (let y = LL.y; y <= UR.y; y++) ps.addPS(x, y);
|
|
38180
38216
|
}
|
|
38181
38217
|
}
|
|
38182
38218
|
function roundedCell(p, ssize) {
|
|
@@ -38228,7 +38264,7 @@ function genBox3(bb0, ssize, margin, center) {
|
|
|
38228
38264
|
const UR = roundedCell({ x: center.x + bbW + margin, y: center.y + bbH + margin }, ssize);
|
|
38229
38265
|
fillRect(LL, UR, ps);
|
|
38230
38266
|
return {
|
|
38231
|
-
cells: ps.
|
|
38267
|
+
cells: ps.pointsOf(),
|
|
38232
38268
|
perim: grid(bb0.ur.x - bb0.ll.x + 2 * margin, ssize) + grid(bb0.ur.y - bb0.ll.y + 2 * margin, ssize),
|
|
38233
38269
|
index: 0
|
|
38234
38270
|
};
|
|
@@ -38260,42 +38296,38 @@ function genPoly(root, g, bb, ssize, pinfo, center) {
|
|
|
38260
38296
|
};
|
|
38261
38297
|
for (const n of g.nodes.values()) coverNode(n, ctx);
|
|
38262
38298
|
return {
|
|
38263
|
-
cells: ps.
|
|
38299
|
+
cells: ps.pointsOf(),
|
|
38264
38300
|
perim: grid(bb.ur.x - bb.ll.x + 2 * pinfo.margin, ssize) + grid(bb.ur.y - bb.ll.y + 2 * pinfo.margin, ssize),
|
|
38265
38301
|
index: 0
|
|
38266
38302
|
};
|
|
38267
38303
|
}
|
|
38268
38304
|
function fits2(x, y, info, ctx) {
|
|
38269
38305
|
for (const c of info.cells) {
|
|
38270
|
-
if (ctx.ps.
|
|
38306
|
+
if (ctx.ps.isInPS(c.x + x, c.y + y)) return false;
|
|
38271
38307
|
}
|
|
38272
38308
|
const bb = ctx.bbs[info.index];
|
|
38273
38309
|
const LL = { x: cround(bb.ll.x), y: cround(bb.ll.y) };
|
|
38274
38310
|
ctx.places[info.index] = { x: Math.imul(ctx.step, x) - LL.x, y: Math.imul(ctx.step, y) - LL.y };
|
|
38275
|
-
for (const c of info.cells) ctx.ps.
|
|
38311
|
+
for (const c of info.cells) ctx.ps.addPS(c.x + x, c.y + y);
|
|
38276
38312
|
return true;
|
|
38277
38313
|
}
|
|
38278
|
-
function
|
|
38279
|
-
|
|
38280
|
-
|
|
38281
|
-
|
|
38282
|
-
|
|
38283
|
-
|
|
38284
|
-
|
|
38285
|
-
|
|
38286
|
-
|
|
38287
|
-
|
|
38288
|
-
|
|
38289
|
-
|
|
38290
|
-
|
|
38291
|
-
for (; x < bnd; x++) yield [x, y];
|
|
38292
|
-
for (; y < bnd; y++) yield [x, y];
|
|
38293
|
-
for (; x > -bnd; x--) yield [x, y];
|
|
38294
|
-
for (; y > 0; y--) yield [x, y];
|
|
38314
|
+
function leg(c, dx, dy, end, info, ctx) {
|
|
38315
|
+
for (; (dx !== 0 ? c.x : c.y) !== end; c.x += dx, c.y += dy) {
|
|
38316
|
+
if (fits2(c.x, c.y, info, ctx)) return true;
|
|
38317
|
+
}
|
|
38318
|
+
return false;
|
|
38319
|
+
}
|
|
38320
|
+
function ringWide(bnd, info, ctx) {
|
|
38321
|
+
const c = { x: 0, y: -bnd };
|
|
38322
|
+
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);
|
|
38323
|
+
}
|
|
38324
|
+
function ringTall(bnd, info, ctx) {
|
|
38325
|
+
const c = { x: -bnd, y: 0 };
|
|
38326
|
+
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);
|
|
38295
38327
|
}
|
|
38296
38328
|
function placeFixed(info, ctx, center) {
|
|
38297
38329
|
ctx.places[info.index] = { x: -center.x, y: -center.y };
|
|
38298
|
-
for (const c of info.cells) ctx.ps.
|
|
38330
|
+
for (const c of info.cells) ctx.ps.addPS(c.x, c.y);
|
|
38299
38331
|
}
|
|
38300
38332
|
function placeGraph2(i, info, ctx) {
|
|
38301
38333
|
const bb = ctx.bbs[info.index];
|
|
@@ -38307,10 +38339,7 @@ function placeGraph2(i, info, ctx) {
|
|
|
38307
38339
|
if (fits2(0, 0, info, ctx)) return;
|
|
38308
38340
|
const wide = Math.ceil(bb.ur.x - bb.ll.x) >= Math.ceil(bb.ur.y - bb.ll.y);
|
|
38309
38341
|
for (let bnd = 1; ; bnd++) {
|
|
38310
|
-
|
|
38311
|
-
for (const [x, y] of ring) {
|
|
38312
|
-
if (fits2(x, y, info, ctx)) return;
|
|
38313
|
-
}
|
|
38342
|
+
if (wide ? ringWide(bnd, info, ctx) : ringTall(bnd, info, ctx)) return;
|
|
38314
38343
|
}
|
|
38315
38344
|
}
|
|
38316
38345
|
function polyGraphs(gs, root, pinfo, bbs) {
|