Example #1
0
static status
computeBoundingBoxBezier(Bezier b)
{ reg r;

  r.minx = 1000000;
  r.miny = 1000000;
  r.maxx = -1000000;
  r.maxy = -10000000;

  if ( b->selected == ON )
  { int mw=5, mh=5;

    include_in_reg(&r, b->start);
    include_in_reg(&r, b->end);
    include_in_reg(&r, b->control1);
    if ( notNil(b->control2) )
      include_in_reg(&r, b->control2);

    r.minx -= (mw+1)/2;
    r.maxx += (mw+1)/2;
    r.miny -= (mh+1)/2;
    r.maxy += (mh+1)/2;
  } else
  { ipoint ptsbuf[MAXPTS];
    IPoint pts = ptsbuf;
    int npts = MAXPTS;
    int i;

    compute_points_bezier(b, pts, &npts);

    for(i=0; i<npts; i++,pts++)
    { if ( pts[0].x < r.minx ) r.minx = pts[0].x;
      if ( pts[0].x > r.maxx ) r.maxx = pts[0].x;
      if ( pts[0].y < r.miny ) r.miny = pts[0].y;
      if ( pts[0].y > r.maxy ) r.maxy = pts[0].y;
    }
  }

  if ( r.maxx >= r.minx && r.maxy >= r.miny )
  { int pens = valInt(b->pen) / 2;
    int pena = (valInt(b->pen) % 2 == 0 ? pens : pens + 1);

    r.minx -= pens; r.maxx += pena;
    r.miny -= pens; r.maxy += pena;

    assign(b->area, x, toInt(r.minx));
    assign(b->area, y, toInt(r.miny));
    assign(b->area, w, toInt(r.maxx - r.minx));
    assign(b->area, h, toInt(r.maxy - r.miny));
  } else
    clearArea(b->area);

  if ( adjustFirstArrowBezier(b) )
    unionNormalisedArea(b->area, b->first_arrow->area);
  if ( adjustSecondArrowBezier(b) )
    unionNormalisedArea(b->area, b->second_arrow->area);

  succeed;
}
Example #2
0
static void
includeArrowsInAreaArc(Arc a)
{ if ( notNil(a->first_arrow) || notNil(a->second_arrow) )
  { int sx, sy, ex, ey;
    int cx, cy;
    Any av[4];

    points_arc(a, &sx, &sy, &ex, &ey);
    cx = valInt(a->position->x);
    cy = valInt(a->position->y);

    if ( notNil(a->first_arrow) )
    { av[0] = toInt(sx);
      av[1] = toInt(sy);

      if ( valReal(a->size_angle) >= 0.0 )
      { av[2] = toInt(sx+(sy-cy));
	av[3] = toInt(sy-(sx-cx));
      } else
      { av[2] =	toInt(sx-(sy-cy));
	av[3] = toInt(sy+(sx-cx));
      }

      if ( qadSendv(a->first_arrow, NAME_points, 4, av) )
      { ComputeGraphical(a->first_arrow);
	unionNormalisedArea(a->area, a->first_arrow->area);
      }
    }
    if ( notNil(a->second_arrow) )
    { av[0] = toInt(ex);
      av[1] = toInt(ey);

      if ( valReal(a->size_angle) >= 0.0 )
      { av[2] = toInt(ex-(ey-cy));
	av[3] = toInt(ey+(ex-cx));
      } else
      { av[2] = toInt(ex+(ey-cy));
	av[3] = toInt(ey-(ex-cx));
      }

      if ( qadSendv(a->second_arrow, NAME_points, 4, av) )
      { ComputeGraphical(a->second_arrow);
	unionNormalisedArea(a->area, a->second_arrow->area);
      }
    }
  }
}
Example #3
0
status
computeLine(Line ln)
{ if ( notNil(ln->request_compute) )
  { int x1  = valInt(ln->start_x);
    int x2  = valInt(ln->end_x);
    int y1  = valInt(ln->start_y);
    int y2  = valInt(ln->end_y);
    int pen = valInt(ln->pen);
    int x, y, w, h;
    Area a = ln->area;

    if ( x1 < x2 )
    { x = x1;
      w = x2-x1;
    } else
    { x = x2;
      w = x1-x2;
    }
    if ( y1 < y2 )
    { y = y1;
      h = y2-y1;
    } else
    { y = y2;
      h = y1-y2;
    }

    if ( pen ==	1 )
    { w++;
      h++;
    } else if ( pen > 1 )
    { int ex = (h > 0 ? (pen*h)/(w+h) : 0); /* h = 0: horizontal line */
      int ey = (w > 0 ? (pen*w)/(w+h) : 0); /* w = 0: vertical line */
      int hx = ex/2;
      int hy = ey/2;

      x -= hx;
      w += ex;
      y -= hy;
      h += ey;
    }

    if ( ln->selected == ON )	/* should be solved elsewhere */
    { x -= 3;
      y -= 3;
      w += 6;
      h += 6;
    }

    CHANGING_GRAPHICAL(ln,
		       assign(a, x, toInt(x));
		       assign(a, y, toInt(y));
		       assign(a, w, toInt(w));
		       assign(a, h, toInt(h));

		       if ( adjustFirstArrowLine(ln) )
			 unionNormalisedArea(a, ln->first_arrow->area);
		       if ( adjustSecondArrowLine(ln) )
			 unionNormalisedArea(a, ln->second_arrow->area);

		       changedEntireImageGraphical(ln));

    assign(ln, request_compute, NIL);
  }