faceOf static method

(int, double, double) faceOf(
  1. double x,
  2. double y,
  3. double z
)

The face and texel coordinates (0–1) direction (x, y, z) falls on: directionOf undone.

Implementation

static (int, double, double) faceOf(double x, double y, double z) {
  final ax = x.abs(), ay = y.abs(), az = z.abs();
  int face;
  double sc, tc, ma;
  if (ax >= ay && ax >= az) {
    face = x > 0 ? 0 : 1;
    sc = x > 0 ? -z : z;
    tc = -y;
    ma = ax;
  } else if (ay >= az) {
    face = y > 0 ? 2 : 3;
    sc = x;
    tc = y > 0 ? z : -z;
    ma = ay;
  } else {
    face = z > 0 ? 4 : 5;
    sc = z > 0 ? x : -x;
    tc = -y;
    ma = az;
  }
  return (face, 0.5 * (sc / ma + 1), 0.5 * (tc / ma + 1));
}