Пример #1
0
static POLYAREA *
original_poly (PolygonType * p, bool *forward)
{
  PLINE *contour = NULL;
  POLYAREA *np = NULL;
  Cardinal n;
  Vector v;
  int hole = 0;

  *forward = true;

  if ((np = poly_Create ()) == NULL)
    return NULL;

  /* first make initial polygon contour */
  for (n = 0; n < p->PointN; n++)
    {
      /* No current contour? Make a new one starting at point */
      /*   (or) Add point to existing contour */

      v[0] = p->Points[n].X;
      v[1] = p->Points[n].Y;
      if (contour == NULL)
        {
          if ((contour = poly_NewContour (v)) == NULL)
            return NULL;
        }
      else
        {
          poly_InclVertex (contour->head.prev, poly_CreateNode (v));
        }

      /* Is current point last in contour? If so process it. */
      if (n == p->PointN - 1 ||
          (hole < p->HoleIndexN && n == p->HoleIndex[hole] - 1))
        {
          poly_PreContour (contour, TRUE);

          /* Log the direction in which the outer contour was specified */
          if (hole == 0)
            *forward = (contour->Flags.orient == PLF_DIR);

          /* make sure it is a positive contour (outer) or negative (hole) */
          if (contour->Flags.orient != (hole ? PLF_INV : PLF_DIR))
            poly_InvContour (contour);
          assert (contour->Flags.orient == (hole ? PLF_INV : PLF_DIR));

          poly_InclContour (np, contour);
          contour = NULL;
          assert (poly_Valid (np));

          hole++;
        }
  }
  return np;
}
Пример #2
0
static POLYAREA *
diag_line (Coord X, Coord Y, Coord l, Coord w, bool rt)
{
  PLINE *c;
  Vector v;
  Coord x1, x2, y1, y2;

  if (rt)
    {
      x1 = (l - w) * M_SQRT1_2;
      x2 = (l + w) * M_SQRT1_2;
      y1 = x1;
      y2 = x2;
    }
  else
    {
      x2 = -(l - w) * M_SQRT1_2;
      x1 = -(l + w) * M_SQRT1_2;
      y1 = -x1;
      y2 = -x2;
    }

  v[0] = X + x1;
  v[1] = Y + y2;
  if ((c = poly_NewContour (v)) == NULL)
    return NULL;
  v[0] = X - x2;
  v[1] = Y - y1;
  poly_InclVertex (c->head.prev, poly_CreateNode (v));
  v[0] = X - x1;
  v[1] = Y - y2;
  poly_InclVertex (c->head.prev, poly_CreateNode (v));
  v[0] = X + x2;
  v[1] = Y + y1;
  poly_InclVertex (c->head.prev, poly_CreateNode (v));
  return ContourToPoly (c);
}
Пример #3
0
static POLYAREA *
square_therm (PinTypePtr pin, Cardinal style)
{
  POLYAREA *p, *p2;
  PLINE *c;
  Vector v;
  Coord d, in, out;

  switch (style)
    {
    case 1:
      d = pcb->ThermScale * pin->Clearance * M_SQRT1_2;
      out = (pin->Thickness + pin->Clearance) / 2;
      in = pin->Thickness / 2;
      /* top (actually bottom since +y is down) */
      v[0] = pin->X - in + d;
      v[1] = pin->Y + in;
      if ((c = poly_NewContour (v)) == NULL)
        return NULL;
      v[0] = pin->X + in - d;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      v[0] = pin->X + out - d;
      v[1] = pin->Y + out;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      v[0] = pin->X - out + d;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      p = ContourToPoly (c);
      /* right */
      v[0] = pin->X + in;
      v[1] = pin->Y + in - d;
      if ((c = poly_NewContour (v)) == NULL)
        return NULL;
      v[1] = pin->Y - in + d;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      v[0] = pin->X + out;
      v[1] = pin->Y - out + d;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      v[1] = pin->Y + out - d;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      p2 = ContourToPoly (c);
      p->f = p2;
      p2->b = p;
      /* left */
      v[0] = pin->X - in;
      v[1] = pin->Y - in + d;
      if ((c = poly_NewContour (v)) == NULL)
        return NULL;
      v[1] = pin->Y + in - d;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      v[0] = pin->X - out;
      v[1] = pin->Y + out - d;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      v[1] = pin->Y - out + d;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      p2 = ContourToPoly (c);
      p->f->f = p2;
      p2->b = p->f;
      /* bottom (actually top since +y is down) */
      v[0] = pin->X + in - d;
      v[1] = pin->Y - in;
      if ((c = poly_NewContour (v)) == NULL)
        return NULL;
      v[0] = pin->X - in + d;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      v[0] = pin->X - out + d;
      v[1] = pin->Y - out;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      v[0] = pin->X + out - d;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      p2 = ContourToPoly (c);
      p->f->f->f = p2;
      p2->f = p;
      p2->b = p->f->f;
      p->b = p2;
      return p;
    case 4:
      {
        LineType l;
        l.Flags = NoFlags ();
        d = pin->Thickness / 2 - pcb->ThermScale * pin->Clearance;
        out = pin->Thickness / 2 + pin->Clearance / 4;
        in = pin->Clearance / 2;
        /* top */
        l.Point1.X = pin->X - d;
        l.Point2.Y = l.Point1.Y = pin->Y + out;
        l.Point2.X = pin->X + d;
        p = LinePoly (&l, in);
        /* right */
        l.Point1.X = l.Point2.X = pin->X + out;
        l.Point1.Y = pin->Y - d;
        l.Point2.Y = pin->Y + d;
        p2 = LinePoly (&l, in);
        p->f = p2;
        p2->b = p;
        /* bottom */
        l.Point1.X = pin->X - d;
        l.Point2.Y = l.Point1.Y = pin->Y - out;
        l.Point2.X = pin->X + d;
        p2 = LinePoly (&l, in);
        p->f->f = p2;
        p2->b = p->f;
        /* left */
        l.Point1.X = l.Point2.X = pin->X - out;
        l.Point1.Y = pin->Y - d;
        l.Point2.Y = pin->Y + d;
        p2 = LinePoly (&l, in);
        p->f->f->f = p2;
        p2->b = p->f->f;
        p->b = p2;
        p2->f = p;
        return p;
      }
    default:                   /* style 2 and 5 */
      d = 0.5 * pcb->ThermScale * pin->Clearance;
      if (style == 5)
        d += d;
      out = (pin->Thickness + pin->Clearance) / 2;
      in = pin->Thickness / 2;
      /* topright */
      v[0] = pin->X + in;
      v[1] = pin->Y + in;
      if ((c = poly_NewContour (v)) == NULL)
        return NULL;
      v[1] = pin->Y + d;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      if (style == 2)
        {
          v[0] = pin->X + out;
          poly_InclVertex (c->head.prev, poly_CreateNode (v));
        }
      else
        frac_circle (c, v[0] + pin->Clearance / 4, v[1], v, 2);
      v[1] = pin->Y + in;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      /* pivot 1/4 circle to next point */
      frac_circle (c, pin->X + in, pin->Y + in, v, 4);
      v[0] = pin->X + d;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      if (style == 2)
        {
          poly_InclVertex (c->head.prev, poly_CreateNode (v));
          v[1] = pin->Y + in;
          poly_InclVertex (c->head.prev, poly_CreateNode (v));
        }
      else
        frac_circle (c, v[0], v[1] - pin->Clearance / 4, v, 2);
      p = ContourToPoly (c);
      /* bottom right */
      v[0] = pin->X + in;
      v[1] = pin->Y - d;
      if ((c = poly_NewContour (v)) == NULL)
        return NULL;
      v[1] = pin->Y - in;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      v[0] = pin->X + d;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      if (style == 2)
        {
          v[1] = pin->Y - out;
          poly_InclVertex (c->head.prev, poly_CreateNode (v));
        }
      else
        frac_circle (c, v[0], v[1] - pin->Clearance / 4, v, 2);
      v[0] = pin->X + in;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      /* pivot 1/4 circle to next point */
      frac_circle (c, pin->X + in, pin->Y - in, v, 4);
      v[1] = pin->Y - d;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      if (style == 5)
        frac_circle (c, v[0] - pin->Clearance / 4, v[1], v, 2);
      p2 = ContourToPoly (c);
      p->f = p2;
      p2->b = p;
      /* bottom left */
      v[0] = pin->X - d;
      v[1] = pin->Y - in;
      if ((c = poly_NewContour (v)) == NULL)
        return NULL;
      v[0] = pin->X - in;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      v[1] = pin->Y - d;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      if (style == 2)
        {
          v[0] = pin->X - out;
          poly_InclVertex (c->head.prev, poly_CreateNode (v));
        }
      else
        frac_circle (c, v[0] - pin->Clearance / 4, v[1], v, 2);
      v[1] = pin->Y - in;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      /* pivot 1/4 circle to next point */
      frac_circle (c, pin->X - in, pin->Y - in, v, 4);
      v[0] = pin->X - d;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      if (style == 5)
        frac_circle (c, v[0], v[1] + pin->Clearance / 4, v, 2);
      p2 = ContourToPoly (c);
      p->f->f = p2;
      p2->b = p->f;
      /* top left */
      v[0] = pin->X - d;
      v[1] = pin->Y + out;
      if ((c = poly_NewContour (v)) == NULL)
        return NULL;
      v[0] = pin->X - in;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      /* pivot 1/4 circle to next point (x-out, y+in) */
      frac_circle (c, pin->X - in, pin->Y + in, v, 4);
      v[1] = pin->Y + d;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      if (style == 2)
        {
          v[0] = pin->X - in;
          poly_InclVertex (c->head.prev, poly_CreateNode (v));
        }
      else
        frac_circle (c, v[0] + pin->Clearance / 4, v[1], v, 2);
      v[1] = pin->Y + in;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      v[0] = pin->X - d;
      poly_InclVertex (c->head.prev, poly_CreateNode (v));
      if (style == 5)
        frac_circle (c, v[0], v[1] + pin->Clearance / 4, v, 2);
      p2 = ContourToPoly (c);
      p->f->f->f = p2;
      p2->f = p;
      p2->b = p->f->f;
      p->b = p2;
      return p;
    }
}