MCPcopy Create free account
hub / github.com/dailydotdev/apps / hexAt

Function hexAt

packages/webapp/components/world/engine/world.js:6886–6893  ·  view source on GitHub ↗
(x,z)

Source from the content-addressed store, hash-verified

6884/* World point -> the cell that contains it. Cube rounding, the standard trick;
6885 this is the whole of the picking system — no raycast, no colliders. */
6886function hexAt(x,z){
6887 const q=(2/3)*x/HC, r=(-x/3+Math.sqrt(3)/3*z)/HC;
6888 const cx=q, cz=r, cy=-cx-cz;
6889 let rx=Math.round(cx), ry=Math.round(cy), rz=Math.round(cz);
6890 const dx=Math.abs(rx-cx), dy=Math.abs(ry-cy), dz=Math.abs(rz-cz);
6891 if(dx>dy&&dx>dz) rx=-ry-rz; else if(dy>dz) ry=-rx-rz; else rz=-rx-ry;
6892 return [rx,rz];
6893}
6894
6895/* A district's territory is its land plus a verge for the border to live in.
6896 It tracks the CURRENT level, so a district that has been read once owns one

Callers 3

pickFunction · 0.85
handTargetAtFunction · 0.85
handReleaseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected