/* -*-ePiX-*- */
#include "epix.h"
using namespace ePiX;

// draw a regular n-gon with labeled vertices
void polygon(int n, double th_0 = 0)
{
  const double d_th(full_turn()/n);
  path poly;
  for (int i=0; i<n; ++i)
    {
      // i-th vertex
      double th(th_0 + i*d_th);
      const P vtx(cis(th));
      poly.pt(vtx);

      // set label angle
      label_angle(th + 0.25*full_turn());

      // draw label
      std::stringstream buf;
      buf << "$" << i << "$";
      dot(vtx, -8*vtx, buf.str());
    }

  poly.close().draw();
}

int main()
{
  picture(P(0,0), P(2,3), "4 x 6in");

  begin();

  border();

  // draw one hexagon in a screen
  screen scr(P(-1,-1), P(1,1));
  activate(scr);

  polygon(6);

  // marks to distinguish a vertex and orientation
  spot(P(1,0));
  black(0.3);
  line(P(-0.75,0), P(0.75,0));

  black();
  arc_arrow(P(0,0), 0.75, 0, M_PI/3);
  arc_arrow(P(0,0), 0.75, 2*M_PI/3, M_PI);
  arc_arrow(P(0,0), 0.75, 4*M_PI/3, 5*M_PI/3);
  scr.scale(0.9);

  // use layout and affine maps to draw symmetries
  inset(P(0,2), P(1,3));

  scr.rotate(2*M_PI/3);
  inset(P(0,1), P(1,2));

  scr.rotate(2*M_PI/3);
  inset(P(0,0), P(1,1));

  scr.rotate(2*M_PI/3).reflect(0);
  inset(P(1,2), P(2,3));

  scr.rotate(2*M_PI/3);
  inset(P(1,1), P(2,2));

  scr.rotate(2*M_PI/3);
  inset(P(1,0), P(2,1));

  deactivate(scr);

  // label insets
  font_size("LARGE");
  label_angle(0);
  masklabel(P(0.5, 2.5), "$e$");
  masklabel(P(0.5, 1.5), "$\\alpha$");
  masklabel(P(0.5, 0.5), "$\\alpha^2$");

  masklabel(P(1.5, 2.5), "$\\beta$");
  masklabel(P(1.5, 1.5), "$\\beta\\alpha^2$");
  masklabel(P(1.5, 0.5), "$\\beta\\alpha$");

  pst_format();
  end();
}
