MCPcopy
hub / github.com/jasondavies/d3-cloud / place

Function place

index.js:110–157  ·  view source on GitHub ↗
(board, tag, bounds)

Source from the content-addressed store, hash-verified

108 }
109
110 function place(board, tag, bounds) {
111 var perimeter = [{x: 0, y: 0}, {x: size[0], y: size[1]}],
112 startX = tag.x,
113 startY = tag.y,
114 maxDelta = Math.sqrt(size[0] * size[0] + size[1] * size[1]),
115 s = spiral(size),
116 dt = random() < .5 ? 1 : -1,
117 t = -dt,
118 dxdy,
119 dx,
120 dy;
121
122 while (dxdy = s(t += dt)) {
123 dx = ~~dxdy[0];
124 dy = ~~dxdy[1];
125
126 if (Math.min(Math.abs(dx), Math.abs(dy)) >= maxDelta) break;
127
128 tag.x = startX + dx;
129 tag.y = startY + dy;
130
131 if (tag.x + tag.x0 < 0 || tag.y + tag.y0 < 0 ||
132 tag.x + tag.x1 > size[0] || tag.y + tag.y1 > size[1]) continue;
133 // TODO only check for collisions within current bounds.
134 if (!bounds || collideRects(tag, bounds)) {
135 if (!cloudCollide(tag, board, size[0])) {
136 var sprite = tag.sprite,
137 w = tag.width >> 5,
138 sw = size[0] >> 5,
139 lx = tag.x - (w << 4),
140 sx = lx & 0x7f,
141 msx = 32 - sx,
142 h = tag.y1 - tag.y0,
143 x = (tag.y + tag.y0) * sw + (lx >> 5),
144 last;
145 for (var j = 0; j < h; j++) {
146 last = 0;
147 for (var i = 0; i <= w; i++) {
148 board[x + i] |= (last << msx) | (i < w ? (last = sprite[j * w + i]) >>> sx : 0);
149 }
150 x += sw;
151 }
152 return true;
153 }
154 }
155 }
156 return false;
157 }
158
159 cloud.timeInterval = function(_) {
160 return arguments.length ? (timeInterval = _ == null ? Infinity : _, cloud) : timeInterval;

Callers 1

stepFunction · 0.85

Calls 2

collideRectsFunction · 0.85
cloudCollideFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…