~danieljabailey/inkscape/arc_node_editor

« back to all changes in this revision

Viewing changes to src/helper/geom.cpp

  • Committer: Daniel Bailey
  • Date: 2016-05-15 20:44:44 UTC
  • Revision ID: d@nielbailey.com-20160515204444-tak344mvzf55nhwk
Added support for editting arc segments in the node editor

Show diffs side-by-side

added added

removed removed

Lines of Context:
456
456
 
457
457
//#################################################################################
458
458
 
 
459
/**
 
460
 * Converts all segments in all paths to Geom::LineSegment or Geom::HLineSegment or
 
461
 * Geom::VLineSegment or Geom::CubicBezier or Geom::EllipticalArc.
 
462
 */
 
463
Geom::PathVector
 
464
pathv_to_linear_and_cubic_beziers_and_arcs( Geom::PathVector const &pathv )
 
465
{
 
466
    Geom::PathVector output;
 
467
 
 
468
    for (Geom::PathVector::const_iterator pit = pathv.begin(); pit != pathv.end(); ++pit) {
 
469
        output.push_back( Geom::Path() );
 
470
        output.back().setStitching(true);
 
471
        output.back().start( pit->initialPoint() );
 
472
 
 
473
        for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_open(); ++cit) {
 
474
            if (is_straight_curve(*cit)) {
 
475
                Geom::LineSegment l(cit->initialPoint(), cit->finalPoint());
 
476
                output.back().append(l);
 
477
            } else {
 
478
                Geom::EllipticalArc const *arc = dynamic_cast<Geom::EllipticalArc const *>(&*cit);
 
479
                if (arc){
 
480
                    output.back().append(arc->duplicate());
 
481
                }
 
482
                else{
 
483
                    Geom::BezierCurve const *curve = dynamic_cast<Geom::BezierCurve const *>(&*cit);
 
484
                    if (curve && curve->order() == 3) {
 
485
                        Geom::CubicBezier b((*curve)[0], (*curve)[1], (*curve)[2], (*curve)[3]);
 
486
                        output.back().append(b);
 
487
                    } else {
 
488
                        // convert all other curve types to cubicbeziers
 
489
                        Geom::Path cubicbezier_path = Geom::cubicbezierpath_from_sbasis(cit->toSBasis(), 0.1);
 
490
                        cubicbezier_path.close(false);
 
491
                        output.back().append(cubicbezier_path);
 
492
                    }
 
493
                }
 
494
            }
 
495
        }
 
496
        output.back().close( pit->closed() );
 
497
    }
 
498
    return output;
 
499
}
 
500
 
459
501
/*
460
502
 * Converts all segments in all paths to Geom::LineSegment or Geom::HLineSegment or
461
503
 * Geom::VLineSegment or Geom::CubicBezier.