chiark / gitweb /
Fix the push-free for convex polygons. Fix the objectOrderFinder to handle the case...
authordaid <daid303@gmail.com>
Fri, 29 Nov 2013 09:51:30 +0000 (10:51 +0100)
committerdaid <daid303@gmail.com>
Fri, 29 Nov 2013 09:51:30 +0000 (10:51 +0100)
Cura/util/objectScene.py
Cura/util/polygon.py

index 947bc95b474220e1c3211964b8373e5a15756308..e118a3b3613f4b84a932e520179506c4fc0e9da7 100644 (file)
@@ -36,6 +36,12 @@ class _objectOrderFinder(object):
                        for b in initialList:
                                self._hitMap[a][b] = self._checkHit(a, b)
 
+               #Check if we have 2 files that overlap so that they can never be printed one at a time.
+               for a in initialList:
+                       if self._hitMap[a][b] and self._hitMap[b][a]:
+                               self.order = None
+                               return
+
                initialList.sort(self._objIdxCmp)
 
                n = 0
@@ -155,7 +161,6 @@ class Scene(object):
                self.pushFree()
 
        def pushFree(self):
-               return
                n = 1000
                while self._pushFree():
                        n -= 1
@@ -193,25 +198,13 @@ class Scene(object):
        def _pushFree(self):
                for a in self._objectList:
                        for b in self._objectList:
-                               if not self._checkHit(a, b):
+                               if a == b:
+                                       continue
+                               v = polygon.polygonCollisionPushVector(a._boundaryHull + a.getPosition(), b._boundaryHull + b.getPosition())
+                               if type(v) is bool:
                                        continue
-                               posDiff = a.getPosition() - b.getPosition()
-                               if posDiff[0] == 0.0 and posDiff[1] == 0.0:
-                                       posDiff[1] = 1.0
-                               if abs(posDiff[0]) > abs(posDiff[1]):
-                                       axis = 0
-                               else:
-                                       axis = 1
-                               aPos = a.getPosition()
-                               bPos = b.getPosition()
-                               center = (aPos[axis] + bPos[axis]) / 2
-                               distance = (a.getSize()[axis] + b.getSize()[axis]) / 2 + 0.1 + self._sizeOffsets[axis] + self._headSizeOffsets[axis]
-                               if posDiff[axis] < 0:
-                                       distance = -distance
-                               aPos[axis] = center + distance / 2
-                               bPos[axis] = center - distance / 2
-                               a.setPosition(aPos)
-                               b.setPosition(bPos)
+                               a.setPosition(a.getPosition() + v / 2.0)
+                               b.setPosition(b.getPosition() - v / 2.0)
                                return True
                return False
 
index 746fb0ed7e4d88a04412b493047ec794553f3325..8da33639bf69da041529efa23525ea80fb0d7c40 100644 (file)
@@ -82,3 +82,42 @@ def polygonCollision(polyA, polyB):
                if aMax < bMin:
                        return False
        return True
+
+def polygonCollisionPushVector(polyA, polyB):
+       retSize = 10000000.0
+       ret = False
+       for n in xrange(0, len(polyA)):
+               p0 = polyA[n-1]
+               p1 = polyA[n]
+               normal = (p1 - p0)[::-1]
+               normal[1] = -normal[1]
+               normal /= numpy.linalg.norm(normal)
+               aMin, aMax = projectPoly(polyA, normal)
+               bMin, bMax = projectPoly(polyB, normal)
+               if aMin > bMax:
+                       return False
+               if bMin > aMax:
+                       return False
+               size = min(bMax, bMax) - max(aMin, bMin)
+               if size < retSize:
+                       ret = normal * (size + 0.1)
+                       retSize = size
+       for n in xrange(0, len(polyB)):
+               p0 = polyB[n-1]
+               p1 = polyB[n]
+               normal = (p1 - p0)[::-1]
+               normal[1] = -normal[1]
+               normal /= numpy.linalg.norm(normal)
+               aMin, aMax = projectPoly(polyA, normal)
+               bMin, bMax = projectPoly(polyB, normal)
+               if aMin > bMax:
+                       return False
+               if aMax < bMin:
+                       return False
+               size = min(bMax, bMax) - max(aMin, bMin)
+               if size < retSize:
+                       ret = normal * -(size + 0.1)
+                       retSize = size
+       #ret = ret[::-1]
+       #ret[1] = -ret[1]
+       return ret