+vector tet_piecemins;
+vector tet_piecemaxs;
+void PieceMinsMaxs(float rot, float pc)
+{
+ vector sz, ce;
+ float t;
+ vector v;
+
+ sz = PieceSize(pc);
+ ce = PieceCenter(pc);
+ // 1 = 2..2
+ // 2 = 2..3
+ // 3 = 1..3
+ // 4 = 1..4
+ tet_piecemins_x = floor(3.0 - sz_x * 0.5);
+ tet_piecemaxs_x = floor(2.0 + sz_x * 0.5);
+ if(sz_y == 1)
+ {
+ // special case for "I"
+ tet_piecemins_y = tet_piecemaxs_y = 2;
+ }
+ else
+ {
+ tet_piecemins_y = 1;
+ tet_piecemaxs_y = sz_y;
+ }
+ //print(sprintf("ce%v sz%v mi%v ma%v\n", ce, sz, tet_piecemins, tet_piecemaxs));
+ if (rot == 1) // 90 degrees
+ {
+ t = tet_piecemins_y;
+ tet_piecemins_y = -tet_piecemins_x + ce_y + ce_x;
+ tet_piecemins_x = t - ce_y + ce_x;
+ t = tet_piecemaxs_y;
+ tet_piecemaxs_y = -tet_piecemaxs_x + ce_y + ce_x;
+ tet_piecemaxs_x = t - ce_y + ce_x;
+ // swap mins_y, maxs_y
+ t = tet_piecemins_y;
+ tet_piecemins_y = tet_piecemaxs_y;
+ tet_piecemaxs_y = t;
+ // TODO OPTIMIZE
+ }
+ else if (rot == 2)//180
+ {
+ v = tet_piecemins;
+ tet_piecemins = 2 * ce - tet_piecemaxs;
+ tet_piecemaxs = 2 * ce - v;
+ }
+ else if (rot == 3) // 270
+ {
+ t = tet_piecemins_y;
+ tet_piecemins_y = tet_piecemins_x - ce_x + ce_y;
+ tet_piecemins_x = -t + ce_x + ce_y;
+ t = tet_piecemaxs_y;
+ tet_piecemaxs_y = tet_piecemaxs_x - ce_x + ce_y;
+ tet_piecemaxs_x = -t + ce_x + ce_y;
+ // swap mins_x, maxs_x
+ t = tet_piecemins_x;
+ tet_piecemins_x = tet_piecemaxs_x;
+ tet_piecemaxs_x = t;
+ // TODO OPTIMIZE
+ }
+#ifdef VERIFY
+ print(vtos(tet_piecemins), "-");
+ print(vtos(tet_piecemaxs), "\n");
+ if(tet_piecemins_x > tet_piecemaxs_x)
+ error("inconsistent mins/maxs");
+ if(tet_piecemins_y > tet_piecemaxs_y)
+ error("inconsistent mins/maxs");
+ float i, j;
+ vector realmins, realmaxs;
+ realmins = '4 4 0';
+ realmaxs = '1 1 0';
+ for(i = 1; i <= 4; ++i)
+ for(j = 1; j <= 4; ++j)
+ if(PieceMetric(i, j, rot, pc))
+ {
+ realmins_x = min(realmins_x, i);
+ realmins_y = min(realmins_y, j);
+ realmaxs_x = max(realmaxs_x, i);
+ realmaxs_y = max(realmaxs_y, j);
+ }
+ if(realmins != tet_piecemins || realmaxs != tet_piecemaxs)
+ error(sprintf("incorrect mins/maxs: %v %v in %d rot %d mins %v maxs %v\n", realmins, realmaxs, rot, pc, tet_piecemins, tet_piecemaxs));
+#endif
+}