X-Git-Url: https://git.donarmstrong.com/?p=xournal.git;a=blobdiff_plain;f=src%2Fxo-shapes.c;h=5631c0d87300720e2654e1657076a4a725545bcb;hp=01f9073d24c9430f5902bfc810e963b78a484e63;hb=b471a5e1ffc9ad87400f079679fdf261875d513e;hpb=4d39b1b77c637b56b4f094e39328b3394cefa4dc diff --git a/src/xo-shapes.c b/src/xo-shapes.c index 01f9073..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); }