示例#1
0
QList<RVector> RSpline::getPointsWithDistanceToEnd(double distance, int from) const {
    QList<RVector> ret;

    if (splineProxy!=NULL) {
        double t;
        if (from&RS::FromStart) {
            t = splineProxy->getTAtDistance(*this, distance);
            ret << getPointAt(t);
        }
        if (from&RS::FromEnd) {
            t = splineProxy->getTAtDistance(*this, getLength() - distance);
            ret << getPointAt(t);
        }
    }
    else {
        // no spline proxy (not precise, but better than nothing in some cases):
        double length = getLength();
        if (length<=RS::PointTolerance) {
            return ret;
        }

        if (from&RS::FromStart) {
            RVector p = getPointAt(getTMin() + (distance/length*getTDelta()));
            ret.append(p);
        }

        if (from&RS::FromEnd) {
            RVector p = getPointAt(getTMin() + ((length-distance)/length*getTDelta()));
            ret.append(p);
        }
    }

    return ret;
}
示例#2
0
/**
 * \return List of RLines describing this spline.
 */
QList<QSharedPointer<RShape> > RSpline::getExploded(int segments) const {
    if (!exploded.isEmpty() && segments==-1) {
        return exploded;
    }

    //qDebug() << "RSpline::getExploded: segments: " << segments;
    //RDebug::printBacktrace("getExploded:    ");

    //##boundingBox = RBox();

    updateInternal();

    exploded.clear();

    if (!isValid()) {
        //qWarning() << "RSpline::getExploded: invalid spline";
        return exploded;
    }

    if (segments==-1) {
        segments = 8;
    }

    double tMin = getTMin();
    double tMax = getTMax();

    double step = getTDelta() / (controlPoints.size() * segments);

    RVector p1;
    RVector prev = RVector::invalid;
    for (double t = tMin; t<tMax+(step/2.0); t+=step) {
        double tc = qMin(t, tMax);
        p1 = getPointAt(tc);

        if (RMath::isNaN(p1.x) || RMath::isNaN(p1.y)) {
            continue;
        }

        if (prev.isValid()) {
            RLine* line = new RLine(prev, p1);
            exploded.append(QSharedPointer<RShape>(line));
        }
        prev = p1;

        //##boundingBox.growToInclude(p1);
    }

    p1 = getEndPoint();
    if (!RMath::isNaN(p1.x) && !RMath::isNaN(p1.y)) {
        if (prev.isValid()) {
            RLine* line = new RLine(prev, p1);
            // prevent zero length line at the end:
            if (line->getLength()>1.0e-4) {
                exploded.append(QSharedPointer<RShape>(line));
            }
        }
    }

    return exploded;
}
示例#3
0
QList<RVector> RSpline::getPointsWithDistanceToEnd(double distance, RS::From from) const {
    QList<RVector> ret;

    double length = getLength();
    if (length<=RS::PointTolerance) {
        return ret;
    }

    if (from==RS::FromStart || from==RS::FromAny) {
        RVector p = getPointAt(getTMin() + (distance/length*getTDelta()));
        ret.append(p);
    }

    if (from==RS::FromEnd || from==RS::FromAny) {
        RVector p = getPointAt(getTMin() + ((length-distance)/length*getTDelta()));
        ret.append(p);
    }

    return ret;
}
示例#4
0
RVector RSpline::getMiddlePoint() const {
    return getPointAt(getTMin() + (getTDelta()/2.0));
}