From: Stuart Buchanan <stuart_d_buchanan@yahoo.co.uk>
Date: Fri, 21 Nov 2014 22:14:03 +0000 (+0000)
Subject: Fix two bugs in random object placement
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=958ae9bdf0c1c71280b5dfeeacb0bd0b73e9e791;p=simgear.git

Fix two bugs in random object placement
---

diff --git a/simgear/scene/tgdb/obj.cxx b/simgear/scene/tgdb/obj.cxx
index b8e02f51..097de74c 100644
--- a/simgear/scene/tgdb/obj.cxx
+++ b/simgear/scene/tgdb/obj.cxx
@@ -628,6 +628,8 @@ public:
 
               // place an object each unit of area
               while ( n > 1.0 ) {
+            	n -= 1.0;
+
                 float a = mt_rand(&seed);
                 float b = mt_rand(&seed);
                 if ( a + b > 1 ) {
@@ -650,7 +652,6 @@ public:
                 float edge_dist = *std::min_element(edges, edges + 3);
 
                 if (edge_dist < spacing) {
-                  n -= 1.0;
                   continue;
                 }
 
@@ -665,7 +666,6 @@ public:
 
                   if (mt_rand(&seed) > img->getColor(x, y).b()) {
                     // Failed object mask check
-                    n -= 1.0;
                     continue;
                   }
 
@@ -680,7 +680,7 @@ public:
                   float min_dist2 = (l->second + object->get_spacing_m()) *
                                     (l->second + object->get_spacing_m());
 
-                  if (distSqr(l->first, randomPoint) > min_dist2) {
+                  if (distSqr(l->first, randomPoint) < min_dist2) {
                     close = true;
                     continue;
                   }