Пример #1
0
 //------------------------------------------------------------------------------
 public static IntRect GetBounds(List<List<IntPoint>> paths)
 {
     int i = 0, cnt = paths.Count;
     while (i < cnt && paths[i].Count == 0) i++;
     if (i == cnt) return new IntRect(0, 0, 0, 0);
     IntRect result = new IntRect();
     result.left = paths[i][0].X;
     result.right = result.left;
     result.top = paths[i][0].Y;
     result.bottom = result.top;
     for (; i < cnt; i++)
         for (int j = 0; j < paths[i].Count; j++)
         {
             if (paths[i][j].X < result.left) result.left = paths[i][j].X;
             else if (paths[i][j].X > result.right) result.right = paths[i][j].X;
             if (paths[i][j].Y < result.top) result.top = paths[i][j].Y;
             else if (paths[i][j].Y > result.bottom) result.bottom = paths[i][j].Y;
         }
     return result;
 }
Пример #2
0
            public Boolean SaveToFile(string filename, double scale = 1.0, int margin = 10)
            {
                if (scale == 0) scale = 1.0;
                if (margin < 0) margin = 0;

                //calculate the bounding rect ...
                int i = 0, j = 0;
                while (i < PolyInfoList.Count)
                {
                    j = 0;
                    while (j < PolyInfoList[i].polygons.Count &&
                        PolyInfoList[i].polygons[j].Count == 0) j++;
                    if (j < PolyInfoList[i].polygons.Count) break;
                    i++;
                }
                if (i == PolyInfoList.Count) return false;
                IntRect rec = new IntRect();
                rec.left = PolyInfoList[i].polygons[j][0].X;
                rec.right = rec.left;
                rec.top = PolyInfoList[0].polygons[j][0].Y;
                rec.bottom = rec.top;

                for (; i < PolyInfoList.Count; i++)
                {
                    foreach (Polygon pg in PolyInfoList[i].polygons)
                        foreach (IntPoint pt in pg)
                        {
                            if (pt.X < rec.left) rec.left = pt.X;
                            else if (pt.X > rec.right) rec.right = pt.X;
                            if (pt.Y < rec.top) rec.top = pt.Y;
                            else if (pt.Y > rec.bottom) rec.bottom = pt.Y;
                        }
                }

                rec.left = (Int64)((double)rec.left * scale);
                rec.top = (Int64)((double)rec.top * scale);
                rec.right = (Int64)((double)rec.right * scale);
                rec.bottom = (Int64)((double)rec.bottom * scale);
                Int64 offsetX = -rec.left + margin;
                Int64 offsetY = -rec.top + margin;

                StreamWriter writer = new StreamWriter(filename);
                if (writer == null) return false;
                writer.Write(svg_header,
                    (rec.right - rec.left) + margin * 2,
                    (rec.bottom - rec.top) + margin * 2,
                    (rec.right - rec.left) + margin * 2,
                    (rec.bottom - rec.top) + margin * 2);

                foreach (PolyInfo pi in PolyInfoList)
                {
                    writer.Write(" <path d=\"");
                    foreach (Polygon p in pi.polygons)
                    {
                        if (p.Count < 3) continue;
                        writer.Write(String.Format(NumberFormatInfo.InvariantInfo, " M {0:f2} {1:f2}",
                            (double)((double)p[0].X * scale + offsetX),
                            (double)((double)p[0].Y * scale + offsetY)));
                        for (int k = 1; k < p.Count; k++)
                        {
                            writer.Write(String.Format(NumberFormatInfo.InvariantInfo, " L {0:f2} {1:f2}",
                            (double)((double)p[k].X * scale + offsetX),
                            (double)((double)p[k].Y * scale + offsetY)));
                        }
                        writer.Write(" z");
                    }

                    writer.Write(String.Format(NumberFormatInfo.InvariantInfo, svg_path_format,
                    ColorTranslator.ToHtml(pi.si.brushClr),
                    (float)pi.si.brushClr.A / 255,
                    (pi.si.pft == PolyFillType.pftEvenOdd ? "evenodd" : "nonzero"),
                    ColorTranslator.ToHtml(pi.si.penClr),
                    (float)pi.si.penClr.A / 255,
                    pi.si.penWidth));

                    if (pi.si.showCoords)
                    {
                        writer.Write("<g font-family=\"Verdana\" font-size=\"11\" fill=\"black\">\n\n");
                        foreach (Polygon p in pi.polygons)
                        {
                            foreach (IntPoint pt in p)
                            {
                                Int64 x = pt.X;
                                Int64 y = pt.Y;
                                writer.Write(String.Format(
                                    "<text x=\"{0}\" y=\"{1}\">{2},{3}</text>\n",
                                    (int)(x * scale + offsetX), (int)(y * scale + offsetY), x, y));

                            }
                            writer.Write("\n");
                        }
                        writer.Write("</g>\n");
                    }
                }
                writer.Write("</svg>\n");
                writer.Close();
                return true;
            }
        //------------------------------------------------------------------------------
        public IntRect GetBounds()
        {
            IntRect result = new IntRect();
            LocalMinima lm = m_MinimaList;
            if (lm == null) return result;
            result.left = lm.leftBound.xbot;
            result.top = lm.leftBound.ybot;
            result.right = lm.leftBound.xbot;
            result.bottom = lm.leftBound.ybot;
            while (lm != null)
            {
                if (lm.leftBound.ybot > result.bottom)
                    result.bottom = lm.leftBound.ybot;
                TEdge e = lm.leftBound;
                for (; ; )
                {
                    TEdge bottomE = e;
                    while (e.nextInLML != null)
                    {
                        if (e.xbot < result.left) result.left = e.xbot;
                        if (e.xbot > result.right) result.right = e.xbot;
                        e = e.nextInLML;
                    }
                    if (e.xbot < result.left) result.left = e.xbot;
                    if (e.xbot > result.right) result.right = e.xbot;
                    if (e.xtop < result.left) result.left = e.xtop;
                    if (e.xtop > result.right) result.right = e.xtop;
                    if (e.ytop < result.top) result.top = e.ytop;

                    if (bottomE == lm.leftBound) e = lm.rightBound;
                    else break;
                }
                lm = lm.next;
            }
            return result;
        }
Пример #4
0
 public IntRect(IntRect ir)
 {
   this.left = ir.left; this.top = ir.top;
   this.right = ir.right; this.bottom = ir.bottom;
 }
Пример #5
0
      //------------------------------------------------------------------------------

      public IntRect GetBounds()
      {
          IntRect result = new IntRect();
          LocalMinima lm = m_MinimaList;
          if (lm == null) return result;
          result.left = lm.LeftBound.Bot.X;
          result.top = lm.LeftBound.Bot.Y;
          result.right = lm.LeftBound.Bot.X;
          result.bottom = lm.LeftBound.Bot.Y;
          while (lm != null)
          {
              if (lm.LeftBound.Bot.Y > result.bottom)
                  result.bottom = lm.LeftBound.Bot.Y;
              TEdge e = lm.LeftBound;
              for (; ; )
              {
                  TEdge bottomE = e;
                  while (e.NextInLML != null)
                  {
                      if (e.Bot.X < result.left) result.left = e.Bot.X;
                      if (e.Bot.X > result.right) result.right = e.Bot.X;
                      e = e.NextInLML;
                  }
                  if (e.Bot.X < result.left) result.left = e.Bot.X;
                  if (e.Bot.X > result.right) result.right = e.Bot.X;
                  if (e.Top.X < result.left) result.left = e.Top.X;
                  if (e.Top.X > result.right) result.right = e.Top.X;
                  if (e.Top.Y < result.top) result.top = e.Top.Y;

                  if (bottomE == lm.LeftBound) e = lm.RightBound;
                  else break;
              }
              lm = lm.Next;
          }
          return result;
      }
Пример #6
0
        //------------------------------------------------------------------------------

        public IntRect GetBounds()
        {
            IntRect     result = new IntRect();
            LocalMinima lm     = m_MinimaList;

            if (lm == null)
            {
                return(result);
            }
            result.left   = lm.LeftBound.Bot.X;
            result.top    = lm.LeftBound.Bot.Y;
            result.right  = lm.LeftBound.Bot.X;
            result.bottom = lm.LeftBound.Bot.Y;
            while (lm != null)
            {
                if (lm.LeftBound.Bot.Y > result.bottom)
                {
                    result.bottom = lm.LeftBound.Bot.Y;
                }
                TEdge e = lm.LeftBound;
                for (;;)
                {
                    TEdge bottomE = e;
                    while (e.NextInLML != null)
                    {
                        if (e.Bot.X < result.left)
                        {
                            result.left = e.Bot.X;
                        }
                        if (e.Bot.X > result.right)
                        {
                            result.right = e.Bot.X;
                        }
                        e = e.NextInLML;
                    }

                    if (e.Bot.X < result.left)
                    {
                        result.left = e.Bot.X;
                    }
                    if (e.Bot.X > result.right)
                    {
                        result.right = e.Bot.X;
                    }
                    if (e.Top.X < result.left)
                    {
                        result.left = e.Top.X;
                    }
                    if (e.Top.X > result.right)
                    {
                        result.right = e.Top.X;
                    }
                    if (e.Top.Y < result.top)
                    {
                        result.top = e.Top.Y;
                    }

                    if (bottomE == lm.LeftBound)
                    {
                        e = lm.RightBound;
                    }
                    else
                    {
                        break;
                    }
                }

                lm = lm.Next;
            }

            return(result);
        }