Beispiel #1
0
 def mindistance(self, point):
     distlist = []
     for vertex in self.vertices:
         distlist.append(Point.dist(point, vertex))
     if distlist:
         return min(distlist)
     else:
         return None
Beispiel #2
0
 def closestvertex(self, point):
     distlist = []
     for vertex in self.vertices:
         distlist.append(Point.dist(point, vertex))
     if distlist:
         index = distlist.index(min(distlist))
         return self.vertices[index]
     else:
         return None
Beispiel #3
0
 def borderPaint(self):
     q = QPainter()
     for vertex in self.vertices:
         q.begin(self)
         brush = QBrush(Qt.BDiagPattern)
         pen = QPen(Qt.black, 1, Qt.DashLine)
         if self.pos and Point.dist(Point(self.pos.x(), self.pos.y()), vertex) <= 100:
             q.setBrush(brush)
         q.setPen(pen)
         q.drawEllipse(vertex.myQPoint(), 100, 100)
         q.end()
Beispiel #4
0
 def finishTheRoad(self, v):
     for point in self.pointList:
         d = Point.dist(self.previous(point), point)
         if d == 0.0:
             self.pointList.remove(point)
     points = self.pointList.copy()
     road = self.newroad
     road.found(points, v)
     self.roads.append(road)
     self.pointList.clear()
     self.signal.switch.emit()
     self.pos = None
Beispiel #5
0
def sidecurve(points, l):
    points1 = []
    points2 = []
    n = 10
    for i in range(n, len(points) - n):
        if onLine(points[i - n], points[i], points[i + n]) == False:
            p = center(points[i - n], points[i], points[i + n])
            p1 = Point(round(points[i].x() + (p.x() - points[i].x())*l/Point.dist(points[i], p)), round(points[i].y() + (p.y() - points[i].y())*l/Point.dist(points[i], p)))
            p2 = Point(round(points[i].x() - (p.x() - points[i].x()) * l / Point.dist(points[i], p)),
                   round(points[i].y() - (p.y() - points[i].y()) * l / Point.dist(points[i], p)))
            if lower(points[i-n], points[i], p1):
                points1.append(p1)
                points2.append(p2)
            else:
                points1.append(p2)
                points2.append(p1)
        else:
            n1 = points[i].y() - points[i - n].y()
            n2 = points[i - n].x() - points[i].x()
            #print(n1, n2)
            mod = (n1 ** 2 + n2 ** 2) ** 0.5
            p1 = Point(round(points[i].x() - n1 * l / mod), round(points[i].y() - n2 * l / mod))
            p2 = Point(round(points[i].x() + n1 * l / mod), round(points[i].y() + n2 * l / mod))
            #print(p1, p2)
            #if lower(points[i - 2], points[i], points1[-1]) == lower(points[i - 2], points[i], p1):
            if lower(points[i - n], points[i], p1):
                points1.append(p1)
                points2.append(p2)
            else:
                points1.append(p2)
                points2.append(p1)
            #else:
             #       points1.append(p2)
             #       points2.append(p1)

    return [points1, points2]
Beispiel #6
0
    def moveAndDraw(self, event):
        m = 1
        point = Point(event.x(), event.y())
        distance_from_previous_point = Point.dist(point, self.basepoint)
        self.pos = event.pos()
        if distance_from_previous_point >= m:
            if distance_from_previous_point >= 2*m:
                cos = (point.x() - self.basepoint.x()) / distance_from_previous_point
                sin = (point.y() - self.basepoint.y()) / distance_from_previous_point
                point = Point(self.basepoint.x() + round(cos), self.basepoint.y() + round(sin))
                for i in range(m, math.ceil(distance_from_previous_point), m):
                    self.pointList.append(point)
                    point = Point(self.basepoint.x() + round(cos*i), self.basepoint.y() + round(sin*i))
            self.pointList.append(point)
            self.basepoint = point

        if self.mindistance(point) <= 20 and len(self.pointList) >= 50:
            v = self.closestvertex(point)
            self.pointList.append(Point(v.x(), v.y()))
            self.finishTheRoad(v)