{-- TerraHS - Interface between TerraLib and Haskell
(c) Sergio Costa (INPE) - Setembro, 2005
This program is free software; you can redistribute it
and/or modify it under the terms of the GNU General
Public License 2.1 as published by the Free Software Foundation
(http://www.opensource.org/licenses/gpl-license.php)--}{- | A module for supporting a TePolygonTerraLib class
In TerraLib, a 2D polygon consists of an outer ring and a list of inner rings
More information - <http://www.terralib.org> -}moduleTerraHS.TerraLib.TePolygon(-- * The @TePolygon@ typeTePolygon(..),-- * The @TePolygonPtr@ typeTePolygonPtr,-- * The @TePolygonSet@ typeTePolygonSet(..),-- * The @TePolygonSetPtr@ typeTePolygonSetPtr,polbox)whereimportForeign(Int32,unsafePerformIO)importForeign.C.StringimportqualifiedForeign.Ptr(Ptr)importTerraHS.TerraLib.TePointimportTerraHS.TerraLib.TeLine2DimportTerraHS.TerraLib.TeBoximportTerraHS.Algebras.Base.ObjectimportTerraHS.Misc.GenericFunctionsimportTerraHS.Algebras.Spatial.Polygons-- | The type @TePolygon@ represents a 2D polygon . -- In TerraLib, a 2D polygon consists of an outer ring and a list of inner ring-- In Haskell, a 2D polygon consists of a list TeLinearRingdataTePolygon=TePolygon[TeLinearRing]deriving(Eq,Show)-- | The type @TePolygonPtr@ is a pointer to @TePolygon@typeTePolygonPtr=Foreign.Ptr.PtrTePolygon-- | The type @TePolygonSet@ represents a set of 2D polygon . dataTePolygonSet=TePolygonSet[TePolygon]deriving(Eq,Show)-- | The type @TePolygonSetPtr@ is a pointer to @TePolygonSet@typeTePolygonSetPtr=Foreign.Ptr.PtrTePolygonSetpolygonId::TePolygonPtr->String->IO()polygonIdptrstr=newCStringstr>>=(tepolygon_setobidptr)>>=returninstancePointerTePolygonwherenew(TePolygonls)=tepolygon_new>>=\pol->doall(map((addLinepol))(ls))>>returnpolwhereaddLinepoll=newl>>=\l->(tepolygon_addtelinepoll)>>deleteldeleteptr=tepolygon_destroyptrfromPointerptr=tepolygon_sizeptr>>=\s->polygon2linesptr0s>>=\ps->return(TePolygonps)wherepolygon2linespis=doifi>=sthenreturn[]elsetepolygon_getteline2dpi>>=fromPointer>>=\x->polygon2linesp(i+1)s>>=\xs->return(x:xs)instancePointerTePolygonSetwherenew(TePolygonSet[])=tepolygonset_newnew(TePolygonSetxs)=doptr<-new(TePolygonSet[])addPolygonsptrxs0returnptrwhereaddPolygonsptr[]_=error"erro"addPolygonsptr[x]i=newx>>=\p->polygonIdp(showi)>>(tepolygonset_addtepolygonptrp)addPolygonsptr(x:xs)i=newx>>=\p->polygonIdp(showi)>>(tepolygonset_addtepolygonptrp)>>(addPolygonsptrxs(i+1))deleteptr=tepolygonset_destroyptrinstanceElementTePolygonSetTePolygonwheregetElementptri=tepolygonset_gettepolygonptri>>=fromPointer>>=returninstanceSizeTePolygonSetwheresizeptr=(tepolygonset_sizeptr)instancePolygonsTePolygonTeLine2DDoublewherecreatePolygonls=(TePolygonls)polboxpol=unsafePerformIO((newpol)>>=\tpol->(tepolygon_boxtpol)>>=\b->fromPointerb>>=\bh->deleteb>>deletetpol>>returnbh)--- TePolygon, TePolyonSet -----------------------------foreignimportstdcallunsafe"c_tepolygon_new"tepolygon_new::Prelude.IOTePolygonPtrforeignimportstdcallunsafe"c_tepolygon_size"tepolygon_size::TePolygonPtr->Prelude.IOInt32foreignimportstdcallunsafe"c_tepolygon_getteline2d"tepolygon_getteline2d::TePolygonPtr->Int32->Prelude.IOTeLine2DPtrforeignimportstdcallunsafe"c_tepolygon_box"tepolygon_box::TePolygonPtr->Prelude.IOTeBoxPtrforeignimportstdcallunsafe"c_tepolygonset_new"tepolygonset_new::Prelude.IOTePolygonSetPtrforeignimportstdcallunsafe"c_tepolygonset_size"tepolygonset_size::TePolygonSetPtr->Prelude.IOInt32foreignimportstdcallunsafe"c_tepolygonset_gettepolygon"tepolygonset_gettepolygon::TePolygonSetPtr->Int32->Prelude.IOTePolygonPtrforeignimportstdcallunsafe"c_tepolygonset_addtepolygon"tepolygonset_addtepolygon::TePolygonSetPtr->TePolygonPtr->Prelude.IO()foreignimportstdcallunsafe"c_tepolygon_addteline"tepolygon_addteline::TePolygonPtr->TeLine2DPtr->Prelude.IO()foreignimportstdcallunsafe"c_tepolygonset_destroy"tepolygonset_destroy::TePolygonSetPtr->Prelude.IO()foreignimportstdcallunsafe"c_tepolygon_destroy"tepolygon_destroy::TePolygonPtr->Prelude.IO()foreignimportstdcallunsafe"c_tepolygon_setobid"tepolygon_setobid::TePolygonPtr->CString->Prelude.IO()