Difference between revisions of "Working with 2Geom FAQ"

From Inkscape Wiki
Jump to navigation Jump to search
Line 15: Line 15:
 
     D2<Piecewise<SBasis> > y = make_cuts_independant(x);
 
     D2<Piecewise<SBasis> > y = make_cuts_independant(x);
 
     x = sectionize(y);
 
     x = sectionize(y);
 +
 +
This is unclear!!! please expand.
  
 
===How do I calculate the bounding box of a path?===
 
===How do I calculate the bounding box of a path?===

Revision as of 17:56, 31 October 2007

Introduction

Questions that arise during coding with 2geom are put here. To see other 2geom related questions go to the general lib2geom FAQ.

Questions

How to create a straight line (for types: Path, pwd2, d2pw)?

   Path p;
   p.appendNew<LineSegment>(a, b);
   
   Piecewise<D2<SBasis> > pwd2 = Piecewise<D2<SBasis> >(D2<SBasis>(Linear(a[X], b[X]), Linear(a[Y], b[Y])));

How to convert from Path to pwd2 to d2pw to path and back?

   D2<Piecewise<SBasis> > y = make_cuts_independant(x);
   x = sectionize(y);

This is unclear!!! please expand.

How do I calculate the bounding box of a path?

   Rect r = path.boundsFast(); 

or

   Rect r = path.boundsExact();

How do I convert 2geom to svgd and back?

inkscape has code for this somewhere :p (Johan knows this)

What does "compose" do?

Compose is the mathematical operation f(?) o g(?) = f(g(?)). Any transformation, be it translation or mesh distort, can be considered a composition of the original path P(t)->(u,v) and a function T(u,v)->(x,y) which takes each point in the plane to a new point. We write this transformation as compose(T, P). For examples of such composition at work look at the toys

  • '2dsb2d', which composes the path with a polynomial mesh function called a coons patch
  • 'plane3d', which composes the path with a 3d projection onto a plane surface
  • 'center-warp', which shows how repeated composition produces the tweak tool effect
  • 'path-along-path' which shows how composition allows mapping a shape along a path

2Geom provides various compose operations for functions representable using piecewise sbasis functions, as well the ability to compose arbitrary functions defined directly in code. All the mathematics is performed in sbasis space.