PageSourceSearch

https://starwarsdatabase.com/gallery/src/honeycomb-layout.js?v=0.67.1

js starwarsdatabase.com collected 2026-10-07 19:30:24 UTC 1,825 bytes, 19 lines download raw bytes

1// Flat-topped hexagons with alternating columns raised by half a cell.
2// Radius never changes; only rows/columns and the furniture's bounds do.
3export const HONEYCOMB=Object.freeze({capacity:25,radius:.275,wall:.025,depth:.64,layoutDepth:2.40,bottom:.18});
4export function honeycombGrid(columns,rows){
5  if(!Number.isInteger(columns)||!Number.isInteger(rows)||columns<3||columns>5||rows<3||rows>5)throw new RangeError('Honeycomb requires three to five rows and columns.');
6  const r=HONEYCOMB.radius,pitchY=Math.sqrt(3)*r,cellWidth=2*r,gridWidth=(columns-1)*1.5*r+cellWidth,gridHeight=(rows+.5)*pitchY,top=HONEYCOMB.bottom+gridHeight;
7  return {columns,rows,capacity:columns*rows,cellWidth,cellHeight:pitchY,pitchX:1.5*r,pitchY,gridWidth,gridHeight,top,width:gridWidth+.12,depth:HONEYCOMB.depth,layoutDepth:HONEYCOMB.layoutDepth,height:top+.37,approach:Math.max(2.65,(top/2+.29)/Math.tan(28.5*Math.PI/180)+.24)};
8}
9export function honeycombLayout(count){
10  if(!Number.isInteger(count)||count<1||count>HONEYCOMB.capacity)throw new RangeError('Invalid Honeycomb population.');
11  const choices=[];for(let rows=3;rows<=5;rows++)for(let columns=3;columns<=5;columns++){const grid=honeycombGrid(columns,rows);if(grid.capacity>=count)choices.push(grid);}
12  // Minimize empty cells, then prefer balanced physical proportions.
13  choices.sort((a,b)=>a.capacity-b.capacity||Math.abs(Math.log(a.gridWidth/a.gridHeight))-Math.abs(Math.log(b.gridWidth/b.gridHeight))||a.rows-b.rows);
14  return choices[0];
15}
16export function honeycombSlots(layout){
17  const {columns,rows,pitchX,pitchY}=layout;
18  return Array.from({length:columns*rows},(_,index)=>{const row=Math.floor(index/columns),column=index%columns;return {index,row,column,x:(column-(columns-1)/2)*pitchX,y:HONEYCOMB.bottom+pitchY/2+(rows-1-row)*pitchY+(column%2?pitchY/2:0)};});
19}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.