Lines Matching refs:bez
43 static INLINE void split_left(struct bezier *bez, VGfloat t, struct bezier* left)
45 left->x1 = bez->x1;
46 left->y1 = bez->y1;
48 left->x2 = bez->x1 + t * (bez->x2 - bez->x1);
49 left->y2 = bez->y1 + t * (bez->y2 - bez->y1);
51 left->x3 = bez->x2 + t * (bez->x3 - bez->x2);
52 left->y3 = bez->y2 + t * (bez->y3 - bez->y2);
54 bez->x3 = bez->x3 + t * (bez->x4 - bez->x3);
55 bez->y3 = bez->y3 + t * (bez->y4 - bez->y3);
57 bez->x2 = left->x3 + t * (bez->x3 - left->x3);
58 bez->y2 = left->y3 + t * (bez->y3 - left->y3);
63 left->x4 = bez->x1 = left->x3 + t * (bez->x2 - left->x3);
64 left->y4 = bez->y1 = left->y3 + t * (bez->y2 - left->y3);
67 static INLINE void split(struct bezier *bez,
71 double c = (bez->x2 + bez->x3) * 0.5;
72 first_half->x2 = (bez->x1 + bez->x2) * 0.5;
73 second_half->x3 = (bez->x3 + bez->x4) * 0.5;
74 first_half->x1 = bez->x1;
75 second_half->x4 = bez->x4;
81 c = (bez->y2 + bez->y3) / 2;
82 first_half->y2 = (bez->y1 + bez->y2) * 0.5;
83 second_half->y3 = (bez->y3 + bez->y4) * 0.5;
84 first_half->y1 = bez->y1;
85 second_half->y4 = bez->y4;
92 struct polygon * bezier_to_polygon(struct bezier *bez)
95 polygon_vertex_append(poly, bez->x1, bez->y1);
96 bezier_add_to_polygon(bez, poly);
100 void bezier_add_to_polygon(const struct bezier *bez,
106 beziers[0] = *bez;
134 static void add_if_close(struct bezier *bez, VGfloat *length, VGfloat error)
136 struct bezier left, right; /* bez poly splits */
140 len = len + line_length(bez->x1, bez->y1, bez->x2, bez->y2);
141 len = len + line_length(bez->x2, bez->y2, bez->x3, bez->y3);
142 len = len + line_length(bez->x3, bez->y3, bez->x4, bez->y4);
144 chord = line_length(bez->x1, bez->y1, bez->x4, bez->y4);
147 split(bez, &left, &right); /* split in two */
158 float bezier_length(struct bezier *bez, float error)
162 add_if_close(bez, &length, error);
166 void bezier_init(struct bezier *bez,
172 bez->x1 = x1;
173 bez->y1 = y1;
174 bez->x2 = x2;
175 bez->y2 = y2;
176 bez->x3 = x3;
177 bez->y3 = y3;
178 bez->x4 = x4;
179 bez->y4 = y4;
187 static INLINE void bezier_init2v(struct bezier *bez,
193 bez->x1 = pt1[0];
194 bez->y1 = pt1[1];
196 bez->x2 = pt2[0];
197 bez->y2 = pt2[1];
199 bez->x3 = pt3[0];
200 bez->y3 = pt3[1];
202 bez->x4 = pt4[0];
203 bez->y4 = pt4[1];
207 void bezier_transform(struct bezier *bez,
211 matrix_map_point(matrix, bez->x1, bez->y1, &bez->x1, &bez->y1);
212 matrix_map_point(matrix, bez->x2, bez->y2, &bez->x2, &bez->y2);
213 matrix_map_point(matrix, bez->x3, bez->y3, &bez->x3, &bez->y3);
214 matrix_map_point(matrix, bez->x4, bez->y4, &bez->x4, &bez->y4);
217 static INLINE void bezier_point_at(const struct bezier *bez, float t, float *pt)
228 pt[0] = a*bez->x1 + b*bez->x2 + c*bez->x3 + d*bez->x4;
229 pt[1] = a*bez->y1 + b*bez->y2 + c*bez->y3 + d*bez->y4;
232 static INLINE void bezier_normal_at(const struct bezier *bez, float t, float *norm)
239 norm[0] = (bez->y2-bez->y1) * a + (bez->y3-bez->y2) * b + (bez->y4-bez->y3) * c;
240 norm[1] = -(bez->x2-bez->x1) * a - (bez->x3-bez->x2) * b - (bez->x4-bez->x3) * c;
518 int bezier_translate_by_normal(struct bezier *bez,
528 if (bez->x1 == bez->x2 && bez->x1 == bez->x3 && bez->x1 == bez->x4 &&
529 bez->y1 == bez->y2 && bez->y1 == bez->y3 && bez->y1 == bez->y4)
534 beziers[0] = *bez;
580 void bezier_bounds(const struct bezier *bez,
583 float xmin = bez->x1;
584 float xmax = bez->x1;
585 float ymin = bez->y1;
586 float ymax = bez->y1;
588 if (bez->x2 < xmin)
589 xmin = bez->x2;
590 else if (bez->x2 > xmax)
591 xmax = bez->x2;
592 if (bez->x3 < xmin)
593 xmin = bez->x3;
594 else if (bez->x3 > xmax)
595 xmax = bez->x3;
596 if (bez->x4 < xmin)
597 xmin = bez->x4;
598 else if (bez->x4 > xmax)
599 xmax = bez->x4;
601 if (bez->y2 < ymin)
602 ymin = bez->y2;
603 else if (bez->y2 > ymax)
604 ymax = bez->y2;
605 if (bez->y3 < ymin)
606 ymin = bez->y3;
607 else if (bez->y3 > ymax)
608 ymax = bez->y3;
609 if (bez->y4 < ymin)
610 ymin = bez->y4;
611 else if (bez->y4 > ymax)
612 ymax = bez->y4;
620 void bezier_start_tangent(const struct bezier *bez,
623 tangent[0] = bez->x1;
624 tangent[1] = bez->y1;
625 tangent[2] = bez->x2;
626 tangent[3] = bez->y2;
629 tangent[0] = bez->x1;
630 tangent[1] = bez->y1;
631 tangent[2] = bez->x3;
632 tangent[3] = bez->y3;
635 tangent[0] = bez->x1;
636 tangent[1] = bez->y1;
637 tangent[2] = bez->x4;
638 tangent[3] = bez->y4;
643 static INLINE VGfloat bezier_t_at_length(struct bezier *bez,
647 VGfloat len = bezier_length(bez, error);
659 struct bezier right = *bez;
677 void bezier_point_at_length(struct bezier *bez,
683 VGfloat t = bezier_t_at_length(bez, length, 0.000001);
684 bezier_point_at(bez, t, point);
685 bezier_normal_at(bez, t, normal);
689 void bezier_point_at_t(struct bezier *bez, float t,
692 bezier_point_at(bez, t, point);
693 bezier_normal_at(bez, t, normal);
697 void bezier_exact_bounds(const struct bezier *bez,
701 polygon_vertex_append(poly, bez->x1, bez->y1);
702 bezier_add_to_polygon(bez, poly);