skia2/experimental/Intersection/QuadraticSubDivide.cpp

70 lines
1.9 KiB
C++
Raw Normal View History

/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "CurveIntersection.h"
work in progress for shape operations A experimental/Intersection A experimental/Intersection/Intersections.h A experimental/Intersection/DataTypes.cpp A experimental/Intersection/QuadraticReduceOrder.cpp A experimental/Intersection/IntersectionUtilities.cpp A experimental/Intersection/CubicIntersection_Tests.h A experimental/Intersection/LineParameteters_Test.cpp A experimental/Intersection/ReduceOrder.cpp A experimental/Intersection/QuadraticIntersection.cpp A experimental/Intersection/Extrema.h A experimental/Intersection/CubicIntersection_TestData.h A experimental/Intersection/QuadraticParameterization_Test.cpp A experimental/Intersection/TestUtilities.cpp A experimental/Intersection/CubicRoots.cpp A experimental/Intersection/QuadraticParameterization.cpp A experimental/Intersection/QuadraticSubDivide.cpp A experimental/Intersection/LineIntersection_Test.cpp A experimental/Intersection/LineIntersection.cpp A experimental/Intersection/CubicParameterizationCode.cpp A experimental/Intersection/LineParameters.h A experimental/Intersection/CubicIntersection.h A experimental/Intersection/CubeRoot.cpp A experimental/Intersection/SkAntiEdge.h A experimental/Intersection/ConvexHull_Test.cpp A experimental/Intersection/CubicBezierClip_Test.cpp A experimental/Intersection/CubicIntersection_Tests.cpp A experimental/Intersection/CubicBezierClip.cpp A experimental/Intersection/CubicIntersectionT.cpp A experimental/Intersection/Inline_Tests.cpp A experimental/Intersection/ReduceOrder_Test.cpp A experimental/Intersection/QuadraticIntersection_TestData.h A experimental/Intersection/DataTypes.h A experimental/Intersection/Extrema.cpp A experimental/Intersection/EdgeApp.cpp A experimental/Intersection/CubicIntersection_TestData.cpp A experimental/Intersection/IntersectionUtilities.h A experimental/Intersection/CubicReduceOrder.cpp A experimental/Intersection/CubicCoincidence.cpp A experimental/Intersection/CubicIntersection_Test.cpp A experimental/Intersection/CubicIntersection.cpp A experimental/Intersection/QuadraticUtilities.h A experimental/Intersection/SkAntiEdge.cpp A experimental/Intersection/TestUtilities.h A experimental/Intersection/CubicParameterization_Test.cpp A experimental/Intersection/LineIntersection.h A experimental/Intersection/CubicSubDivide.cpp A experimental/Intersection/CubicParameterization.cpp A experimental/Intersection/QuadraticBezierClip_Test.cpp A experimental/Intersection/QuadraticBezierClip.cpp A experimental/Intersection/BezierClip_Test.cpp A experimental/Intersection/ConvexHull.cpp A experimental/Intersection/BezierClip.cpp A experimental/Intersection/QuadraticIntersection_TestData.cpp git-svn-id: http://skia.googlecode.com/svn/trunk@3005 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-01-10 21:46:10 +00:00
#include "IntersectionUtilities.h"
/*
Given a quadratic q, t1, and t2, find a small quadratic segment.
The new quadratic is defined by A, B, and C, where
A = c[0]*(1 - t1)*(1 - t1) + 2*c[1]*t1*(1 - t1) + c[2]*t1*t1
C = c[3]*(1 - t1)*(1 - t1) + 2*c[2]*t1*(1 - t1) + c[1]*t1*t1
To find B, compute the point halfway between t1 and t2:
q(at (t1 + t2)/2) == D
Next, compute where D must be if we know the value of B:
_12 = A/2 + B/2
12_ = B/2 + C/2
123 = A/4 + B/2 + C/4
= D
work in progress for shape operations A experimental/Intersection A experimental/Intersection/Intersections.h A experimental/Intersection/DataTypes.cpp A experimental/Intersection/QuadraticReduceOrder.cpp A experimental/Intersection/IntersectionUtilities.cpp A experimental/Intersection/CubicIntersection_Tests.h A experimental/Intersection/LineParameteters_Test.cpp A experimental/Intersection/ReduceOrder.cpp A experimental/Intersection/QuadraticIntersection.cpp A experimental/Intersection/Extrema.h A experimental/Intersection/CubicIntersection_TestData.h A experimental/Intersection/QuadraticParameterization_Test.cpp A experimental/Intersection/TestUtilities.cpp A experimental/Intersection/CubicRoots.cpp A experimental/Intersection/QuadraticParameterization.cpp A experimental/Intersection/QuadraticSubDivide.cpp A experimental/Intersection/LineIntersection_Test.cpp A experimental/Intersection/LineIntersection.cpp A experimental/Intersection/CubicParameterizationCode.cpp A experimental/Intersection/LineParameters.h A experimental/Intersection/CubicIntersection.h A experimental/Intersection/CubeRoot.cpp A experimental/Intersection/SkAntiEdge.h A experimental/Intersection/ConvexHull_Test.cpp A experimental/Intersection/CubicBezierClip_Test.cpp A experimental/Intersection/CubicIntersection_Tests.cpp A experimental/Intersection/CubicBezierClip.cpp A experimental/Intersection/CubicIntersectionT.cpp A experimental/Intersection/Inline_Tests.cpp A experimental/Intersection/ReduceOrder_Test.cpp A experimental/Intersection/QuadraticIntersection_TestData.h A experimental/Intersection/DataTypes.h A experimental/Intersection/Extrema.cpp A experimental/Intersection/EdgeApp.cpp A experimental/Intersection/CubicIntersection_TestData.cpp A experimental/Intersection/IntersectionUtilities.h A experimental/Intersection/CubicReduceOrder.cpp A experimental/Intersection/CubicCoincidence.cpp A experimental/Intersection/CubicIntersection_Test.cpp A experimental/Intersection/CubicIntersection.cpp A experimental/Intersection/QuadraticUtilities.h A experimental/Intersection/SkAntiEdge.cpp A experimental/Intersection/TestUtilities.h A experimental/Intersection/CubicParameterization_Test.cpp A experimental/Intersection/LineIntersection.h A experimental/Intersection/CubicSubDivide.cpp A experimental/Intersection/CubicParameterization.cpp A experimental/Intersection/QuadraticBezierClip_Test.cpp A experimental/Intersection/QuadraticBezierClip.cpp A experimental/Intersection/BezierClip_Test.cpp A experimental/Intersection/ConvexHull.cpp A experimental/Intersection/BezierClip.cpp A experimental/Intersection/QuadraticIntersection_TestData.cpp git-svn-id: http://skia.googlecode.com/svn/trunk@3005 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-01-10 21:46:10 +00:00
Group the known values on one side:
B = D*2 - A/2 - C/2
*/
static double interp_quad_coords(const double* src, double t)
{
double ab = interp(src[0], src[2], t);
double bc = interp(src[2], src[4], t);
double abc = interp(ab, bc, t);
return abc;
}
void sub_divide(const Quadratic& src, double t1, double t2, Quadratic& dst) {
double ax = dst[0].x = interp_quad_coords(&src[0].x, t1);
double ay = dst[0].y = interp_quad_coords(&src[0].y, t1);
double dx = interp_quad_coords(&src[0].x, (t1 + t2) / 2);
double dy = interp_quad_coords(&src[0].y, (t1 + t2) / 2);
double cx = dst[2].x = interp_quad_coords(&src[0].x, t2);
double cy = dst[2].y = interp_quad_coords(&src[0].y, t2);
/* bx = */ dst[1].x = 2*dx - (ax + cx)/2;
/* by = */ dst[1].y = 2*dy - (ay + cy)/2;
}
/* classic one t subdivision */
static void interp_quad_coords(const double* src, double* dst, double t)
{
double ab = interp(src[0], src[2], t);
double bc = interp(src[2], src[4], t);
dst[0] = src[0];
dst[2] = ab;
dst[4] = interp(ab, bc, t);
dst[6] = bc;
dst[8] = src[4];
}
void chop_at(const Quadratic& src, QuadraticPair& dst, double t)
{
interp_quad_coords(&src[0].x, &dst.pts[0].x, t);
interp_quad_coords(&src[0].y, &dst.pts[0].y, t);
}