Пример #1
0
/** updates point to the point on the arc at angle angle degrees */
void arc_get_point_at_angle(Arc *arc, Point* point, real angle)
{
    Point vec;
    vec.x = cos(angle/180.0*M_PI);
    vec.y = -sin(angle/180.0*M_PI);
    point_copy(point,&arc->center);
    point_add_scaled(point,&vec,arc->radius);
}
Пример #2
0
void add_arrow_rectangle(Rectangle *rect,
                                const Point *vertex,
                                const Point *normed_dir,
                                double extra_long,double extra_trans)
{
    Point vl,vt,pt;
    vl = *normed_dir;

    point_get_perp(&vt,&vl);
    point_copy_add_scaled(&pt,vertex,&vl,extra_long);
    point_add_scaled(&pt,&vt,extra_trans);
    rectangle_add_point(rect,&pt);
    point_add_scaled(&pt,&vt,-2.0 * extra_trans);
    rectangle_add_point(rect,&pt);
    point_add_scaled(&pt,&vl,-2.0 * extra_long);
    rectangle_add_point(rect,&pt);
    point_add_scaled(&pt,&vt,2.0 * extra_trans);
    rectangle_add_point(rect,&pt);
}
Пример #3
0
void
point_convex(Point *dst, const Point *src1, const Point *src2, real alpha)
{
  /* Make convex combination of src1 and src2:
     dst = alpha * src1 + (1-alpha) * src2;
  */
  point_copy(dst,src1);
  point_scale(dst,alpha);
  point_add_scaled(dst,src2,1.0 - alpha);
}
Пример #4
0
void
polyline_calculate_gap_endpoints(Polyline *polyline, Point *gap_endpoints)
{
  Point  start_vec, end_vec;
  ConnectionPoint *start_cp, *end_cp;
  int n = polyline->poly.numpoints;

  gap_endpoints[0] = polyline->poly.points[0];
  gap_endpoints[1] = polyline->poly.points[n-1];

  start_cp = (polyline->poly.object.handles[0])->connected_to;
  end_cp = (polyline->poly.object.handles[polyline->poly.object.num_handles-1])->connected_to;

  if (connpoint_is_autogap(start_cp)) {
      gap_endpoints[0] = calculate_object_edge(&gap_endpoints[0],
					   &polyline->poly.points[1],
					   start_cp->object);
  }
  if (connpoint_is_autogap(end_cp)) {    
      gap_endpoints[1] = calculate_object_edge(&gap_endpoints[1],
					   &polyline->poly.points[n-2],
					   end_cp->object);
  }

  start_vec = gap_endpoints[0];
  point_sub(&start_vec, &polyline->poly.points[0]);
  point_normalize(&start_vec);

  end_vec = gap_endpoints[1];
  point_sub(&end_vec, &polyline->poly.points[n-1]);
  point_normalize(&end_vec);
  
  /* add absolute gap */
  point_add_scaled(&gap_endpoints[0], &start_vec, polyline->absolute_start_gap);
  point_add_scaled(&gap_endpoints[1], &end_vec, polyline->absolute_end_gap);
}
Пример #5
0
/*!
 * \brief Set the other point of the pattern
 *
 * The meaning of the point depends on the type of the pattern.
 * For line gradient it is the second point giving the direction.
 * With a radial gradient it is the focal point.
 *
 * \ingroup DiaPattern
 */
void
dia_pattern_set_point (DiaPattern *self, real x, real y)
{
  self->other.x = x;
  self->other.y = y;
  /* with radial we have to ensure the point is in circle */
  if (self->type == DIA_RADIAL_GRADIENT) {
    real dist = distance_ellipse_point (&self->start, self->radius*2, self->radius*2, 0.0, &self->other);
    if (dist > 0) {
      /* If the point defined by ‘fx’ and ‘fy’ lies outside the circle defined
       * by ‘cx’, ‘cy’ and ‘r’, then the user agent shall set the focal point to
       * the intersection of the line from (‘cx’, ‘cy’) to (‘fx’, ‘fy’) with the
       * circle defined by ‘cx’, ‘cy’ and ‘r’
       */
      Point p1 = self->start;
      Point p2 = self->other;
      point_sub (&p2, &p1);
      point_normalize (&p2);
      point_add_scaled (&p1, &p2, self->radius);
      self->other = p1;
    }
  }
}
Пример #6
0
Файл: bezier.c Проект: GNOME/dia
static void
compute_gap_points(Bezierline *bezierline, Point *gap_points)
{
        real bez_length;
        BezierConn *bez = &bezierline->bez;
        Point vec_start, vec_end;


        gap_points[0] = bez->bezier.points[0].p1;
        gap_points[1] = bez->bezier.points[1].p1;
        gap_points[2] = bez->bezier.points[bez->bezier.num_points-1].p2;
        gap_points[3] = bez->bezier.points[bez->bezier.num_points-1].p3;

        point_copy(&vec_start, &gap_points[1]);
        point_sub(&vec_start, &gap_points[0]);
        point_normalize(&vec_start); /* unit vector pointing from first point */
        point_copy(&vec_end, &gap_points[2]);
        point_sub(&vec_end, &gap_points[3]);
        point_normalize(&vec_end); /* unit vector pointing from last point */


        bez_length = approx_bez_length(bez) ;

        if (connpoint_is_autogap(bez->object.handles[0]->connected_to) &&
               (bez->object.handles[0])->connected_to != NULL &&
               (bez->object.handles[0])->connected_to->object != NULL ) {
            Point end;
            point_copy(&end, &gap_points[0]);
            point_add_scaled(&end, &vec_start, bez_length); /* far away on the same slope */
            end = calculate_object_edge(&gap_points[0], &end,
                            (bez->object.handles[0])->connected_to->object);
            point_sub(&end, &gap_points[0]); /* vector from old start to new start */
            /* move points */
            point_add(&gap_points[0], &end);
            point_add(&gap_points[1], &end);
        }

        if (connpoint_is_autogap(bez->object.handles[3*(bez->bezier.num_points-1)]->connected_to) &&
                (bez->object.handles[3*(bez->bezier.num_points-1)])->connected_to != NULL &&
                (bez->object.handles[3*(bez->bezier.num_points-1)])->connected_to->object != NULL) {
            Point end;
            point_copy(&end, &gap_points[3]);
            point_add_scaled(&end, &vec_end, bez_length); /* far away on the same slope */
            end = calculate_object_edge(&gap_points[3], &end,
                            (bez->object.handles[3*(bez->bezier.num_points-1)])->connected_to->object);
            point_sub(&end, &gap_points[3]); /* vector from old end to new end */
            /* move points */
            point_add(&gap_points[3], &end);
            point_add(&gap_points[2], &end);
        }


        /* adds the absolute start gap  according to the slope at the first point */
        point_add_scaled(&gap_points[0], &vec_start, bezierline->absolute_start_gap);
        point_add_scaled(&gap_points[1], &vec_start, bezierline->absolute_start_gap);

        /* adds the absolute end gap  according to the slope at the last point */
        point_add_scaled(&gap_points[2], &vec_end, bezierline->absolute_end_gap);
        point_add_scaled(&gap_points[3], &vec_end, bezierline->absolute_end_gap);


}