Laxkit  0.0.7.1
Public Member Functions | Public Attributes
LaxInterfaces::Coordinate Class Reference

The basic coordinate class for points. More...

List of all members.

Public Member Functions

 Coordinate ()
 Your basic constructor.
 Coordinate (flatpoint p)
 Constructor to make a vertex point at p.
 Coordinate (double x, double y)
 Constructor to make a vertex point at (x,y).
 Coordinate (flatpoint pp, unsigned long nflags, SegmentControls *ctl)
 Coordinate (double x, double y, unsigned long nflags, SegmentControls *ctl)
 Constructor to make a vertex point at (x,y). Incs count of ctl.
 Coordinate (const Coordinate &p)
 Creates copy with next and prev equal to NULL.
virtual ~Coordinate ()
 Deletes both prev and next if they exist.
const Coordinateoperator= (const Coordinate &p)
virtual double x ()
virtual void x (double xx)
virtual double y ()
virtual void y (double yy)
virtual flatpoint p ()
virtual void p (double xx, double yy)
virtual void p (flatpoint pp)
virtual int isAttachedTo (Coordinate *v)
 Return 1 if this==v. Return 2 if is TOPREV of v, or -1 if is TONEXT of v. Else 0.
virtual int isEndpoint ()
 Return whether this is an endpoint, or is a handle connected to an endpoint.
virtual CoordinatepreviousVertex (int n=0)
 Find the previous vertex from this.
virtual CoordinatenextVertex (int n=0)
 Finds the next vertex after this.
virtual CoordinatefirstPoint (int v=0)
 Return the most previous point in line, or this if line is closed.
virtual CoordinatelastPoint (int v=0)
 Return the most next point in open line, or this, if the line is a closed loop.
virtual int hasCoord (Coordinate *co)
 Return 1 if co is somewhere in path, else 0.
virtual void ShiftPoint (flatpoint p)
virtual Coordinateduplicate ()
 Sort of a workaround for copy constructor, copy point, flags, iid, info, but set next, prev to NULL.
virtual CoordinateduplicateAll ()
 Return a complete copy of the path, SegmentControls and all.
virtual void append (double x, double y, unsigned long flags=POINT_VERTEX, SegmentControls *ctl=NULL)
 Append a new vertex point (x,y) to the next NULL, with iid=0.
virtual void close ()
 Make this a closed loop if it is not already.
virtual int isClosed ()
 Return whether the coordinate is part of a closed path or not.
virtual void connect (Coordinate *np, char after=1)
 This connects a SINGLE point np either after or before (after==0).
virtual Coordinatedisconnect (char after=1)
 This severs the link between this and this->next (or prev if after=0)
virtual Coordinatedetach ()
 Removes this from the path.
virtual CoordinatedetachThrough (Coordinate *p)
 Removes all points from this to and including p from the path, closing the connection of the remaining path.
virtual int insert (Coordinate *c, int after=1)
 Insert point after *this (if after!=0) else before *this.
virtual int NumPoints (int v)
 Return the number of individual points (v==0), or the number of vertices if v==1.
virtual flatpoint direction (int after)
 Return a vector pointing in the visual direction the line seems to go in.

Public Attributes

flatpoint fp
unsigned long flags
int iid
int info
SegmentControlscontrols
Coordinatenext
Coordinateprev

Detailed Description

The basic coordinate class for points.

#include <lax/interfaces/pathinterface.h>
Todo:
perhaps make this ref counting?

The point's actual values are wrapped in x(), y(), and p(). This will help out making coordinate references later on.. Many of the functions in here must be called with care, lest memory leaks occur. PathInterface takes, or at least ought to be taking, the appropriate precautions.

Here are the defines for flags:

//POINT_MASK is basically what kind of coordinate it is
#define POINT_VERTEX (1<<0)
#define POINT_TONEXT (1<<1)
#define POINT_TOPREV (1<<2)
#define POINT_MIDDLE (1<<3)
#define POINT_LOOP_TERMINATOR (1<<14)
#define POINT_TERMINATOR (1<<15)
#define POINT_MASK (1|2|4|8|(1<<14)|(1<<15))
// Point's x and y coordinates can be defined relative to various things.
// This is to facilitate keeping controls with their vertex. One must
// define an origin and axis.
// Origin: If none of the following 3 are set, then absolute coordinates
// are assumed.
#define POINT_REL_TO_PREV (1<<4)
#define POINT_REL_TO_NEXT (1<<5)
#define POINT_REL_TO_MIDPOINT (1<<6)
// Axis:
// Axis 1 has the x direction == (v2-v1)/||v2-v1||, y=transpose x
// Axis 2 has the x direction == (v2-v1)/2, y=transpose x
// If neither axis 1 or 2 is set, then the axis of the points coords is used.
#define POINT_REL_AXIS_1 (1<<7)
#define POINT_REL_AXIS_2 (1<<8)
#define POINT_REL_AXIS_DEFAULT (1<<9)
// selectable means that PathInterface can select/move/rotate/etc
#define POINT_SELECTABLE (1<<10)
#define POINT_READONLY (1<<11)
// program should make efforts to make the tangent smooth here
// (this is attribute of a vertex)
#define POINT_SMOOTH (1<<12)
// program should make efforts to make the tangent length equal on both sides of the point
#define POINT_REALLYSMOOTH (1<<12|1<<13)

Constructor & Destructor Documentation

LaxInterfaces::Coordinate::Coordinate ( flatpoint  pp,
unsigned long  nflags,
SegmentControls ctl 
)

Incs count of ctl.

References Laxkit::anObject::inc_count().

LaxInterfaces::Coordinate::Coordinate ( const Coordinate p)

Creates copy with next and prev equal to NULL.

This will result in count of this->controls being incremented by 1.

References Laxkit::anObject::inc_count().

LaxInterfaces::Coordinate::~Coordinate ( )
virtual

Deletes both prev and next if they exist.

Assumes simple connections to other nodes, Care taken here to destroy loops of unknown size, meaning that if this point is connected to a loop, the whole loop is deleted properly, without segfaulting.


Member Function Documentation

void LaxInterfaces::Coordinate::append ( double  x,
double  y,
unsigned long  flags = POINT_VERTEX,
SegmentControls ctl = NULL 
)
virtual

Append a new vertex point (x,y) to the next NULL, with iid=0.

Puts the point in the next most NULL. If this is a closed loop, then puts in this->next. It does not check for consistency with controls...

This function is for convenience of making simple lines on the fly. If ctl!=NULL, then its count is incremented.

References Laxkit::anObject::inc_count().

void LaxInterfaces::Coordinate::connect ( Coordinate np,
char  after = 1 
)
virtual

This connects a SINGLE point np either after or before (after==0).

Assumes that np->next==np->prev==NULL. To insert a string of points, use insert().

This function only concerns itself with the immediately next connection. It does not check for consistency with control points. That is the duty of PathInterface. It does not scan down the line. It assumes that the relevant next/prevs are of this and of np are all NULL. It does not do error checking.

Referenced by LaxInterfaces::PathInterface::CutNear(), and LaxInterfaces::MeasureInterface::LBDown().

Coordinate * LaxInterfaces::Coordinate::detach ( )
virtual

Removes this from the path.

This completely removes *this from the line by setting next=prev=NULL, and next->prev=next, and prev->next=next if next and/or prev exist.

Returns a coordinate that is on the remaining path, if any.

This function would only be called by PathInterface, PathsData, or Path, which take the necessary precautions to ensure that no path heads are screwed up.

Referenced by LaxInterfaces::PathInterface::removeSegment().

Coordinate * LaxInterfaces::Coordinate::detachThrough ( Coordinate p)
virtual

Removes all points from this to and including p from the path, closing the connection of the remaining path.

This completely removes the points from the line by setting next=prev=NULL, and next->prev=next, and prev->next=next if next and/or prev exist. p is assumed to be in the next direction from this.

Returns a coordinate that is on the remaining path, if any. If this was on a closed path, then the segment this..p will now be open.

This function would only be called by PathInterface, PathsData, or Path, which take the necessary precautions to ensure that no path heads are screwed up.

Referenced by LaxInterfaces::PathInterface::DeletePoint().

flatpoint LaxInterfaces::Coordinate::direction ( int  after)
virtual

Return a vector pointing in the visual direction the line seems to go in.

Note this is different than a tangent. If prev or next points are attached, then use those, but if there is a null tangent, then the numerical tangent will be 0. In this case, assume bezier points, and calculate the visual direction. If we are on a terminator, then grab the tangent from the non-null side.

A unit vector will always be returned. Default on not possible is (1,0).

References Laxkit::bez_point(), and norm().

Referenced by LaxInterfaces::PathInterface::MouseMove(), LaxInterfaces::Path::PointAlongPath(), LaxInterfaces::PathInterface::SetCurvertex(), and LaxInterfaces::PathInterface::UpdateDir().

Coordinate * LaxInterfaces::Coordinate::disconnect ( char  after = 1)
virtual

This severs the link between this and this->next (or prev if after=0)

This function should only be called by PathInterface, PathsData, or Path, which take the necessary precautions.

Returns pointer to the coordinate on the other side of the break, if any.

Coordinate * LaxInterfaces::Coordinate::duplicate ( )
virtual

Sort of a workaround for copy constructor, copy point, flags, iid, info, but set next, prev to NULL.

I might simply not understand copy constructors, but this function exists in case there are points that are supposed to be accessed and set the same as a normal Coordinate, but the internals are worked around somehow. Normal copy constructors do not afford such flexiblity.

controls count will end up being incremented by 1.

Coordinate * LaxInterfaces::Coordinate::firstPoint ( int  v = 0)
virtual

Return the most previous point in line, or this if line is closed.

If v!=0, find the first vertex. If there is no first vertex (path is all control points) returns the first point (or this if closed loop). firstPoint will never return NULL.

References nextVertex().

Referenced by LaxInterfaces::PathInterface::AddPoint(), LaxInterfaces::Path::ClosestPoint(), LaxInterfaces::Path::distance_to_t(), LaxInterfaces::Path::fixpath(), insert(), LaxInterfaces::Path::Intersect(), LaxInterfaces::Path::Length(), LaxInterfaces::PathInterface::MergeEndpoints(), LaxInterfaces::Path::PointAlongPath(), LaxInterfaces::PathInterface::Refresh(), LaxInterfaces::Path::Reverse(), LaxInterfaces::PathInterface::scan(), and LaxInterfaces::Path::t_to_distance().

int LaxInterfaces::Coordinate::hasCoord ( Coordinate co)
virtual

Return 1 if co is somewhere in path, else 0.

See also PathsData::hasCoord().

Referenced by LaxInterfaces::PathInterface::DeletePoint().

int LaxInterfaces::Coordinate::insert ( Coordinate c,
int  after = 1 
)
virtual

Insert point after *this (if after!=0) else before *this.

Assumes that c is the most previous point in a list of one or more points, that is open or closed. Also assumes that the segment is sectioned correctly, that is, it does not sever control segments. PathInterface is supposed to check for that. Returns 1 on success.

References firstPoint(), and lastPoint().

Referenced by LaxInterfaces::PathInterface::AddPoint(), LaxInterfaces::Path::append(), and LaxInterfaces::PathInterface::CutNear().

int LaxInterfaces::Coordinate::isEndpoint ( )
virtual

Return whether this is an endpoint, or is a handle connected to an endpoint.

If this is a handle, return 2 if it is a TOPREV and there is no next vertex, or -2 if is a TONEXT and there is no previous vertex.

If this is a vertex, return 1 if there is no next vertex, or -1 if there is no previous vertex.

Else return 0.

Referenced by LaxInterfaces::PathInterface::LBDown(), LaxInterfaces::PathInterface::MergeEndpoints(), and LaxInterfaces::PathInterface::MouseMove().

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

Return the most next point in open line, or this, if the line is a closed loop.

If v!=0, find the last vertex. If there is no last vertex (path is all control points) returns the last point (or this if closed loop). lastPoint will never return NULL.

References previousVertex().

Referenced by LaxInterfaces::Path::append(), LaxInterfaces::Path::dump_in_atts(), LaxInterfaces::Path::dump_out(), insert(), LaxInterfaces::Path::lastPoint(), LaxInterfaces::PathInterface::MergeEndpoints(), and LaxInterfaces::Path::PointAlongPath().

Coordinate * LaxInterfaces::Coordinate::nextVertex ( int  n = 0)
virtual

Finds the next vertex after this.

Returns next vertex starting AFTER this, if n==0.
Returns next vertex starting WITH this, if n==1.
returns NULL if there is no such next vertex.

Referenced by LaxInterfaces::PathInterface::AddPoint(), LaxInterfaces::PathsData::FindBBox(), firstPoint(), LaxInterfaces::PathsData::GetCoordinate(), and LaxInterfaces::PathInterface::scan().

const Coordinate & LaxInterfaces::Coordinate::operator= ( const Coordinate p)

Does not modify next and prev. Everything else is copied over. controls count will end up being incremented by 1.

References Laxkit::anObject::inc_count().

Coordinate * LaxInterfaces::Coordinate::previousVertex ( int  n = 0)
virtual

Find the previous vertex from this.

Returns previous vertex starting BEFORE this, if n==0.
Returns previous vertex starting WITH this, if n==1.
Returns NULL if can't find any previous vertex.

Referenced by lastPoint().


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

Mon Feb 17 2014 11:52:58, Laxkit