Example #1
0
def getWidenedLoop(loop, loopList, outsetLoop, radius, tinyRadius):
    "Get the widened loop."
    intersectingWithinLoops = getIntersectingWithinLoops(
        loop, loopList, outsetLoop)
    if len(intersectingWithinLoops) < 1:
        return loop
    widdershinsLoops = [loop]
    for intersectingWithinLoop in intersectingWithinLoops:
        reversedLoop = intersectingWithinLoop[:]
        reversedLoop.reverse()
        widdershinsLoops.append(reversedLoop)
    paths = []
    for widdershinsLoopIndex in xrange(len(widdershinsLoops)):
        widdershinsLoop = widdershinsLoops[widdershinsLoopIndex]
        for pointIndex in xrange(len(widdershinsLoop)):
            pointBegin = widdershinsLoop[pointIndex]
            pointEnd = widdershinsLoop[(pointIndex + 1) % len(widdershinsLoop)]
            otherLoops = widdershinsLoops[:
                                          widdershinsLoopIndex] + widdershinsLoops[
                                              widdershinsLoopIndex + 1:]
            segments = getSegmentsFromPoints(otherLoops, pointBegin, pointEnd)
            for segment in segments:
                addToPaths(paths, tinyRadius, segment)
    for endIndex in xrange(len(paths) - 1, 0, -1):
        connectEndPath(endIndex, paths, tinyRadius)
    widenedLoop = []
    for path in paths:
        widenedLoop += path
    if abs(widenedLoop[0] - widenedLoop[-1]) < tinyRadius:
        widenedLoop = widenedLoop[1:]
    return euclidean.getSimplifiedLoop(widenedLoop, radius)
Example #2
0
def getWidenedLoop( loop, loopList, outsetLoop, radius, tinyRadius ):
	"Get the widened loop."
	intersectingWithinLoops = getIntersectingWithinLoops( loop, loopList, outsetLoop )
	if len( intersectingWithinLoops ) < 1:
		return loop
	widdershinsLoops = [ loop ]
	for intersectingWithinLoop in intersectingWithinLoops:
		reversedLoop = intersectingWithinLoop[ : ]
		reversedLoop.reverse()
		widdershinsLoops.append( reversedLoop )
	paths = []
	for widdershinsLoopIndex in xrange( len( widdershinsLoops ) ):
		widdershinsLoop = widdershinsLoops[ widdershinsLoopIndex ]
		for pointIndex in xrange( len( widdershinsLoop ) ):
			pointBegin = widdershinsLoop[ pointIndex ]
			pointEnd = widdershinsLoop[ ( pointIndex + 1 ) % len( widdershinsLoop ) ]
			otherLoops = widdershinsLoops[ : widdershinsLoopIndex ] + widdershinsLoops[ widdershinsLoopIndex + 1 : ]
			segments = getSegmentsFromPoints( otherLoops, pointBegin, pointEnd )
			for segment in segments:
				addToPaths( paths, tinyRadius, segment )
	for endIndex in xrange( len( paths ) - 1, 0, - 1 ):
		connectEndPath( endIndex, paths, tinyRadius )
	widenedLoop = []
	for path in paths:
		widenedLoop += path
	if abs( widenedLoop[ 0 ] - widenedLoop[ - 1 ] ) < tinyRadius:
		widenedLoop = widenedLoop[ 1 : ]
	return euclidean.getSimplifiedLoop( widenedLoop, radius )
Example #3
0
def getLargestCenterOutsetLoopFromLoop(loop, radius, thresholdRatio=0.9):
    'Get the largest circle outset loop from the loop.'
    if radius == 0.0:
        return loop
    radius = abs(radius)
    points = getPointsFromLoop(loop, radius, thresholdRatio)
    centers = getCentersFromPoints(points,
                                   globalIntercircleMultiplier * radius)
    largestCenterOutset = None
    largestOutsetArea = -987654321.0
    for center in centers:
        outset = getSimplifiedInsetFromClockwiseLoop(center, radius)
        if isLargeSameDirection(outset, center, radius):
            if euclidean.isPathInsideLoop(
                    loop, outset) != euclidean.isWiddershins(loop):
                centerOutset = CenterOutset(center, outset)
                outsetArea = abs(euclidean.getAreaLoop(outset))
                if outsetArea > largestOutsetArea:
                    largestOutsetArea = outsetArea
                    largestCenterOutset = centerOutset
    if largestCenterOutset == None:
        return None
    largestCenterOutset.center = euclidean.getSimplifiedLoop(
        largestCenterOutset.center, radius)
    return largestCenterOutset
Example #4
0
def getInfillDictionary(arounds,
                        aroundWidth,
                        infillInset,
                        infillWidth,
                        pixelTable,
                        rotatedLoops,
                        testLoops=None):
    'Get combined fill loops which include most of the points.'
    slightlyGreaterThanInfillInset = intercircle.globalIntercircleMultiplier * infillInset
    allPoints = intercircle.getPointsFromLoops(rotatedLoops, infillInset, 0.7)
    centers = intercircle.getCentersFromPoints(allPoints,
                                               slightlyGreaterThanInfillInset)
    infillDictionary = {}
    for center in centers:
        insetCenter = intercircle.getSimplifiedInsetFromClockwiseLoop(
            center, infillInset)
        insetPoint = insetCenter[0]
        if len(insetCenter) > 2 and intercircle.getIsLarge(
                insetCenter, infillInset) and euclidean.getIsInFilledRegion(
                    rotatedLoops, insetPoint):
            around = euclidean.getSimplifiedLoop(center, infillInset)
            euclidean.addLoopToPixelTable(around, pixelTable, aroundWidth)
            arounds.append(around)
            insetLoop = intercircle.getSimplifiedInsetFromClockwiseLoop(
                center, infillInset)
            euclidean.addXIntersectionsFromLoopForTable(
                insetLoop, infillDictionary, infillWidth)
            if testLoops != None:
                testLoops.append(insetLoop)
    return infillDictionary
Example #5
0
def getSimplifiedInsetFromClockwiseLoop(loop, radius):
	'Get loop inset from clockwise loop, out from widdershins loop.'
	inset = []
	for pointIndex, begin in enumerate(loop):
		center = loop[(pointIndex + 1) % len(loop)]
		end = loop[(pointIndex + 2) % len(loop)]
		addInsetPointFromClockwiseTriple(begin, center, end, inset, radius)
	return getWithoutIntersections(euclidean.getSimplifiedLoop(inset, radius))
Example #6
0
def getInfillDictionary(arounds, aroundWidth, infillInset, infillWidth, pixelTable, rotatedLoops, testLoops=None):
	'Get combined fill loops which include most of the points.'
	slightlyGreaterThanInfillInset = intercircle.globalIntercircleMultiplier * infillInset
	allPoints = intercircle.getPointsFromLoops(rotatedLoops, infillInset, 0.7)
	centers = intercircle.getCentersFromPoints(allPoints, slightlyGreaterThanInfillInset)
	infillDictionary = {}
	for center in centers:
		insetCenter = intercircle.getSimplifiedInsetFromClockwiseLoop(center, infillInset)
		insetPoint = insetCenter[0]
		if len(insetCenter) > 2 and intercircle.getIsLarge(insetCenter, infillInset) and euclidean.getIsInFilledRegion(rotatedLoops, insetPoint):
			around = euclidean.getSimplifiedLoop(center, infillInset)
			euclidean.addLoopToPixelTable(around, pixelTable, aroundWidth)
			arounds.append(around)
			insetLoop = intercircle.getSimplifiedInsetFromClockwiseLoop(center, infillInset)
			euclidean.addXIntersectionsFromLoopForTable(insetLoop, infillDictionary, infillWidth)
			if testLoops != None:
				testLoops.append(insetLoop)
	return infillDictionary
def getLargestCenterOutsetLoopFromLoop(loop, radius, thresholdRatio=0.9):
	'Get the largest circle outset loop from the loop.'
	radius = abs(radius)
	points = getPointsFromLoop(loop, radius, thresholdRatio)
	centers = getCentersFromPoints(points, globalIntercircleMultiplier * radius)
	largestCenterOutset = None
	largestOutsetArea = -987654321.0
	for center in centers:
		outset = getSimplifiedInsetFromClockwiseLoop(center, radius)
		if isLargeSameDirection(outset, center, radius):
			if euclidean.isPathInsideLoop(loop, outset) != euclidean.isWiddershins(loop):
				centerOutset = CenterOutset(center, outset)
				outsetArea = abs(euclidean.getAreaLoop(outset))
				if outsetArea > largestOutsetArea:
					largestOutsetArea = outsetArea
					largestCenterOutset = centerOutset
	if largestCenterOutset == None:
		return None
	largestCenterOutset.center = euclidean.getSimplifiedLoop(largestCenterOutset.center, radius)
	return largestCenterOutset
Example #8
0
def getLargestCenterOutsetLoopFromLoop( loop, radius, thresholdRatio = 0.9 ):
	"Get the largest circle outset loop from the loop."
	radius = abs(radius)
	slightlyGreaterThanRadius = 1.01 * radius
	points = getPointsFromLoop( loop, slightlyGreaterThanRadius, thresholdRatio )
	centers = getCentersFromPoints( points, radius )
	largestCenterOutset = None
	largestOutsetArea = - 999999999.0
	for center in centers:
		outset = getSimplifiedInsetFromClockwiseLoop( center, radius )
		if isLargeSameDirection( outset, center, radius ):
			if euclidean.isPathInsideLoop( loop, outset ) != euclidean.isWiddershins(loop):
				centerOutset = CenterOutset( center, outset )
				outsetArea = abs( euclidean.getPolygonArea( outset ) )
				if outsetArea > largestOutsetArea:
					outsetArea = largestOutsetArea
					largestCenterOutset = centerOutset
	if largestCenterOutset == None:
		return None
	largestCenterOutset.center = euclidean.getSimplifiedLoop( largestCenterOutset.center, radius )
	return largestCenterOutset
Example #9
0
def getSimplifiedInsetFromClockwiseLoop(loop, radius):
    "Get loop inset from clockwise loop, out from widdershins loop."
    return getWithoutIntersections(
        euclidean.getSimplifiedLoop(getInsetFromClockwiseLoop(loop, radius),
                                    radius))
Example #10
0
def getSimplifiedInsetFromClockwiseLoop( loop, radius ):
	"Get loop inset from clockwise loop, out from widdershins loop."
	return getWithoutIntersections( euclidean.getSimplifiedLoop( getInsetFromClockwiseLoop( loop, radius ), radius ) )