]> git.donarmstrong.com Git - xournal.git/blobdiff - src/xo-shapes.c
Add "GPL v2 or later" headers to the source files
[xournal.git] / src / xo-shapes.c
index 01f9073d24c9430f5902bfc810e963b78a484e63..3b669e53fb5afb985a2ed74fb524dfff045eddc7 100644 (file)
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
 #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);
 }