MeshExplorer.IO.EpsImage.DrawTriangles C# (CSharp) Method

DrawTriangles() private method

private DrawTriangles ( StreamWriter eps, Mesh mesh, bool label ) : void
eps System.IO.StreamWriter
mesh TriangleNet.Mesh
label bool
return void
        private void DrawTriangles(StreamWriter eps, Mesh mesh, bool label)
        {
            eps.WriteLine("%");
            eps.WriteLine("%  Set the triangle line color and width.");
            eps.WriteLine("%");
            eps.WriteLine("0.6  0.6  0.6 setrgbcolor");
            eps.WriteLine("0.5 setlinewidth");
            eps.WriteLine("%");
            eps.WriteLine("%  Draw the triangles.");
            eps.WriteLine("%");

            StringBuilder labels = new StringBuilder();

            Vertex v1, v2, v3;
            double x1, y1, x2, y2, x3, y3, xa, ya;
            int x_ps, y_ps;

            foreach (var tri in mesh.Triangles)
            {
                eps.WriteLine("newpath");

                v1 = tri.GetVertex(0);
                v2 = tri.GetVertex(1);
                v3 = tri.GetVertex(2);

                x1 = v1.X; y1 = v1.Y;
                x2 = v2.X; y2 = v2.Y;
                x3 = v3.X; y3 = v3.Y;

                x_ps = (int)Math.Floor(((x_max - x1) * x_ps_min + (x1 - x_min) * x_ps_max) / (x_max - x_min));
                y_ps = (int)Math.Floor(((y_max - y1) * y_ps_min + (y1 - y_min) * y_ps_max) / (y_max - y_min));
                eps.WriteLine("  {0}  {1}  moveto", x_ps, y_ps);

                x_ps = (int)Math.Floor(((x_max - x2) * x_ps_min + (x2 - x_min) * x_ps_max) / (x_max - x_min));
                y_ps = (int)Math.Floor(((y_max - y2) * y_ps_min + (y2 - y_min) * y_ps_max) / (y_max - y_min));
                eps.WriteLine("  {0}  {1}  lineto", x_ps, y_ps);

                x_ps = (int)Math.Floor(((x_max - x3) * x_ps_min + (x3 - x_min) * x_ps_max) / (x_max - x_min));
                y_ps = (int)Math.Floor(((y_max - y3) * y_ps_min + (y3 - y_min) * y_ps_max) / (y_max - y_min));
                eps.WriteLine("  {0}  {1}  lineto", x_ps, y_ps);

                x_ps = (int)Math.Floor(((x_max - x1) * x_ps_min + (x1 - x_min) * x_ps_max) / (x_max - x_min));
                y_ps = (int)Math.Floor(((y_max - y1) * y_ps_min + (y1 - y_min) * y_ps_max) / (y_max - y_min));
                eps.WriteLine("  {0}  {1}  lineto", x_ps, y_ps);

                if (label)
                {
                    xa = (x1 + x2 + x3) / 3.0;
                    ya = (y1 + y2 + y3) / 3.0;

                    x_ps = (int)Math.Floor(((x_max - xa) * x_ps_min + (xa - x_min) * x_ps_max) / (x_max - x_min));
                    y_ps = (int)Math.Floor(((y_max - ya) * y_ps_min + (ya - y_min) * y_ps_max) / (y_max - y_min));

                    labels.AppendFormat("  {0}  {1}  moveto ({2}) show", x_ps, y_ps, tri.ID);
                    labels.AppendLine();
                }

                eps.WriteLine("stroke");
            }

            //  Label the triangles.
            if (label)
            {
                eps.WriteLine("%");
                eps.WriteLine("%  Label the triangles.");
                eps.WriteLine("%");
                eps.WriteLine("%  Set the RGB color to darker red.");
                eps.WriteLine("%");
                eps.WriteLine("0.950  0.250  0.150 setrgbcolor");
                eps.WriteLine("/Times-Roman findfont");
                eps.WriteLine("0.20 inch scalefont");
                eps.WriteLine("setfont");
                eps.WriteLine("%");

                eps.Write(labels.ToString());
            }
        }