Ejemplo n.º 1
0
def calcCubicBounds(pt1, pt2, pt3, pt4):
    """Return the bounding rectangle for a cubic bezier segment.
    pt1 and pt4 are the "anchor" points, pt2 and pt3 are the "handles".

        >>> calcCubicBounds((0, 0), (25, 100), (75, 100), (100, 0))
        (0, 0, 100, 75.0)
        >>> calcCubicBounds((0, 0), (50, 0), (100, 50), (100, 100))
        (0.0, 0.0, 100, 100)
        >>> calcCubicBounds((50, 0), (0, 100), (100, 100), (50, 0))
        (35.566243270259356, 0, 64.43375672974068, 75.0)
    """
    (ax, ay), (bx, by), (cx,
                         cy), (dx,
                               dy) = calcCubicParameters(pt1, pt2, pt3, pt4)
    # calc first derivative
    ax3 = ax * 3.0
    ay3 = ay * 3.0
    bx2 = bx * 2.0
    by2 = by * 2.0
    xRoots = [t for t in solveQuadratic(ax3, bx2, cx) if 0 <= t < 1]
    yRoots = [t for t in solveQuadratic(ay3, by2, cy) if 0 <= t < 1]
    roots = xRoots + yRoots

    points = [(ax * t * t * t + bx * t * t + cx * t + dx,
               ay * t * t * t + by * t * t + cy * t + dy)
              for t in roots] + [pt1, pt4]
    return calcBounds(points)
Ejemplo n.º 2
0
def calcQuadraticBounds(pt1, pt2, pt3):
    """Return the bounding rectangle for a qudratic bezier segment.
    pt1 and pt3 are the "anchor" points, pt2 is the "handle".

        >>> calcQuadraticBounds((0, 0), (50, 100), (100, 0))
        (0, 0, 100, 50.0)
        >>> calcQuadraticBounds((0, 0), (100, 0), (100, 100))
        (0.0, 0.0, 100, 100)
    """
    (ax, ay), (bx, by), (cx, cy) = calcQuadraticParameters(pt1, pt2, pt3)
    ax2 = ax*2.0
    ay2 = ay*2.0
    roots = []
    if ax2 != 0:
        roots.append(-bx/ax2)
    if ay2 != 0:
        roots.append(-by/ay2)
    points = [(ax*t*t + bx*t + cx, ay*t*t + by*t + cy) for t in roots if 0 <= t < 1] + [pt1, pt3]
    return calcBounds(points)
Ejemplo n.º 3
0
def calcQuadraticBounds(pt1, pt2, pt3):
    """Return the bounding rectangle for a qudratic bezier segment.
    pt1 and pt3 are the "anchor" points, pt2 is the "handle".

        >>> calcQuadraticBounds((0, 0), (50, 100), (100, 0))
        (0, 0, 100, 50.0)
        >>> calcQuadraticBounds((0, 0), (100, 0), (100, 100))
        (0.0, 0.0, 100, 100)
    """
    (ax, ay), (bx, by), (cx, cy) = calcQuadraticParameters(pt1, pt2, pt3)
    ax2 = ax * 2.0
    ay2 = ay * 2.0
    roots = []
    if ax2 != 0:
        roots.append(-bx / ax2)
    if ay2 != 0:
        roots.append(-by / ay2)
    points = [(ax * t * t + bx * t + cx, ay * t * t + by * t + cy)
              for t in roots if 0 <= t < 1] + [pt1, pt3]
    return calcBounds(points)
Ejemplo n.º 4
0
def calcCubicBounds(pt1, pt2, pt3, pt4):
    """Return the bounding rectangle for a cubic bezier segment.
    pt1 and pt4 are the "anchor" points, pt2 and pt3 are the "handles".

        >>> calcCubicBounds((0, 0), (25, 100), (75, 100), (100, 0))
        (0, 0, 100, 75.0)
        >>> calcCubicBounds((0, 0), (50, 0), (100, 50), (100, 100))
        (0.0, 0.0, 100, 100)
        >>> calcCubicBounds((50, 0), (0, 100), (100, 100), (50, 0))
        (35.566243270259356, 0, 64.43375672974068, 75.0)
    """
    (ax, ay), (bx, by), (cx, cy), (dx, dy) = calcCubicParameters(pt1, pt2, pt3, pt4)
    # calc first derivative
    ax3 = ax * 3.0
    ay3 = ay * 3.0
    bx2 = bx * 2.0
    by2 = by * 2.0
    xRoots = [t for t in solveQuadratic(ax3, bx2, cx) if 0 <= t < 1]
    yRoots = [t for t in solveQuadratic(ay3, by2, cy) if 0 <= t < 1]
    roots = xRoots + yRoots
    
    points = [(ax*t*t*t + bx*t*t + cx * t + dx, ay*t*t*t + by*t*t + cy * t + dy) for t in roots] + [pt1, pt4]
    return calcBounds(points)
Ejemplo n.º 5
0
print time.time() - n

print
##############

print "no-numpy"
print "calcQuadraticParameters\t\t",
n = time.time()
for i in range(c):
    noNumpyBezierTools.calcQuadraticParameters(pt1, pt2, pt3)
print time.time() - n

print "calcBounds\t\t\t",
n = time.time()
for i in range(c):
    noNumpyArrayTools.calcBounds(
        [pt1, pt2, pt3, pt1, pt2, pt3, pt1, pt2, pt3, pt1, pt2, pt3])
print time.time() - n

print "pointsInRect\t\t\t",
n = time.time()
for i in range(c):
    noNumpyArrayTools.pointsInRect(
        [pt1, pt2, pt3, pt1, pt2, pt3, pt1, pt2, pt3, pt1, pt2, pt3, pt4],
        rect)
print time.time() - n

print "calcQuadraticBounds\t\t",
n = time.time()
for i in range(c):
    noNumpyBezierTools.calcQuadraticBounds(pt1, pt2, pt3)
print time.time() - n
Ejemplo n.º 6
0
print time.time() - n

print 
##############

print "no-numpy"
print "calcQuadraticParameters\t\t",
n = time.time()
for i in range(c):
    noNumpyBezierTools.calcQuadraticParameters(pt1, pt2, pt3)
print time.time() - n

print "calcBounds\t\t\t",
n = time.time()
for i in range(c):
    noNumpyArrayTools.calcBounds([pt1, pt2, pt3, pt1, pt2, pt3, pt1, pt2, pt3, pt1, pt2, pt3])
print time.time() - n

print "pointsInRect\t\t\t",
n = time.time()
for i in range(c):
    noNumpyArrayTools.pointsInRect([pt1, pt2, pt3, pt1, pt2, pt3, pt1, pt2, pt3, pt1, pt2, pt3, pt4], rect)
print time.time() - n

print "calcQuadraticBounds\t\t",
n = time.time()
for i in range(c):
    noNumpyBezierTools.calcQuadraticBounds(pt1, pt2, pt3)
print time.time() - n

print "calcCubicBounds\t\t\t",