in src/WordCloud.ts [1249:1322]
private findPosition(surface: number[], word: WordCloudDataPoint, borders: IPoint[], index: number): boolean {
let startPoint: IPoint = { x: word.x, y: word.y },
delta: number = Math.sqrt(this.specialViewport.width * this.specialViewport.width
+ this.specialViewport.height * this.specialViewport.height),
dt: number = WordCloud.GET_FROM_CYCLED_SEQUENCE(WordCloud.PreparedRandoms, index) < WordCloud.AdditionalRandomValue
? WordCloud.DefaultDT
: -WordCloud.DefaultDT;
let shift: number = -dt, point: IPoint, dx: number, dy: number;
let exitRequired = false;
while (!exitRequired) {
shift += dt;
point = this.archimedeanSpiral(shift);
dx = Math.floor(point.x);
dy = Math.floor(point.y);
exitRequired = Math.min(Math.abs(dx), Math.abs(dy)) >= delta;
if (exitRequired) {
break;
}
word.x = startPoint.x + dx;
word.y = startPoint.y + dy;
if (word.x + word.x0 < WordCloud.DefaultX0
|| word.y + word.y0 < WordCloud.DefaultY0
|| word.x + word.x1 > this.specialViewport.width
|| word.y + word.y1 > this.specialViewport.height) {
continue;
}
if (!borders || !this.checkIntersect(word, surface)) {
if (!borders || this.checkIntersectOfRectangles(word, borders[0], borders[1])) {
let sprite: number[] = word.sprite,
width: number = word.width >> WordCloud.WidthOffset,
shiftWidth: number = this.specialViewport.width >> WordCloud.WidthOffset,
lx: number = word.x - (width << WordCloud.LxOffset),
sx: number = lx & WordCloud.SxMask,
msx: number = WordCloud.TheFirstByteMask - sx,
height: number = word.y1 - word.y0,
x: number = (word.y + word.y0) * shiftWidth + (lx >> WordCloud.WidthOffset);
for (let i: number = 0; i < height; i++) {
let lastSprite: number = 0;
for (let j: number = 0; j <= width; j++) {
let leftMask: number = lastSprite << msx,
rightMask: number;
if (j < width)
lastSprite = sprite[i * width + j];
rightMask = j < width
? lastSprite >>> sx
: 0;
surface[x + j] |= leftMask | rightMask;
}
x += shiftWidth;
}
word.sprite = null;
return true;
}
}
}
return false;
}