KJB

Representation of an (x,y) pair of pixel coordinates. More...
#include <pixpoint.h>
Classes  
struct  Is_inbounds 
Predicate functor tests whether a PixPoint is in a bounding box. More...  
struct  Unused 
exception thrown if the PixPoint is used while uninitialized More...  
Public Types  
typedef int  Integer 
any signed integer valued type is fine More...  
Public Member Functions  
PixPoint ()  
ctor sets fields to sentinel values to indicated "unused." More...  
PixPoint (Integer xx, Integer yy)  
Basic ctor builds from two coordinates. More...  
void  swap (PixPoint &that) 
swap state of two pixpoints More...  
bool  is_unused () const 
Test whether a PixPoint is unused (untouched since default ctor) More...  
bool  is_not_unused () const 
convenience inline for better readability More...  
bool  is_used () const 
another convenience inline that is not so unpositive. More...  
bool  operator< (const PixPoint &pp) const 
This operator imposes a total order on PixPoints. More...  
bool  operator== (const PixPoint &pp) const 
test whether two points are equivalent (same integer coords) More...  
bool  operator!= (const PixPoint &pp) const 
test whether two points differ (different integer coords) More...  
PixPoint &  operator+= (const PixPoint &pp) 
add a PixPoint to this PixPoint, when interpreted as 2vectors More...  
PixPoint  operator+ (const PixPoint &pp) const 
add two PixPoints when they are interpreted as 2vectors More...  
PixPoint  operator (const PixPoint &pp) const 
subtract two PixPoints when they are interpreted as 2vectors More...  
PixPoint  operator* (int factor) const 
multiply components of a PixPoint by a factor (like 2vector) More...  
PixPoint  operator/ (int divisor) const 
integerdivide components of a PixPoint (like a 2vector) More...  
Integer  idot (const PixPoint &pp) const 
interp as 2vec, compute dot prod as integer (beware overflow) More...  
float  dist2 (const PixPoint &pp=PixPoint(0, 0)) const 
Distance squared between PixPoint objects, or from the origin. More...  
float  dist (const PixPoint &pp=PixPoint(0, 0)) const 
Return distance between points, using the L2 norm. More...  
Integer  L_infinity_distance (const PixPoint &pp) const 
bool  adjacent8 (const PixPoint &pp) const 
test adjacency using eightconnectivity (or identity). More...  
std::string  str (const std::string &sep=", ") const 
Express a PixPoint as a string (ascii coordinate values) More...  
bool  in_quadrant_I () const 
Test whether a PixPoint has nonnegative x and y coordinates. More...  
bool  is_poz_poz () const 
Test whether a PixPoint has strictly positive x and y coords. More...  
Integer  cross (const PixPoint &pp) const 
return cross product of two PixPoints interpreted as 2vectors. More...  
bool  is_collinear (const PixPoint &p1, const PixPoint &p2) const 
return true iff this point lies on the same line as line(p1,p2). More...  
Static Public Member Functions  
static void  fault_if (bool b) 
throw exception if we try to operate on an unused point More...  
Public Attributes  
Integer  x 
x coordinate of the pixel More...  
Integer  y 
y coordinate of the pixel More...  
Representation of an (x,y) pair of pixel coordinates.
The following structure is used to represent a single pixel coordinate in a trail image. We use a vector of them (below) to represent a trail or trail proposal within that context (i.e., without the full information provided by a struct seg.
Useful pixel methods include adjacency testing, a total order based on row major ordering, and both L2 and Linfinity distances between points.
This struct has a default ctor that sets the fields to a sentinel value (a large number) which indicates that the x and y coordinates have not been properly assigned valid values.
To a limited extent, you can partially use these as 2vectors, since you can store negative coordinate values, and they have both + and  operators.
typedef int kjb::qd::PixPoint::Integer 
any signed integer valued type is fine

inline 
ctor sets fields to sentinel values to indicated "unused."
Basic ctor builds from two coordinates.

inline 
test adjacency using eightconnectivity (or identity).
pp  point to test whether it is adjacent to this one 
This tests whether two pixels are adjacent under the usual 8connected criteria. Note that a pixel is vacuously adjacent to itself, too.
return cross product of two PixPoints interpreted as 2vectors.
pp  other PixPoint (interpreted as 2vector) to cross with this one. 
Actually we should call this the magnitude of the cross product, since the cross product is really a vector product. However, for vectors in the XY plane, in a righthanded coordinate system, the direction is always the Z direction, and this returns the magnitude.
Return distance between points, using the L2 norm.
pp  This method returns the L2norm distance between pp and this point (or the origin, if omitted). 
This used to use sqrtf but <cmath> lacks it, despite <math.h> promising it. However, <cmath> has overloaded versions, including one for float. In the spirit of separating interface from impl., less is in fact more.
Distance squared between PixPoint objects, or from the origin.
pp  This method returns the L2norm distance squared between this point and pp, if pp is specified. If left unspecified, pp defaults to the origin. L2norm distance is Euclidean distance, if you didn't know that already. 
Why use this method? Because it is cheaper than dist() yet produces the same partially ordered set. Formally, for all PixPoints p, q, r dist(p,r) <= dist(q,r) IFF dist2(p,r) <= dist2(q,r). Proof is trivial.

inlinestatic 
throw exception if we try to operate on an unused point
interp as 2vec, compute dot prod as integer (beware overflow)

inline 
Test whether a PixPoint has nonnegative x and y coordinates.
The lines x = 0 and y = 0 are partially in Quadrant I. Wait, that's not a very precise statement. The rays {(x,y) : x>=0, y=0} and {(x,y) : x=0, y>=0} are in Quadrant I. Is that worse? That's worse, isn't it? Ah well, I give up. The code is only 24 characters long; probably best just to read it.
return true iff this point lies on the same line as line(p1,p2).

inline 
convenience inline for better readability

inline 

inline 
Test whether a PixPoint is unused (untouched since default ctor)

inline 
another convenience inline that is not so unpositive.
This returns between this point and pp, when we use the Linfinity norm to compute distance. What's that in ordinary terms? It's the length of the longer edge of the smallest axisaligned bounding box surrounding both points. Confusing? Maybe it's easier just to read the code below. Purpose? It's the number of pixels in the Bressenhamalg. drawn line from this point to pp, minus one.
If this point or the argument is unused, this method returns a negative value.
It would be legitimate to give pp a default value of PixPoint(0,0) just as I did for the dist2() method. I will wait to do so until it is somehow useful.
pp  Point to which (from this point) we want to know distance 

inline 
test whether two points differ (different integer coords)

inline 
multiply components of a PixPoint by a factor (like 2vector)
add two PixPoints when they are interpreted as 2vectors
subtract two PixPoints when they are interpreted as 2vectors

inline 
integerdivide components of a PixPoint (like a 2vector)

inline 
This operator imposes a total order on PixPoints.
pp  Point to compare to this point 
Although it does not really matter, this order reflects rowmajor positioning of the pixels in an array.

inline 
test whether two points are equivalent (same integer coords)

inline 
Express a PixPoint as a string (ascii coordinate values)

inline 
swap state of two pixpoints
Integer kjb::qd::PixPoint::x 
x coordinate of the pixel
Integer kjb::qd::PixPoint::y 
y coordinate of the pixel