X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fxo-shapes.c;h=3b669e53fb5afb985a2ed74fb524dfff045eddc7;hb=0c8dfdb035698cc0112a5e7b776709aca11c2f16;hp=01f9073d24c9430f5902bfc810e963b78a484e63;hpb=e648cece76b671b5b0e165acc6d14178e8de1000;p=xournal.git
diff --git a/src/xo-shapes.c b/src/xo-shapes.c
index 01f9073..3b669e5 100644
--- a/src/xo-shapes.c
+++ b/src/xo-shapes.c
@@ -1,3 +1,18 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
#ifdef HAVE_CONFIG_H
# include
#endif
@@ -69,28 +84,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);
}