void VehicleTrack::addPoint(Point point)
{
    if (segments_.empty())
        segments_.push_back( PSegment( new StraightSegment( point, point ) ) );
    else if ( segments_.size() == 1 && segments_.front()->begin() == segments_.front()->end() )
        segments_.front().reset( new StraightSegment( segments_.front()->begin(), point ) );
    else
    {
        if ( segments_.back()->end() == point )
            return;
        // Mowiac krotko jak jest jeden segment to jest StraightSegment
        // jak dodajemy trzeci punkt to juz mozna beziera zrobic, wiec jest : straight -> bezier -> straight
        // jak kolejny dajemy to jest : straight -> bezier -> straight(mozliwe ze o zerowej dlugosci jak nie wyrabia sie zakretowo) -> bezier -> straight

        Point realBegin = segments_.back()->begin();
        Point lastBegin = realBegin;
        Point lastEnd = segments_.back()->end();

        segments_.pop_back();

        if (!segments_.empty())
            realBegin = static_cast<BezierSegment*>(segments_.back().get())->control();

        Point p1, p2;
        std::pair<Point, Point> p_tmp = bothBezierBetween(lastBegin, point, lastEnd);
        p1 = p_tmp.first;
        p2 = p_tmp.second;

        // optymalizacja(jeszcze nie ma :P): jak begin i end na tym samym x'ie lub y'ku to tylko straight
        segments_.push_back( PSegment( new StraightSegment( lastBegin, p1 ) ) );
        segments_.push_back( PSegment( new BezierSegment( p1, p2, lastEnd ) ) );
        segments_.push_back( PSegment( new StraightSegment( p2, point ) ) );
    }

    recalculateLength();
}
Example #2
0
PSegment& PSegment::ortho(TP p) {
   PSegment* seg = DEBUG_NEW PSegment(-_B, _A, _B*p.x() - _A*p.y());
   return *seg;
}