<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>Crystal Space 1.2.1: csgeom/polyclip.h Source File (Crystal Space 1.2.1 Public API Reference)</title> <link href="tabs.css" rel="stylesheet" type="text/css"> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <table border="0" cellpadding="0" cellspacing="0" width="100%" class="head"> <tr height="59"> <td class="head" width="202" valign="bottom" style="padding-left:0;"><a href="http://www.crystalspace3d.org/"><img src="csblur.png" width="236" height="59" alt="CrystalSpace" border="0"></a></td> <td class="head"><h2>Public API Reference</h2></td> </tr> <tr height="11"> <td colspan="2" class="headshadow" valign="top" style="padding-left:0;"><img src="csblurb.png" width="236" height="11" alt="" border="0"></td> </tr> </table> <div class="content"> <!-- Generated by Doxygen 1.5.3 --> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="classes.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> </ul> </div> <h1>csgeom/polyclip.h</h1><a href="polyclip_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> Crystal Space polygon clipping routines</span> <a name="l00003"></a>00003 <span class="comment"> Copyright (C) 1998 by Jorrit Tyberghein</span> <a name="l00004"></a>00004 <span class="comment"> Contributed by Ivan Avramovic <ivan@avramovic.com> and</span> <a name="l00005"></a>00005 <span class="comment"> Andrew Zabolotny <bit@eltech.ru></span> <a name="l00006"></a>00006 <span class="comment"></span> <a name="l00007"></a>00007 <span class="comment"> This library is free software; you can redistribute it and/or</span> <a name="l00008"></a>00008 <span class="comment"> modify it under the terms of the GNU Library General Public</span> <a name="l00009"></a>00009 <span class="comment"> License as published by the Free Software Foundation; either</span> <a name="l00010"></a>00010 <span class="comment"> version 2 of the License, or (at your option) any later version.</span> <a name="l00011"></a>00011 <span class="comment"></span> <a name="l00012"></a>00012 <span class="comment"> This library is distributed in the hope that it will be useful,</span> <a name="l00013"></a>00013 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00014"></a>00014 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> <a name="l00015"></a>00015 <span class="comment"> Library General Public License for more details.</span> <a name="l00016"></a>00016 <span class="comment"></span> <a name="l00017"></a>00017 <span class="comment"> You should have received a copy of the GNU Library General Public</span> <a name="l00018"></a>00018 <span class="comment"> License along with this library; if not, write to the Free</span> <a name="l00019"></a>00019 <span class="comment"> Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.</span> <a name="l00020"></a>00020 <span class="comment">*/</span> <a name="l00021"></a>00021 <a name="l00022"></a>00022 <span class="preprocessor">#ifndef __CS_POLYCLIP_H__</span> <a name="l00023"></a>00023 <span class="preprocessor"></span><span class="preprocessor">#define __CS_POLYCLIP_H__</span> <a name="l00024"></a>00024 <span class="preprocessor"></span> <a name="l00025"></a>00025 <a name="l00026"></a>00026 <span class="preprocessor">#include "csextern.h"</span> <a name="l00027"></a>00027 <a name="l00028"></a>00028 <span class="preprocessor">#include "<a class="code" href="box_8h.html" title="Bounding boxes for 2D and 3D space.">csgeom/box.h</a>"</span> <a name="l00029"></a>00029 <a name="l00030"></a>00030 <span class="preprocessor">#include "<a class="code" href="clip2d_8h.html" title="2D clipping interface">igeom/clip2d.h</a>"</span> <a name="l00031"></a>00031 <a name="l00032"></a>00032 <span class="preprocessor">#include "<a class="code" href="scf__implementation_8h.html" title="Crystal Space Shared Class Facility (SCF) - implementation creation support.">csutil/scf_implementation.h</a>"</span> <a name="l00033"></a>00033 <a name="l00034"></a>00034 <span class="keyword">class </span><a class="code" href="classcsPoly2DPool.html" title="This is an object pool which holds objects of type csPoly2D.">csPoly2DPool</a>; <a name="l00035"></a>00035 <a name="l00046"></a><a class="code" href="classcsClipper.html">00046</a> <span class="keyword">class </span>CS_CRYSTALSPACE_EXPORT <a class="code" href="classcsClipper.html" title="The csClipper class is an abstract parent to all 2D clipping objects.">csClipper</a> : <a name="l00047"></a>00047 <span class="keyword">public</span> <a class="code" href="classscfImplementation1.html">scfImplementation1</a><csClipper,iClipper2D> <a name="l00048"></a>00048 { <a name="l00049"></a>00049 <span class="keyword">protected</span>: <a name="l00051"></a><a class="code" href="classcsClipper.html#6ab49b50f3a2451d8d2fb01c4e133260">00051</a> <span class="keyword">static</span> <a class="code" href="classcsPoly2DPool.html" title="This is an object pool which holds objects of type csPoly2D.">csPoly2DPool</a> *polypool; <a name="l00052"></a>00052 <a name="l00054"></a><a class="code" href="classcsClipper.html#6e30efeb63038e311c6d5f5ed1a1037b">00054</a> <a class="code" href="group__util.html#gdde6aaee8457bee49c2a92621fe22b79" title="unsigned 8-bit integer (0..255)">uint8</a> mrClipping; <a name="l00055"></a>00055 <a name="l00056"></a>00056 <span class="keyword">public</span>: <a name="l00057"></a>00057 <span class="keyword">static</span> <a class="code" href="classcsPoly2DPool.html" title="This is an object pool which holds objects of type csPoly2D.">csPoly2DPool</a> *GetSharedPool (); <a name="l00058"></a>00058 <a name="l00059"></a>00059 <span class="keyword">public</span>: <a name="l00061"></a>00061 <a class="code" href="classcsClipper.html" title="The csClipper class is an abstract parent to all 2D clipping objects.">csClipper</a> (); <a name="l00062"></a>00062 <a name="l00064"></a>00064 <span class="keyword">virtual</span> ~<a class="code" href="classcsClipper.html" title="The csClipper class is an abstract parent to all 2D clipping objects.">csClipper</a> (); <a name="l00065"></a>00065 <a name="l00067"></a>00067 <span class="keyword">virtual</span> <a class="code" href="group__util.html#gdde6aaee8457bee49c2a92621fe22b79" title="unsigned 8-bit integer (0..255)">uint8</a> ClipInPlace (<a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a> *InPolygon, <span class="keywordtype">size_t</span> &InOutCount, <a name="l00068"></a>00068 <a class="code" href="classcsBox2.html" title="A bounding box in 2D space.">csBox2</a> &BoundingBox); <a name="l00069"></a>00069 <a name="l00071"></a><a class="code" href="classcsClipper.html#9d201cbaff2ec136a2ebe5e8615da079">00071</a> <a class="code" href="group__util.html#gdde6aaee8457bee49c2a92621fe22b79" title="unsigned 8-bit integer (0..255)">uint8</a> LastClipResult () { <span class="keywordflow">return</span> mrClipping; } <a name="l00072"></a>00072 }; <a name="l00073"></a>00073 <a name="l00078"></a><a class="code" href="classcsBoxClipper.html">00078</a> <span class="keyword">class </span>CS_CRYSTALSPACE_EXPORT <a class="code" href="classcsBoxClipper.html" title="The csBoxClipper class is able to clip convex polygons to a rectangle (such as the...">csBoxClipper</a> : <span class="keyword">public</span> <a class="code" href="classcsClipper.html" title="The csClipper class is an abstract parent to all 2D clipping objects.">csClipper</a> <a name="l00079"></a>00079 { <a name="l00081"></a>00081 <a class="code" href="classcsBox2.html" title="A bounding box in 2D space.">csBox2</a> region; <a name="l00083"></a>00083 <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a> ClipBox [4]; <a name="l00084"></a>00084 <a name="l00086"></a>00086 <span class="keyword">inline</span> <span class="keywordtype">void</span> InitClipBox () <a name="l00087"></a>00087 { <a name="l00088"></a>00088 ClipBox [0].Set (region.MinX (), region.MinY ()); <a name="l00089"></a>00089 ClipBox [1].Set (region.MinX (), region.MaxY ()); <a name="l00090"></a>00090 ClipBox [2].Set (region.MaxX (), region.MaxY ()); <a name="l00091"></a>00091 ClipBox [3].Set (region.MaxX (), region.MinY ()); <a name="l00092"></a>00092 } <a name="l00093"></a>00093 <a name="l00094"></a>00094 <span class="keyword">public</span>: <a name="l00096"></a><a class="code" href="classcsBoxClipper.html#72a74d9d24995199da33cadae780fc79">00096</a> <a class="code" href="classcsBoxClipper.html" title="The csBoxClipper class is able to clip convex polygons to a rectangle (such as the...">csBoxClipper</a> (<span class="keyword">const</span> <a class="code" href="classcsBox2.html" title="A bounding box in 2D space.">csBox2</a>& b) : region (b) <a name="l00097"></a>00097 { InitClipBox (); } <a name="l00099"></a><a class="code" href="classcsBoxClipper.html#9570593534dd1a20fcbad29b02b0bf61">00099</a> <a class="code" href="classcsBoxClipper.html" title="The csBoxClipper class is able to clip convex polygons to a rectangle (such as the...">csBoxClipper</a> (<span class="keywordtype">float</span> x1, <span class="keywordtype">float</span> y1, <span class="keywordtype">float</span> x2, <span class="keywordtype">float</span> y2) : region (x1,y1,x2,y2) <a name="l00100"></a>00100 { InitClipBox (); } <a name="l00101"></a>00101 <a name="l00103"></a>00103 <span class="keyword">virtual</span> <a class="code" href="group__util.html#gdde6aaee8457bee49c2a92621fe22b79" title="unsigned 8-bit integer (0..255)">uint8</a> <a class="code" href="structiClipper2D.html#2b9dcd9f97500ea210e434a2f5f02299" title="Clip a set of 2D points and return in &#39;OutPolygon&#39; which is expected to contain...">Clip</a> (<a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a> *InPolygon, <span class="keywordtype">size_t</span> InCount, <a name="l00104"></a>00104 <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a> *OutPolygon, <span class="keywordtype">size_t</span> &OutCount); <a name="l00105"></a>00105 <a name="l00107"></a>00107 <span class="keyword">virtual</span> <a class="code" href="group__util.html#gdde6aaee8457bee49c2a92621fe22b79" title="unsigned 8-bit integer (0..255)">uint8</a> <a class="code" href="structiClipper2D.html#2b9dcd9f97500ea210e434a2f5f02299" title="Clip a set of 2D points and return in &#39;OutPolygon&#39; which is expected to contain...">Clip</a> (<a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a> *InPolygon, <span class="keywordtype">size_t</span> InCount, <a name="l00108"></a>00108 <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a> *OutPolygon, <span class="keywordtype">size_t</span> &OutCount, <a class="code" href="classcsBox2.html" title="A bounding box in 2D space.">csBox2</a> &BoundingBox); <a name="l00109"></a>00109 <a name="l00111"></a>00111 <span class="keyword">virtual</span> <a class="code" href="group__util.html#gdde6aaee8457bee49c2a92621fe22b79" title="unsigned 8-bit integer (0..255)">uint8</a> <a class="code" href="structiClipper2D.html#2b9dcd9f97500ea210e434a2f5f02299" title="Clip a set of 2D points and return in &#39;OutPolygon&#39; which is expected to contain...">Clip</a> (<a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a> *InPolygon, <span class="keywordtype">size_t</span> InCount, <a name="l00112"></a>00112 <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a> *OutPolygon, <span class="keywordtype">size_t</span> &OutCount, <a class="code" href="structcsVertexStatus.html" title="The clipper can output additional information about each vertex in output polygon...">csVertexStatus</a> *OutStatus); <a name="l00113"></a>00113 <a name="l00115"></a>00115 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="structiClipper2D.html#f79ddb0aa5da86b8fe78d25395385de6" title="Classify some bounding box against this clipper.">ClassifyBox</a> (<span class="keyword">const</span> <a class="code" href="classcsBox2.html" title="A bounding box in 2D space.">csBox2</a> &box); <a name="l00116"></a>00116 <a name="l00118"></a><a class="code" href="classcsBoxClipper.html#105c6e61ad5943647a4163c73b312123">00118</a> <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="structiClipper2D.html#c0b0813e21123d4211d8cd093b8dd3ba" title="Return true if given point is inside (or on bound) of clipper polygon.">IsInside</a> (<span class="keyword">const</span> <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a>& v) <a name="l00119"></a>00119 { <span class="keywordflow">return</span> region.In (v.<a class="code" href="classcsVector2.html#cf4ee25489c98e6b7b7a460c4edd4ac6" title="X component of vector.">x</a>, v.<a class="code" href="classcsVector2.html#f736730a67b9ee807f1455da3d2be188" title="Y component of vector.">y</a>); } <a name="l00120"></a>00120 <a name="l00122"></a><a class="code" href="classcsBoxClipper.html#139cf60f2685caac6a254e81dce75c27">00122</a> <span class="keyword">virtual</span> <span class="keywordtype">size_t</span> <a class="code" href="structiClipper2D.html#624994070bdb107a90f8902ba332a937" title="Return number of vertices for this clipper polygon.">GetVertexCount</a> () <a name="l00123"></a>00123 { <span class="keywordflow">return</span> 4; } <a name="l00124"></a>00124 <a name="l00126"></a><a class="code" href="classcsBoxClipper.html#7872039688f9938fbbccb5bfe64c6451">00126</a> <span class="keyword">virtual</span> <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a> *<a class="code" href="structiClipper2D.html#8210d2f967bdd837630a6caccea43169" title="Return a pointer to the array of csVector2&#39;s.">GetClipPoly</a> () <a name="l00127"></a>00127 { <span class="keywordflow">return</span> ClipBox; } <a name="l00128"></a>00128 <a name="l00129"></a><a class="code" href="classcsBoxClipper.html#f352d510f25cd20537cf3edeffd00d27">00129</a> <span class="keyword">virtual</span> <a class="code" href="structiClipper2D.html#03ed976bdb8cd014a5dabccc06bd3730" title="The type of a clipper.">ClipperType</a> <a class="code" href="structiClipper2D.html#7016695a49e465211d75df6224a17979" title="Retrieve the type of this clipper.">GetClipperType</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> clipperBox; } <a name="l00130"></a>00130 }; <a name="l00131"></a>00131 <a name="l00142"></a><a class="code" href="classcsPolygonClipper.html">00142</a> <span class="keyword">class </span>CS_CRYSTALSPACE_EXPORT <a class="code" href="classcsPolygonClipper.html" title="The csPolygonClipper class can be used for clipping any polygon against any other...">csPolygonClipper</a> : <span class="keyword">public</span> <a class="code" href="classcsClipper.html" title="The csClipper class is an abstract parent to all 2D clipping objects.">csClipper</a> <a name="l00143"></a>00143 { <a name="l00145"></a>00145 <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a> *ClipData; <a name="l00147"></a>00147 <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a> *ClipPoly; <a name="l00149"></a>00149 <a class="code" href="classcsPoly2D.html" title="The following class represents a general 2D polygon.">csPoly2D</a> *ClipPoly2D; <a name="l00151"></a>00151 <span class="keywordtype">size_t</span> ClipPolyVertices; <a name="l00153"></a>00153 <a class="code" href="classcsBox2.html" title="A bounding box in 2D space.">csBox2</a> ClipBox; <a name="l00154"></a>00154 <a name="l00156"></a>00156 <span class="keywordtype">void</span> Prepare (); <a name="l00157"></a>00157 <a name="l00158"></a>00158 <span class="keyword">public</span>: <a name="l00160"></a>00160 <a class="code" href="classcsPolygonClipper.html" title="The csPolygonClipper class can be used for clipping any polygon against any other...">csPolygonClipper</a> (<a class="code" href="classcsPoly2D.html" title="The following class represents a general 2D polygon.">csPoly2D</a> *Clipper, <span class="keywordtype">bool</span> mirror = <span class="keyword">false</span>, <a name="l00161"></a>00161 <span class="keywordtype">bool</span> copy = <span class="keyword">false</span>); <a name="l00163"></a>00163 <a class="code" href="classcsPolygonClipper.html" title="The csPolygonClipper class can be used for clipping any polygon against any other...">csPolygonClipper</a> (<a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a> *Clipper, <span class="keywordtype">size_t</span> Count, <span class="keywordtype">bool</span> mirror = <span class="keyword">false</span>, <a name="l00164"></a>00164 <span class="keywordtype">bool</span> copy = <span class="keyword">false</span>); <a name="l00166"></a>00166 <span class="keyword">virtual</span> ~<a class="code" href="classcsPolygonClipper.html" title="The csPolygonClipper class can be used for clipping any polygon against any other...">csPolygonClipper</a> (); <a name="l00167"></a>00167 <a name="l00169"></a>00169 <span class="keyword">virtual</span> <a class="code" href="group__util.html#gdde6aaee8457bee49c2a92621fe22b79" title="unsigned 8-bit integer (0..255)">uint8</a> <a class="code" href="structiClipper2D.html#2b9dcd9f97500ea210e434a2f5f02299" title="Clip a set of 2D points and return in &#39;OutPolygon&#39; which is expected to contain...">Clip</a> (<a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a> *InPolygon, <span class="keywordtype">size_t</span> InCount, <a name="l00170"></a>00170 <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a> *OutPolygon, <span class="keywordtype">size_t</span> &OutCount); <a name="l00171"></a>00171 <a name="l00173"></a>00173 <span class="keyword">virtual</span> <a class="code" href="group__util.html#gdde6aaee8457bee49c2a92621fe22b79" title="unsigned 8-bit integer (0..255)">uint8</a> <a class="code" href="structiClipper2D.html#2b9dcd9f97500ea210e434a2f5f02299" title="Clip a set of 2D points and return in &#39;OutPolygon&#39; which is expected to contain...">Clip</a> (<a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a> *InPolygon, <span class="keywordtype">size_t</span> InCount, <a name="l00174"></a>00174 <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a> *OutPolygon, <span class="keywordtype">size_t</span> &OutCount, <a class="code" href="classcsBox2.html" title="A bounding box in 2D space.">csBox2</a> &BoundingBox); <a name="l00175"></a>00175 <a name="l00177"></a>00177 <span class="keyword">virtual</span> <a class="code" href="group__util.html#gdde6aaee8457bee49c2a92621fe22b79" title="unsigned 8-bit integer (0..255)">uint8</a> <a class="code" href="structiClipper2D.html#2b9dcd9f97500ea210e434a2f5f02299" title="Clip a set of 2D points and return in &#39;OutPolygon&#39; which is expected to contain...">Clip</a> (<a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a> *InPolygon, <span class="keywordtype">size_t</span> InCount, <a name="l00178"></a>00178 <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a> *OutPolygon, <span class="keywordtype">size_t</span> &OutCount, <a class="code" href="structcsVertexStatus.html" title="The clipper can output additional information about each vertex in output polygon...">csVertexStatus</a> *OutStatus); <a name="l00179"></a>00179 <a name="l00181"></a>00181 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="structiClipper2D.html#f79ddb0aa5da86b8fe78d25395385de6" title="Classify some bounding box against this clipper.">ClassifyBox</a> (<span class="keyword">const</span> <a class="code" href="classcsBox2.html" title="A bounding box in 2D space.">csBox2</a> &box); <a name="l00182"></a>00182 <a name="l00184"></a>00184 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="structiClipper2D.html#c0b0813e21123d4211d8cd093b8dd3ba" title="Return true if given point is inside (or on bound) of clipper polygon.">IsInside</a> (<span class="keyword">const</span> <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a>& v); <a name="l00185"></a>00185 <a name="l00187"></a><a class="code" href="classcsPolygonClipper.html#26d0d6eca7d087e976d95b527ac72cff">00187</a> <span class="keyword">virtual</span> <span class="keywordtype">size_t</span> <a class="code" href="structiClipper2D.html#624994070bdb107a90f8902ba332a937" title="Return number of vertices for this clipper polygon.">GetVertexCount</a> () { <span class="keywordflow">return</span> ClipPolyVertices; } <a name="l00188"></a>00188 <a name="l00190"></a><a class="code" href="classcsPolygonClipper.html#a7a349bdcfcd1e804cba188dd93a331e">00190</a> <span class="keyword">virtual</span> <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a> *<a class="code" href="structiClipper2D.html#8210d2f967bdd837630a6caccea43169" title="Return a pointer to the array of csVector2&#39;s.">GetClipPoly</a> () <a name="l00191"></a>00191 { <span class="keywordflow">return</span> ClipPoly; } <a name="l00192"></a>00192 <a name="l00193"></a><a class="code" href="classcsPolygonClipper.html#243d6b080a6679ec445bd4342267edd0">00193</a> <span class="keyword">virtual</span> <a class="code" href="structiClipper2D.html#03ed976bdb8cd014a5dabccc06bd3730" title="The type of a clipper.">ClipperType</a> <a class="code" href="structiClipper2D.html#7016695a49e465211d75df6224a17979" title="Retrieve the type of this clipper.">GetClipperType</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> clipperPoly; } <a name="l00194"></a>00194 }; <a name="l00198"></a>00198 <span class="preprocessor">#endif // __CS_POLYCLIP_H__</span> </pre></div><hr size="1"><address><small>Generated for Crystal Space 1.2.1 by <a href="http://www.doxygen.org/index.html">doxygen</a> 1.5.3 </small></address> </div></body> </html>