예제 #1
0
    def updateNeighbors(self):
        self.nbrs = list()
        midPt = pv.vPrd(pv.vSum(self.start, self.end), 0.5)
        ln = pv.unitV(pv.vDiff(self.end, self.start))
        step = pv.vRotate(ln, math.pi / 2)
        pt1 = pv.vSum(midPt, step)
        pt2 = pv.vDiff(midPt, step)

        test = False
        for label in self.owner.c:
            if self.owner.c[label].hasPoint(
                    pt1) or self.owner.c[label].hasPoint(pt2):
                self.nbrs.append(self.owner.c[label])
                test = True
    def __init__(self, regSize, rType, regPosition, toRender = True):
        self.size = regSize
        self.type = rType
        #this pos attribute is the postition of the top left corner
        self.pos = regPosition
        self.center = pv.vSum(self.pos, [self.size/2, self.size/2])
        #this is the index in the 3x3 matrix among it's siblings
        #for example the middle one is [2,2]
        self.posMat = None
        #the id of the graphic if and when created
        self.graphic = None

        #this contains the scores of this region w.r.t each regiontype with
        #the name of the regiontype as the key of the dictionary
        self.score = dict()
        global regType
        for typeName in regType:
            self.score[typeName] = 0

        #this represents the scale of the region
        #0 is the biggest region and the smaller regions have increasing values
        self.scale = 0

        self.child = [] #this is a list of children of this region
        self.parent = None

        if toRender:
            self.render()
    def __init__(self, verticesList):
        self.vertex = verticesList
        self.graphic = None

        vertSum = [0,0]
        for vert in self.vertex:
            vertSum = pv.vSum(vertSum, vert)

        self.center = pv.vPrd(vertSum, 1/len(self.vertex))

        fences.append(self)
    def relPosOf(self, pt):
        center = pv.vSum(self.pos, [self.size/2, self.size/2])

        angle = pv.lineAngle(center[0], center[1], pt[0], pt[1])

        deg45 = math.pi/4

        if deg45 >= angle or angle > 7*deg45:
            return 0
        
        elif deg45 < angle <= 3*deg45:
            return 1
        
        elif 3*deg45 < angle <= 5*deg45:
            return 2
        
        elif 5* deg45 < angle <= 7*deg45:
            return 3
    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
 def minDistFromLine(self, lineObj):
     center = pv.vSum(self.pos, [self.size/2, self.size/2])
     return lineObj.minDistFrom(center)