32 #include <fors_pattern.h>
34 #include <fors_double.h>
35 #include <fors_utils.h>
48 const fors_point *ref, *min, *max;
76 assure( ref != NULL,
return p, NULL );
77 assure( p1 != NULL,
return p, NULL );
78 assure( p2 != NULL,
return p, NULL );
79 assure( sigma >= 0,
return p, NULL );
85 double dr1 = sqrt(8*sigma*sigma*r1);
86 double dr2 = sqrt(8*sigma*sigma*r2);
89 double t1 = double_atan2(ref->y - p1->y, sqrt(2)*sigma,
90 ref->x - p1->x, sqrt(2)*sigma,
93 double t2 = double_atan2(ref->y - p2->y, sqrt(2)*sigma,
94 ref->x - p2->x, sqrt(2)*sigma,
98 p->ratsq = double_divide(r1, dr1,
102 p->theta = double_subtract(t1, dt1,
109 p->ratsq = double_divide(r2, dr2,
112 p->theta = double_subtract(t2, dt2,
119 while (p->theta < 0 ) p->theta += 2*M_PI;
120 while (p->theta >= 2*M_PI) p->theta -= 2*M_PI;
138 fors_pattern_new_from_points(fors_point_list *points,
142 fors_pattern_list *patterns = fors_pattern_list_new();
143 double tol_sq = tolerance * tolerance;
144 fors_point *ref, *p1, *p2;
146 assure( points != NULL,
return NULL, NULL );
148 for (ref = fors_point_list_first(points);
150 ref = fors_point_list_next(points)) {
152 for (fors_point_list_first_pair(points, &p1, &p2);
154 fors_point_list_next_pair(points, &p1, &p2)) {
160 fors_pattern_list_insert(patterns,
162 ref, p1, p2, sigma));
167 cpl_msg_debug(cpl_func,
168 "Created %d pattern(s)", fors_pattern_list_size(patterns));
186 assure( p != NULL,
return NULL, NULL );
188 d = cpl_malloc(
sizeof(*d));
204 cpl_free(*p); *p = NULL;
217 assure( p != NULL,
return NULL, NULL );
234 assure( p != NULL,
return, NULL );
235 assure( dr2 != NULL,
return, NULL );
236 assure( dtheta != NULL,
return, NULL );
239 *dtheta = p->dtheta / (2*M_PI);
256 assure( p != NULL,
return -1, NULL );
257 assure( q != NULL,
return -1, NULL );
266 (p->ratsq - q->ratsq) * (p->ratsq - q->ratsq) / (1.0 * 1.0) +
267 (dtheta * dtheta) / (M_PI*M_PI);
276 double fors_pattern_dist_per_error(
const fors_pattern *p,
284 fors_pattern_error(p,
291 fors_pattern_error(q,
296 double rr = p_error_r*p_error_r + q_error_r*q_error_r;
297 double tt = p_error_t*p_error_t + q_error_t*q_error_t;
300 (p->ratsq - q->ratsq) * (p->ratsq - q->ratsq) / ((1.0*1.0) * rr) +
301 (dtheta * dtheta) / ((M_PI*M_PI) * tt)
315 cpl_msg_info(cpl_func,
"NULL pattern");
318 cpl_msg_info(cpl_func,
"Rmin^2/Rmax^2 = %f ; theta = %f",
334 assure( p != NULL,
return 0, NULL );
335 assure( q != NULL,
return 0, NULL );
340 return (s2 == 0) ? 0 : s1/s2;
353 assure( p != NULL,
return -1, NULL );
354 assure( q != NULL,
return -1, NULL );
356 double t1 = atan2(p->ref->y - p->max->y,
357 p->ref->x - p->max->x);
358 double t2 = atan2(q->ref->y - q->max->y,
359 q->ref->x - q->max->x);
363 while (t >= 2*M_PI) t -= 2*M_PI;
364 while (t < 0 ) t += 2*M_PI;
372 #define LIST_ELEM fors_pattern
double fors_angle_diff(const double *a1, const double *a2)
Difference between angles.
double fors_point_distsq(const fors_point *p, const fors_point *q)
Metric.