Пример #1
0
int intersect(const Cubic& cubic, const Quadratic& quad, Intersections& i) {
    SkTDArray<double> ts;
    double precision = calcPrecision(cubic);
    cubic_to_quadratics(cubic, precision, ts);
    double tStart = 0;
    Cubic part;
    int tsCount = ts.count();
    for (int idx = 0; idx <= tsCount; ++idx) {
        double t = idx < tsCount ? ts[idx] : 1;
        Quadratic q1;
        sub_divide(cubic, tStart, t, part);
        demote_cubic_to_quad(part, q1);
        Intersections locals;
        intersect2(q1, quad, locals);
        for (int tIdx = 0; tIdx < locals.used(); ++tIdx) {
            double globalT = tStart + (t - tStart) * locals.fT[0][tIdx];
            i.insertOne(globalT, 0);
            globalT = locals.fT[1][tIdx];
            i.insertOne(globalT, 1);
        }
        tStart = t;
    }
    return i.used();
}
static void addValidRoots(const double roots[4], const int count, const int side, Intersections& i) {
    int index;
    for (index = 0; index < count; ++index) {
        if (!approximately_zero_or_more(roots[index]) || !approximately_one_or_less(roots[index])) {
            continue;
        }
        double t = 1 - roots[index];
        if (approximately_less_than_zero(t)) {
            t = 0;
        } else if (approximately_greater_than_one(t)) {
            t = 1;
        }
        i.insertOne(t, side);
    }
}