예제 #1
0
        def splitWall():
            if intPt is None:
                return 0
            # print(w1, w2, intPt)
            dist = min(pv.mod(pv.vDiff(w1.start, intPt)),
                       pv.mod(pv.vDiff(w1.end, intPt)))
            if dist < 0.1:
                return 0

            split1 = wall(w1.start, intPt, owner=self)
            split2 = wall(intPt, w1.end, owner=self)
            # print('added 2 walls')
            return 1
    def scoreWith(self, anotherReg, stochasticity):
        scDiff = self.scaleDiff(anotherReg)
        if scDiff >= 0 and (not anotherReg is self.parent):
            scoreVal = anotherReg.size #making the score proportional to the size of the region
            d = pv.mod(pv.vDiff(self.center, anotherReg.center))
            if d == 0:d = 1 #this is just to prevent division by zero

            scoreVal /= math.pow(d, scDiff + 1)
            #scoreVal *= anotherReg.type.agglomerationFactor
            scoreVal *= (1+(random.uniform(-1,1)*stochasticity))

            for typeName in regType:
                self.score[typeName] += regType[typeName].rel(anotherReg.type)*scoreVal
    def intercept(self, lineObj):
        #corners of the sqaure region
        sq = list()
        sq.append([self.pos[0]+self.size, self.pos[1]])
        sq.append([self.pos[0]+self.size, self.pos[1]+self.size])
        sq.append([self.pos[0], self.pos[1]+self.size])
        sq.append(self.pos)
        
        iSum = 0 #this is the sum of intercepts that we will continue to increment

        i = 0
        while i < len(lineObj.point)-1:
            #print(i, iSum)
            p1 = lineObj.point[i]
            p2 = lineObj.point[i+1]

            if self.hasPoint(p1) and self.hasPoint(p2):
                iSum += pv.mod(pv.vDiff(p2,p1))
            else:
                s = 0
                intPt = list()
                while s < len(sq) and len(intPt) <= 2:
                    s1 = sq[s]
                    s2 = sq[(s+1)%4]

                    iPt = pv.intersectionPt(p1, p2, s1, s2)
                    if not iPt is None:
                        intPt.append(iPt)

                    s += 1

                if len(intPt) >= 2:
                    iSum += pv.mod(pv.vDiff(intPt[0], intPt[1]))

            i += 1
        
        return iSum
    def minDistFrom(self, pos):
        i = 0
        minDist = math.inf
        while i < len(self.point)-1:
            a = self.point[i]
            b = self.point[i+1]

            dt = pv.lineDist(a,b,pos)
            pt = pv.vSum(pos, dt)

            if pv.dot(pv.vDiff(pt,a),pv.vDiff(pt,b)) <= 0:
                distance = pv.mod(dt)
            else:
                dtA = pv.mod(pv.vDiff(pos,a))
                dtB = pv.mod(pv.vDiff(pos,b))

                distance = min(dtA, dtB)

            if distance < minDist:
                minDist = distance

            i += 1

        return minDist
예제 #5
0
    def render(self, img):
        draw = ImageDraw.Draw(img)
        # offset the door from ends of wall to avoid awkward joints
        offset = math.ceil((self.size / 2) + 1)
        offsetRatio = offset / (pv.mod(pv.vDiff(self.wall.end,
                                                self.wall.start)))
        # these are the start and end points of the wall after accounting for the offset
        newStart = pv.linEval(self.wall.start, self.wall.end, offsetRatio)
        newEnd = pv.linEval(self.wall.end, self.wall.start, offsetRatio)
        # now evaluating door position between these new start and new end points
        xypos = pv.linEval(newStart, newEnd, self.pos)
        # draw the door
        hSize = self.size / 2
        coord = [
            xypos[0] - hSize, xypos[1] - hSize, xypos[0] + hSize,
            xypos[1] + hSize
        ]

        draw.rectangle(coord, self.color)

        del draw
        return img
예제 #6
0
 def length(self):
     return pv.mod(pv.vDiff(self.start, self.end))