#ifndef Polygon2_HH
#define Polygon2_HH
//////////////////////////////////////////////////////////////////////////
//! file="amma/Geometry/CmpGeo2d/Polygon2.hh"
//! lib=Mcg2
//! userlevel=Normal
//! author="Radek Marik"
//! docentry="Geometry.2-D"
//! date="20.08.1994"
//! rcsid="$Id: Polygon2.hh,v 1.5 1999/05/24 10:33:02 ees1cg Exp $"
#include "amma/DList.hh"
#include "amma/Line2dPP.hh"
#include "amma/LiPoint2.hh"
class GfSetC;
class SubPolygon2dC;
class istream;
class ostream;
//====================================================================
//======= Polygon2dC ================================================
//====================================================================
//: A polygon in 2d space
// The Polygon2dC class is a representation of a polygon in 2 dimensional
// space. A polygon is the region of a plane bounded by a finite collection
// of line segments forming a simple closed curve.
// Ref.: - O'Rourke,J.: Computatinal geometry in C;
// Cambridge University Press, 1994, p. 1
// BIG OBJECT
class Polygon2dC: private Point2dListC
{
public:
inline Polygon2dC();
// Empty polygon.
inline Polygon2dC(const Point2dListC & points);
// Constructs a polygon from a list of points. The 'points' will
// be shared by the polygon (as a big object).
Polygon2dC(const Polygon2dC & points);
// Another access to the polygon.
Polygon2dC(const SubPolygon2dC & pol);
// Creates the polygon from the subset of vertexes of another polygon.
Polygon2dC(const char * s);
// Creates the polygon from one item of a GF set.
inline const DListC & List() const;
// Access to the constant list of vertexes.
RealT Area2() const;
// Returns twice the signed area of this polygon.
// Ref.: - O'Rourke,J.: Computatinal geometry in C;
// Cambridge University Press, 1994, pp. 20-26
BooleanT
IsDiagonalie(const Point2dCLIterC & a, const Point2dCLIterC & b) const;
// Returns TRUE if (a, b) is a proper internal *or* external
// diagonal of this polygon. The edges incident to 'a' and 'b'
// are ignored.
// Ref.: - O'Rourke,J.: Computatinal geometry in C;
// Cambridge University Press, 1994, pp. 35-36
BooleanT
IsInCone(const Point2dCLIterC & a, const Point2dCLIterC & b) const;
// Returns TRUE iff the diagonal (a,b) is strictly internal
// to this polygon in the neighborhood of the 'a' endpoint.
// Ref.: - O'Rourke,J.: Computatinal geometry in C;
// Cambridge University Press, 1994, pp. 37-38
inline
BooleanT
IsDiagonal(const Point2dCLIterC & a, const Point2dCLIterC & b) const;
// Returns TRUE iff (a,b) is a proper internal diagonal of
// this polygon.
// Ref.: - O'Rourke,J.: Computatinal geometry in C;
// Cambridge University Press, 1994, pp. 38-39
BooleanT Contains(const Point2dC & p) const;
// Returns TRUE iff the point 'p' is an internal point of this polygon.
DListC Triangulate();
// Returns the set of diagonals of this polygon. The polygon vertexes are
// supposed to be in the counter-clockwise order and they can
// be collinear. The polygon is destroyed.
// Ref.: - O'Rourke,J.: Computatinal geometry in C;
// Cambridge University Press, 1994, pp. 35-42
void SaveAsGF(ostream & s);
// Saves the polygon into the output stream 's' in GF format.
//private:
inline Point2dListC & List();
//: Access to the list of vertexes.
// This was private, I'm not clear why...
friend istream & operator>>(istream & s, Polygon2dC & pol);
friend ostream & operator<<(ostream & s, const Polygon2dC & pol);
};
istream &
operator>>(istream & s, Polygon2dC & pol);
// Reads a polygon from the input stream.
ostream &
operator<<(ostream & s, const Polygon2dC & pol);
// Sends the polygon into the output stream.
DListC Polygons2d(const GfSetC & s);
// Creates the list of polygons in 2D space from the GF set 's'.
//====================================================================
//======= Polygon2dC ================================================
//====================================================================
inline
const DListC &
Polygon2dC::List() const
//======================
{ return *this; }
inline
Point2dListC &
Polygon2dC::List()
//================
{ return *this; }
inline
Polygon2dC::Polygon2dC()
//======================
: Point2dListC()
{}
inline
Polygon2dC::Polygon2dC(const Point2dListC & points)
//=================================================
: Point2dListC(points)
{}
inline
BooleanT
Polygon2dC::IsDiagonal(const Point2dCLIterC & a,
const Point2dCLIterC & b) const
//====================================================
{ return IsInCone(a,b) && IsDiagonalie(a,b); }
#endif
// IAPS - Image analysis program system.
// End of include file Polygon2.hh