/************************************************************************
 *   gpoint_adt.h : header file for point ADT 
 *   
 *   Change Log :
 *		  Spring 1996 Initial version,  Liujian Qian
 *		  11-11-1996  revised accordingly --LQ
 *
 * $Id: gadt_point.h,v 1.5 1999/02/16 22:05:22 qian Exp $
 ************************************************************************/


#ifndef _GPOINT_H_
#define _GPOINT_H_

#include <iostream.h>
#include "gadt.h"
#include "gdatapipe.h"

/**
   ADT of a geometric point. 

   You know what a point is.  Note that all the coordinates in GFC
   are doubles.
*/
class GPoint : public GSpatial
{
public:
    /// make  them public just for efficiency
    Coord x, y, z;  

public:
    ///
    NOP			GPoint(): x(0), y(0), z(0) {  }
    ///
    NOP			GPoint(Coord _x, Coord _y, Coord _z=0) 
	                      :x(_x), y(_y), z(_z) { }
    ///
    NOP			GPoint(const GPoint& other) 
	                      {x = other.x, y = other.y, z = other.z; }
    ///
    GPoint& 		operator=(const GPoint& pnt);
    
    virtual GType  	type() 	   const {return _Point;}
    virtual uint32  	getPSize() const;
    virtual Result	init(void) {x=y=z=0; return GOk;}

    /**
     * usr format: "x y"
     */
    virtual Result 	input     (const char* in);
    virtual Result 	output    (char*& out);
    
    virtual Result	pack	   (DataPipe& p);
    virtual Result      unpack     (DataPipe& p);

    virtual Result 	mbr(GRect& box) const;
    virtual GADT* 	clone() const {return new GPoint; }
    virtual int	  	cmp(const GADT& other) const;
    
    virtual Result	scale      (double xf, double yf, double zf=1);
    virtual Result      translate  (double xf, double yf, double zf=1);    
    virtual Result	rotate	   (double, bool);
    virtual Result	transform  (const GMatrix&);
    virtual int		intersects (const GSpatial& ) const {return GOk;}
    virtual int		covers	   (const GSpatial& ) const {return GOk;}

    //====================================================
    //====
    //GROUP:   ADT-specific methods
    //====
    //====================================================

    ///
    inline Coord  	getX() const	  { return x; }
    ///
    inline Coord  	getY() const	  { return y; }
    ///
    inline Coord	getZ() const 	  { return z; }
    ///
    inline void   	setX(Coord _x)  { x = _x;  }
    ///
    inline void   	setY(Coord _y)  { y = _y;  }
    ///
    inline void		setZ(Coord _z)  { z = _z; }
    ///
    inline void   	set(Coord _x, Coord _y, Coord _z=0)    {x=_x, y=_y, z=_z; }
    
    /// generate a circle buffer centered at the point.
    //  r is the radius of the generated circle.
    void  	genCircle(GCircle& circle, double r);

    /// generate a rectangle buffer centered at the point.
    //  width and height gives the total width and height of 
    //  the generated square.
    void  	genSquare(GRect& rect, double width, double height);
    /// get distance to the origion.
    double	distance() const;
    
    /// get distance to another point
    double 	distance (const GPoint& other) const;

    /// get distance to another segment
    double 	distance (const GSegment& other) const;

    /// check if the point is inside a given rectangle
    int   	isInside     (const GRect& other) const;

    /// check if the point is inside a given circle
    int   	isInside     (const GCircle& other) const;

    /// check if the point is inside a given triangle *not implemented
    int   	isInside     (const GTrig& other) const;

    /// check if the point is inside a given polygon
    int   	isInside     (const GPolygon& other) const;

    /// check if the point coincides with another one
    bool		equals	     (const GPoint& a) const;

    /// print the point info
    friend ostream&  	operator<<(ostream& s, const GPoint& pnt);
};


extern double distPnts (Coord x0, Coord y0, Coord x1, Coord y1);

//for proper registeration of GPoint ADT
static class _GIPoint
{
    static int cnt;
public:
    _GIPoint() 
    {
	if(cnt++ ==0 ) 
	    GADTManager::registerADT(new GADTDef( _Point, "Point", 1, 1, new GPoint) );
    }
    ~_GIPoint() 
    {
	if(--cnt==0)
	    GADTManager::removeADT(_Point);
    }
} gi_point;


#endif

Documentation generated by lqian@lqian-sun on Wed Jul 14 09:36:10 EDT 1999