def isAddedPointOnPathFree(path, pixelTable, point, pointIndex, width):
    'Determine if the point added to a path is intersecting the pixel table or the path.'
    if pointIndex > 0 and pointIndex < len(path):
        if isSharpCorner((path[pointIndex - 1]), point, (path[pointIndex])):
            return False
    pointIndexMinusOne = pointIndex - 1
    if pointIndexMinusOne >= 0:
        maskTable = {}
        begin = path[ pointIndexMinusOne ]
        if pointIndex < len(path):
            end = path[pointIndex]
            euclidean.addValueSegmentToPixelTable(begin, end, maskTable, None, width)
        segmentTable = {}
        euclidean.addSegmentToPixelTable(point, begin, segmentTable, 0.0, 2.0, width)
        if euclidean.isPixelTableIntersecting(pixelTable, segmentTable, maskTable):
            return False
        if isAddedPointOnPathIntersectingPath(begin, path, point, pointIndexMinusOne):
            return False
    if pointIndex < len(path):
        maskTable = {}
        begin = path[pointIndex]
        if pointIndexMinusOne >= 0:
            end = path[ pointIndexMinusOne ]
            euclidean.addValueSegmentToPixelTable(begin, end, maskTable, None, width)
        segmentTable = {}
        euclidean.addSegmentToPixelTable(point, begin, segmentTable, 0.0, 2.0, width)
        if euclidean.isPixelTableIntersecting(pixelTable, segmentTable, maskTable):
            return False
        if isAddedPointOnPathIntersectingPath(begin, path, point, pointIndex):
            return False
    return True
def isSidePointAdded(pixelTable, closestPath, closestPathIndex, closestPointIndex, layerExtrusionWidth, removedEndpointPoint, width):
    'Add side point along with the closest removed endpoint to the path, with minimal twisting.'
    if closestPointIndex <= 0 or closestPointIndex >= len(closestPath):
        return False
    pointBegin = closestPath[ closestPointIndex - 1 ]
    pointEnd = closestPath[ closestPointIndex ]
    removedEndpointPoint = removedEndpointPoint
    closest = pointBegin
    farthest = pointEnd
    removedMinusClosest = removedEndpointPoint - pointBegin
    removedMinusClosestLength = abs(removedMinusClosest)
    if removedMinusClosestLength <= 0.0:
        return False
    removedMinusOther = removedEndpointPoint - pointEnd
    removedMinusOtherLength = abs(removedMinusOther)
    if removedMinusOtherLength <= 0.0:
        return False
    insertPointAfter = None
    insertPointBefore = None
    if removedMinusOtherLength < removedMinusClosestLength:
        closest = pointEnd
        farthest = pointBegin
        removedMinusClosest = removedMinusOther
        removedMinusClosestLength = removedMinusOtherLength
        insertPointBefore = removedEndpointPoint
    else:
        insertPointAfter = removedEndpointPoint
    removedMinusClosestNormalized = removedMinusClosest / removedMinusClosestLength
    perpendicular = removedMinusClosestNormalized * complex(0.0, layerExtrusionWidth)
    sidePoint = removedEndpointPoint + perpendicular
    #extra check in case the line to the side point somehow slips by the line to the perpendicular
    sidePointOther = removedEndpointPoint - perpendicular
    if abs(sidePoint - farthest) > abs(sidePointOther - farthest):
        perpendicular = -perpendicular
        sidePoint = sidePointOther
    maskTable = {}
    closestSegmentTable = {}
    toPerpendicularTable = {}
    euclidean.addValueSegmentToPixelTable(pointBegin, pointEnd, maskTable, None, width)
    euclidean.addValueSegmentToPixelTable(closest, removedEndpointPoint, closestSegmentTable, None, width)
    euclidean.addValueSegmentToPixelTable(sidePoint, farthest, toPerpendicularTable, None, width)
    if euclidean.isPixelTableIntersecting(pixelTable, toPerpendicularTable, maskTable) or euclidean.isPixelTableIntersecting(closestSegmentTable, toPerpendicularTable, maskTable):
        sidePoint = removedEndpointPoint - perpendicular
        toPerpendicularTable = {}
        euclidean.addValueSegmentToPixelTable(sidePoint, farthest, toPerpendicularTable, None, width)
        if euclidean.isPixelTableIntersecting(pixelTable, toPerpendicularTable, maskTable) or euclidean.isPixelTableIntersecting(closestSegmentTable, toPerpendicularTable, maskTable):
            return False
    if insertPointBefore != None:
        addPointOnPathIfFree(closestPath, closestPathIndex, pixelTable, insertPointBefore, closestPointIndex, width)
    addPointOnPathIfFree(closestPath, closestPathIndex, pixelTable, sidePoint, closestPointIndex, width)
    if insertPointAfter != None:
        addPointOnPathIfFree(closestPath, closestPathIndex, pixelTable, insertPointAfter, closestPointIndex, width)
    return True
Exemple #3
0
	def getConnectionIsCloseWithoutOverlap( self, location, path ):
		"Determine if the connection is close enough and does not overlap another thread."
		if len( path ) < 1:
			return False
		locationComplex = location.dropAxis( 2 )
		segment = locationComplex - path[ - 1 ]
		segmentLength = abs( segment )
		if segmentLength <= 0.0:
			return True
		segment /= segmentLength
		distance = self.connectingStepLength
		segmentEndLength = segmentLength - self.connectingStepLength
		while distance < segmentEndLength:
			alongPoint = distance * segment + path[ - 1 ]
			if not euclidean.isPointInsideLoops( self.boundaryLoops, alongPoint ):
				return False
			distance += self.connectingStepLength
#		removedLayerPixelTable = self.layerPixelTable.copy()
#		if self.oldLocation in self.maskPixelTableTable:
#			euclidean.removePixelTableFromPixelTable( self.maskPixelTableTable[ self.oldLocation ], removedLayerPixelTable )
#		euclidean.addPathToPixelTable( path[ : - 2 ], removedLayerPixelTable, None, self.layerPixelWidth )
		segmentTable = {}
		euclidean.addSegmentToPixelTable( path[ - 1 ], locationComplex, segmentTable, 2.0, 2.0, self.layerPixelWidth )
#		euclidean.addValueSegmentToPixelTable( path[ - 1 ], locationComplex, segmentTable, None, self.layerPixelWidth )
#		euclidean.addValueSegmentToPixelTable( path[ - 1 ], locationComplex, segmentTable, None, self.layerPixelWidth )
#		maskPixelTable = {}
#		if location in self.maskPixelTableTable:
#			maskPixelTable = self.maskPixelTableTable[ location ]
		if euclidean.isPixelTableIntersecting( self.layerPixelTable, segmentTable, {} ):
#		if euclidean.isPixelTableIntersecting( removedLayerPixelTable, segmentTable, {} ):
			return False
		euclidean.addValueSegmentToPixelTable( path[ - 1 ], locationComplex, self.layerPixelTable, None, self.layerPixelWidth )
#		euclidean.addPixelTableToPixelTable( segmentTable, self.layerPixelTable )
		return True
def isAddedPointOnPathFree(path, pixelTable, point, pointIndex, width):
    'Determine if the point added to a path is intersecting the pixel table or the path.'
    if pointIndex > 0 and pointIndex < len(path):
        if isSharpCorner((path[pointIndex - 1]), point, (path[pointIndex])):
            return False
    pointIndexMinusOne = pointIndex - 1
    if pointIndexMinusOne >= 0:
        maskTable = {}
        begin = path[pointIndexMinusOne]
        if pointIndex < len(path):
            end = path[pointIndex]
            euclidean.addValueSegmentToPixelTable(begin, end, maskTable, None,
                                                  width)
        segmentTable = {}
        euclidean.addSegmentToPixelTable(point, begin, segmentTable, 0.0, 2.0,
                                         width)
        if euclidean.isPixelTableIntersecting(pixelTable, segmentTable,
                                              maskTable):
            return False
        if isAddedPointOnPathIntersectingPath(begin, path, point,
                                              pointIndexMinusOne):
            return False
    if pointIndex < len(path):
        maskTable = {}
        begin = path[pointIndex]
        if pointIndexMinusOne >= 0:
            end = path[pointIndexMinusOne]
            euclidean.addValueSegmentToPixelTable(begin, end, maskTable, None,
                                                  width)
        segmentTable = {}
        euclidean.addSegmentToPixelTable(point, begin, segmentTable, 0.0, 2.0,
                                         width)
        if euclidean.isPixelTableIntersecting(pixelTable, segmentTable,
                                              maskTable):
            return False
        if isAddedPointOnPathIntersectingPath(begin, path, point, pointIndex):
            return False
    return True
Exemple #5
0
	def getConnectionIsCloseWithoutOverlap( self, location, path ):
		"Determine if the connection is close enough and does not overlap another thread."
		if len(path) < 1:
			return False
		locationComplex = location.dropAxis()
		segment = locationComplex - path[-1]
		segmentLength = abs(segment)
		if segmentLength <= 0.0:
			return True
		if segmentLength > self.maximumConnectionDistance:
			return False
		segmentTable = {}
		euclidean.addSegmentToPixelTable( path[-1], locationComplex, segmentTable, 2.0, 2.0, self.layerPixelWidth )
		if euclidean.isPixelTableIntersecting( self.layerPixelTable, segmentTable, {} ):
			return False
		euclidean.addValueSegmentToPixelTable( path[-1], locationComplex, self.layerPixelTable, None, self.layerPixelWidth )
		return True
Exemple #6
0
	def getConnectionIsCloseWithoutOverlap( self, location, path ):
		"Determine if the connection is close enough and does not overlap another thread."
		if len(path) < 1:
			return False
		locationComplex = location.dropAxis()
		segment = locationComplex - path[-1]
		segmentLength = abs(segment)
		if segmentLength <= 0.0:
			return True
		if segmentLength > self.maximumConnectionDistance:
			return False
		segmentTable = {}
		euclidean.addSegmentToPixelTable( path[-1], locationComplex, segmentTable, 2.0, 2.0, self.layerPixelWidth )
		if euclidean.isPixelTableIntersecting( self.layerPixelTable, segmentTable, {} ):
			return False
		euclidean.addValueSegmentToPixelTable( path[-1], locationComplex, self.layerPixelTable, None, self.layerPixelWidth )
		return True
Exemple #7
0
    def getConnectionIsCloseWithoutOverlap(self, location, path):
        "Determine if the connection is close enough and does not overlap another thread."
        if len(path) < 1:
            return False
        locationComplex = location.dropAxis(2)
        segment = locationComplex - path[-1]
        segmentLength = abs(segment)
        if segmentLength <= 0.0:
            return True
        if segmentLength > self.maximumConnectionDistance:
            return False
        segment /= segmentLength
        distance = self.connectingStepLength
        segmentEndLength = segmentLength - self.connectingStepLength
        while distance < segmentEndLength:
            alongPoint = distance * segment + path[-1]
            if not euclidean.getIsInFilledRegion(self.boundaryLoops,
                                                 alongPoint):
                return False
            distance += self.connectingStepLength


#		removedLayerPixelTable = self.layerPixelTable.copy()
#		if self.oldLocation in self.maskPixelTableTable:
#			euclidean.removePixelTableFromPixelTable( self.maskPixelTableTable[ self.oldLocation ], removedLayerPixelTable )
#		euclidean.addPathToPixelTable( path[ : - 2 ], removedLayerPixelTable, None, self.layerPixelWidth )
        segmentTable = {}
        euclidean.addSegmentToPixelTable(path[-1], locationComplex,
                                         segmentTable, 2.0, 2.0,
                                         self.layerPixelWidth)
        #		euclidean.addValueSegmentToPixelTable( path[-1], locationComplex, segmentTable, None, self.layerPixelWidth )
        #		euclidean.addValueSegmentToPixelTable( path[-1], locationComplex, segmentTable, None, self.layerPixelWidth )
        #		maskPixelTable = {}
        #		if location in self.maskPixelTableTable:
        #			maskPixelTable = self.maskPixelTableTable[ location ]
        if euclidean.isPixelTableIntersecting(self.layerPixelTable,
                                              segmentTable, {}):
            #		if euclidean.isPixelTableIntersecting( removedLayerPixelTable, segmentTable, {} ):
            return False
        euclidean.addValueSegmentToPixelTable(path[-1], locationComplex,
                                              self.layerPixelTable, None,
                                              self.layerPixelWidth)
        #		euclidean.addPixelTableToPixelTable( segmentTable, self.layerPixelTable )
        return True
def isSidePointAdded(pixelTable, closestPath, closestPathIndex,
                     closestPointIndex, layerExtrusionWidth,
                     removedEndpointPoint, width):
    'Add side point along with the closest removed endpoint to the path, with minimal twisting.'
    if closestPointIndex <= 0 or closestPointIndex >= len(closestPath):
        return False
    pointBegin = closestPath[closestPointIndex - 1]
    pointEnd = closestPath[closestPointIndex]
    removedEndpointPoint = removedEndpointPoint
    closest = pointBegin
    farthest = pointEnd
    removedMinusClosest = removedEndpointPoint - pointBegin
    removedMinusClosestLength = abs(removedMinusClosest)
    if removedMinusClosestLength <= 0.0:
        return False
    removedMinusOther = removedEndpointPoint - pointEnd
    removedMinusOtherLength = abs(removedMinusOther)
    if removedMinusOtherLength <= 0.0:
        return False
    insertPointAfter = None
    insertPointBefore = None
    if removedMinusOtherLength < removedMinusClosestLength:
        closest = pointEnd
        farthest = pointBegin
        removedMinusClosest = removedMinusOther
        removedMinusClosestLength = removedMinusOtherLength
        insertPointBefore = removedEndpointPoint
    else:
        insertPointAfter = removedEndpointPoint
    removedMinusClosestNormalized = removedMinusClosest / removedMinusClosestLength
    perpendicular = removedMinusClosestNormalized * complex(
        0.0, layerExtrusionWidth)
    sidePoint = removedEndpointPoint + perpendicular
    #extra check in case the line to the side point somehow slips by the line to the perpendicular
    sidePointOther = removedEndpointPoint - perpendicular
    if abs(sidePoint - farthest) > abs(sidePointOther - farthest):
        perpendicular = -perpendicular
        sidePoint = sidePointOther
    maskTable = {}
    closestSegmentTable = {}
    toPerpendicularTable = {}
    euclidean.addValueSegmentToPixelTable(pointBegin, pointEnd, maskTable,
                                          None, width)
    euclidean.addValueSegmentToPixelTable(closest, removedEndpointPoint,
                                          closestSegmentTable, None, width)
    euclidean.addValueSegmentToPixelTable(sidePoint, farthest,
                                          toPerpendicularTable, None, width)
    if euclidean.isPixelTableIntersecting(
            pixelTable, toPerpendicularTable,
            maskTable) or euclidean.isPixelTableIntersecting(
                closestSegmentTable, toPerpendicularTable, maskTable):
        sidePoint = removedEndpointPoint - perpendicular
        toPerpendicularTable = {}
        euclidean.addValueSegmentToPixelTable(sidePoint, farthest,
                                              toPerpendicularTable, None,
                                              width)
        if euclidean.isPixelTableIntersecting(
                pixelTable, toPerpendicularTable,
                maskTable) or euclidean.isPixelTableIntersecting(
                    closestSegmentTable, toPerpendicularTable, maskTable):
            return False
    if insertPointBefore != None:
        addPointOnPathIfFree(closestPath, closestPathIndex, pixelTable,
                             insertPointBefore, closestPointIndex, width)
    addPointOnPathIfFree(closestPath, closestPathIndex, pixelTable, sidePoint,
                         closestPointIndex, width)
    if insertPointAfter != None:
        addPointOnPathIfFree(closestPath, closestPathIndex, pixelTable,
                             insertPointAfter, closestPointIndex, width)
    return True