Laxkit  0.0.7.1
Public Member Functions | Public Attributes | Static Public Attributes
LaxInterfaces::Path Class Reference

Path contains only one path. More...

Inheritance diagram for LaxInterfaces::Path:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 Path (Coordinate *np, LineStyle *nls=NULL)
virtual ~Path ()
 Destructor always deletes path.
virtual Pathduplicate ()
virtual void fixpath ()
 Make sure that path points to the first vertex point of the line, if possible.
virtual CoordinatelastPoint (int v=0)
 Return the last point (vertex or control) that occurs at the end, or just before path.
virtual void append (double x, double y, unsigned long flags=POINT_VERTEX, SegmentControls *ctl=NULL)
virtual void append (flatpoint p, unsigned long flags=POINT_VERTEX, SegmentControls *ctl=NULL)
virtual void append (Coordinate *coord)
 The path takes possession of coord. Calling code should not delete it.
virtual void appendBezFromStr (const char *value)
 Append bezier points taken from the string.
virtual void moveTo (flatpoint p)
virtual void lineTo (flatpoint p)
virtual void curveTo (flatpoint c1, flatpoint c2, flatpoint p2)
virtual void close ()
 Make sure the path is closed.
virtual void clear ()
 Flush all points.
virtual int Intersect (flatpoint p1, flatpoint p2, int isline, double startt, flatpoint *pts, int ptsn, double *t, int tn)
 Find the intersection(s) of the segment (or infinite line) from p1 to p2 and the curve.
virtual int PointAlongPath (double t, int tisdistance, flatpoint *point, flatpoint *tangent)
virtual flatpoint ClosestPoint (flatpoint point, double *disttopath, double *distalongpath, double *tdist)
 Find the point on any of the paths closests to point.
virtual int Reverse ()
 Reverse the direction of the path.
virtual double Length (double tstart, double tend)
 Find the distance along the path between the bounds, or whole length if tend<tstart.
virtual double distance_to_t (double distance, int *err)
virtual double t_to_distance (double t, int *err)
virtual void dump_out (FILE *f, int indent, int what, Laxkit::anObject *context)
 Dump out path contents.
virtual void dump_in_atts (LaxFiles::Attribute *att, int flag, Laxkit::anObject *context)
- Public Member Functions inherited from LaxFiles::DumpUtility
virtual Attributedump_out_atts (Attribute *att, int what, Laxkit::anObject *savecontext)
 Default is return NULL. what==0 means write out normal Attribute formatted things.
virtual void dump_in (FILE *f, int indent, int what, Laxkit::anObject *loadcontext, Attribute **att)
 Read in a file segment as an Attribute, and pass parsing duties to dump_in_atts.
virtual ~DumpUtility ()
 Empty virtual destructor.

Public Attributes

Coordinatepath
LineStylelinestyle

Static Public Attributes

static Laxkit::PtrStack
< PathOperator
basepathops
 A reference pool of PathOperator classes.

Detailed Description

Path contains only one path.

#include <lax/interfaces/pathinterface.h>

Paths can use any PathOperator object found in basepathops to aid in constructing and maintaining path data. Straight lines and bezier lines are handled without any special PathOperators.

Path class exists just to contain a single (connected) path with its own linestyle. PathsData holds objects with multiple paths.


Constructor & Destructor Documentation

LaxInterfaces::Path::Path ( Coordinate np,
LineStyle nls = NULL 
)

Incs count of linestyle.

References Laxkit::anObject::inc_count().

LaxInterfaces::Path::~Path ( )
virtual

Destructor always deletes path.

Dec_count of linestyle.

References Laxkit::anObject::dec_count().


Member Function Documentation

void LaxInterfaces::Path::append ( flatpoint  p,
unsigned long  flags = POINT_VERTEX,
SegmentControls ctl = NULL 
)
virtual

ctl count will be incremented.

void LaxInterfaces::Path::append ( Coordinate coord)
virtual

The path takes possession of coord. Calling code should not delete it.

coord can be a string of points or a single point, open or closed.

References LaxInterfaces::Coordinate::insert(), and LaxInterfaces::Coordinate::lastPoint().

void LaxInterfaces::Path::appendBezFromStr ( const char value)
virtual

Append bezier points taken from the string.

The string must be something like "1 2 p 3 4 n 5 6 7 8". Any pair of numbers not prefaced by a 'n' or 'p' is a vertex point. A 'n' indicates it is a control point for the following point (which must be a vertex). A 'p' is for control points for a previous vertex point. Any violation of these terms stops the appending of points.

On path vertices may be tagged with 'v', and an optional point type indicator, one of 'c','s','S', or 'e'.

References LaxFiles::DoubleListAttribute().

Referenced by dump_in_atts().

flatpoint LaxInterfaces::Path::ClosestPoint ( flatpoint  point,
double *  disttopath,
double *  distalongpath,
double *  tdist 
)
virtual

Find the point on any of the paths closests to point.

point is assumed to already be in data coordinates. Returns the distance between those, and the t parameter to that path point.

References Laxkit::bez_closest_point(), Laxkit::bez_segment_length(), LaxInterfaces::Coordinate::firstPoint(), and norm().

void LaxInterfaces::Path::curveTo ( flatpoint  c1,
flatpoint  c2,
flatpoint  p2 
)
virtual

If no existing points, first do a lineTo(c1). Else, is a shortcut for:

append(c1,POINT_TOPREV,NULL)
append(c2,POINT_TONEXT,NULL)
append(p2,POINT_VERTEX,NULL)

double LaxInterfaces::Path::distance_to_t ( double  distance,
int err 
)
virtual

If the tt is on the path, set *err=1. else *err=0.

References Laxkit::bez_distance_to_t(), Laxkit::bez_segment_length(), LaxInterfaces::Coordinate::firstPoint(), and norm().

void LaxInterfaces::Path::dump_in_atts ( LaxFiles::Attribute att,
int  flag,
Laxkit::anObject context 
)
virtual
void LaxInterfaces::Path::dump_out ( FILE *  f,
int  indent,
int  what,
Laxkit::anObject context 
)
virtual

Dump out path contents.

If what==-1, then dump out pseudocode mockup of format.

Dumps out something like:

    linestyle
      ...     #standard linestyle attributes
    closed    #flag to indicate that this path is a closed path
    points \
      1 2                   #a vertex point
      p 1.5 2.5             #a control point of the previous vertex
      n 3 5                 #a control point of the next vertex
    segment controllername  #a non-straight-line and non-bezier segment
      asbezier p 3 5 n 2 4 5 6  # Important! bezier approximation of the segment.

if not present and the controller cannot be found,

then this segment is ignored.

      ...                   #any further attributes defining the segment. exactly what
                            #they are is dependent of the actual controller of the segment.
                            #If for some reason the segment controller is not found, then
                            #the bezier approximation is appended to the path as bezier points
 

Implements LaxFiles::DumpUtility.

References basepathops, LaxInterfaces::LineStyle::dump_out(), Laxkit::PtrStack< T >::e, LaxInterfaces::Coordinate::lastPoint(), and Laxkit::PtrStack< T >::n.

Referenced by LaxInterfaces::PathsData::dump_out().

Coordinate * LaxInterfaces::Path::lastPoint ( int  v = 0)
virtual

Return the last point (vertex or control) that occurs at the end, or just before path.

If v!=0, then return the last vertex, rather than the last of any kind of point.

References LaxInterfaces::Coordinate::lastPoint().

void LaxInterfaces::Path::lineTo ( flatpoint  p)
virtual

same as append(p,POINT_VERTEX,NULL).

Referenced by moveTo().

void LaxInterfaces::Path::moveTo ( flatpoint  p)
virtual

For a single path, this is the same as lineTo(). In a PathsData, this starts a new subpath.

References lineTo().

int LaxInterfaces::Path::PointAlongPath ( double  t,
int  tisdistance,
flatpoint point,
flatpoint tangent 
)
virtual

t is measured from path->firstVertex(1), and thus should be positive.

Returns 1 for point found, -1 for point clamped to beginning point, -2 clamped to end, or 0 if t is not on the line, path doesn't exist.

Todo:

be able to wind around the path if continuous, or go backwards (for negative t)

must implement find tangent at clamped endpoints

*** note that if you have a loop of null points, and you are going along based on distance, than this will not break!!

References Laxkit::bez_distance_to_t(), Laxkit::bez_point(), Laxkit::bez_segment_length(), LaxInterfaces::Coordinate::direction(), LaxInterfaces::Coordinate::firstPoint(), LaxInterfaces::Coordinate::lastPoint(), and norm().

int LaxInterfaces::Path::Reverse ( )
virtual

Reverse the direction of the path.

Return 0 for success or 1 for some error.

Todo:
*** this ignores pathop ownership!

References LaxInterfaces::Coordinate::firstPoint().

double LaxInterfaces::Path::t_to_distance ( double  tt,
int err 
)
virtual

If the tt is on the path, set *err=1. else *err=0.

Todo:
If tt<0 this fails... it shouldn't!!

References Laxkit::bez_segment_length(), Laxkit::bez_t_to_distance(), LaxInterfaces::Coordinate::firstPoint(), and norm().


Member Data Documentation

PtrStack< PathOperator > LaxInterfaces::Path::basepathops
static

A reference pool of PathOperator classes.

This static pool is necessary to allow Path or PathsData, for instance, to figure out their actual bounds and to dump_out properly, independently of any particular PathInterface or PathOperator instance.

Referenced by dump_in_atts(), dump_out(), LaxInterfaces::PathInterface::getPathOpFromId(), and LaxInterfaces::PathInterface::Refresh().


The documentation for this class was generated from the following files:

Mon Feb 17 2014 11:52:58, Laxkit