X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fxo-shapes.c;h=5631c0d87300720e2654e1657076a4a725545bcb;hb=b471a5e1ffc9ad87400f079679fdf261875d513e;hp=0efdf69f0fb404c1e8e8025e1f430c3e83a30928;hpb=dcbb0ab8521a5e166f257d86884407eb98ef63f0;p=xournal.git diff --git a/src/xo-shapes.c b/src/xo-shapes.c index 0efdf69..5631c0d 100644 --- a/src/xo-shapes.c +++ b/src/xo-shapes.c @@ -69,28 +69,34 @@ inline double center_y(struct Inertia s) inline double I_xx(struct Inertia s) { + if (s.mass <= 0.) return 0.; return (s.sxx - s.sx*s.sx/s.mass)/s.mass; } inline double I_xy(struct Inertia s) { + if (s.mass <= 0.) return 0.; return (s.sxy - s.sx*s.sy/s.mass)/s.mass; } inline double I_yy(struct Inertia s) { + if (s.mass <= 0.) return 0.; return (s.syy - s.sy*s.sy/s.mass)/s.mass; } inline double I_rad(struct Inertia s) { - return sqrt(I_xx(s)+I_yy(s)); + double ixx = I_xx(s), iyy = I_yy(s); + if (ixx+iyy <= 0.) return 0.; + return sqrt(ixx+iyy); } inline double I_det(struct Inertia s) { - if (s.mass == 0.) return 0.; double ixx = I_xx(s), iyy = I_yy(s), ixy = I_xy(s); + if (s.mass <= 0.) return 0.; + if (ixx+iyy <= 0.) return 0.; return 4*(ixx*iyy-ixy*ixy)/(ixx+iyy)/(ixx+iyy); } @@ -408,7 +414,7 @@ gboolean try_arrow(void) while (alpha[i]<-M_PI/2) { alpha[i]+=M_PI; rs[i].reversed = !rs[i].reversed; } while (alpha[i]>M_PI/2) { alpha[i]-=M_PI; rs[i].reversed = !rs[i].reversed; } #ifdef RECOGNIZER_DEBUG - printf("arrow: alpha[%d] = %.1f degrees\n", i, alpha[i]*180/M_PI); + printf("DEBUG: arrow: alpha[%d] = %.1f degrees\n", i, alpha[i]*180/M_PI); #endif if (fabs(alpha[i])ARROW_ANGLE_MAX) return FALSE; } @@ -424,20 +430,20 @@ gboolean try_arrow(void) dist = hypot(pt[0]-(rs[j].reversed?rs[j].x1:rs[j].x2), pt[1]-(rs[j].reversed?rs[j].y1:rs[j].y2)); #ifdef RECOGNIZER_DEBUG - printf("linear tolerance: tip[%d] = %.2f\n", j, dist/rs[j].radius); + printf("DEBUG: linear tolerance: tip[%d] = %.2f\n", j, dist/rs[j].radius); #endif if (dist>ARROW_TIP_LINEAR_TOLERANCE*rs[j].radius) return FALSE; } dist = (pt[0]-x2)*sin(angle)-(pt[1]-y2)*cos(angle); dist /= rs[1].radius + rs[2].radius; #ifdef RECOGNIZER_DEBUG - printf("sideways gap tolerance = %.2f\n", dist); + printf("DEBUG: sideways gap tolerance = %.2f\n", dist); #endif if (fabs(dist)>ARROW_SIDEWAYS_GAP_TOLERANCE) return FALSE; dist = (pt[0]-x2)*cos(angle)+(pt[1]-y2)*sin(angle); dist /= rs[1].radius + rs[2].radius; #ifdef RECOGNIZER_DEBUG - printf("main linear gap = %.2f\n", dist); + printf("DEBUG: main linear gap = %.2f\n", dist); #endif if (distARROW_MAIN_LINEAR_GAP_MAX) return FALSE; @@ -534,7 +540,7 @@ void recognize_patterns(void) it = undo->item; calc_inertia(it->path->coords, 0, it->path->num_points-1, &s); #ifdef RECOGNIZER_DEBUG - printf("Mass=%.0f, Center=(%.1f,%.1f), I=(%.0f,%.0f, %.0f), " + printf("DEBUG: Mass=%.0f, Center=(%.1f,%.1f), I=(%.0f,%.0f, %.0f), " "Rad=%.2f, Det=%.4f \n", s.mass, center_x(s), center_y(s), I_xx(s), I_yy(s), I_xy(s), I_rad(s), I_det(s)); #endif @@ -544,9 +550,9 @@ void recognize_patterns(void) if (n>0) { optimize_polygonal(it->path->coords, n, brk, ss); #ifdef RECOGNIZER_DEBUG - printf("Polygon, %d edges: ", n); + printf("DEBUG: Polygon, %d edges: ", n); for (i=0; iCIRCLE_MIN_DET) { score = score_circle(it->path->coords, 0, it->path->num_points-1, &s); #ifdef RECOGNIZER_DEBUG - printf("Circle score: %.2f\n", score); + printf("DEBUG: Circle score: %.2f\n", score); #endif if (score < CIRCLE_MAX_SCORE) { make_circle_shape(center_x(s), center_y(s), I_rad(s));