├── .gitignore ├── AUTHORS.txt ├── ExampleData ├── Data │ ├── custom.dat │ ├── star.dat │ ├── diamond.dat │ ├── test.dat │ ├── strange.dat │ ├── tank.dat │ ├── 2.dat │ ├── dude.dat │ ├── funny.dat │ ├── Pointsets │ │ ├── example1.dat │ │ ├── example2.dat │ │ ├── example3.dat │ │ └── example4.dat │ ├── debug.dat │ ├── bird.dat │ ├── sketchup.dat │ └── polygon.dae ├── Textures │ └── poly2tri_logotype_256x256.png ├── Properties │ └── AssemblyInfo.cs ├── ExampleData.cs └── ExampleData.csproj ├── README.txt ├── Debug ├── Properties │ └── AssemblyInfo.cs ├── PolygonInfo.cs ├── Debug.csproj └── DebugForm.cs ├── Properties └── AssemblyInfo.cs ├── SwfTest ├── Properties │ └── AssemblyInfo.cs ├── SwfTest.csproj └── TestForm.cs ├── LICENSE.txt ├── Triangulation ├── Orientation.cs ├── TriangulationAlgorithm.cs ├── TriangulationMode.cs ├── Delaunay │ ├── Sweep │ │ ├── DTSweepEdgeEvent.cs │ │ ├── DTSweepBasin.cs │ │ ├── PointOnEdgeException.cs │ │ ├── DTSweepPointComparator.cs │ │ ├── AdvancingFrontNode.cs │ │ ├── DTSweepConstraint.cs │ │ ├── DTSweepDebugContext.cs │ │ ├── AdvancingFront.cs │ │ └── DTSweepContext.cs │ └── DelaunayTriangle.cs ├── TriangulationDebugContext.cs ├── TriangulationConstraint.cs ├── ITriangulatable.cs ├── Util │ ├── PointGenerator.cs │ └── PolygonGenerator.cs ├── Sets │ ├── ConstrainedPointSet.cs │ └── PointSet.cs ├── TriangulationPoint.cs ├── TriangulationContext.cs └── TriangulationUtil.cs ├── Polygon ├── PolygonPoint.cs ├── PolygonSet.cs └── Polygon.cs ├── Utility ├── FixedArray3.cs └── FixedBitArray3.cs ├── Poly2Tri.sln ├── P2T.cs └── Poly2Tri.csproj /.gitignore: -------------------------------------------------------------------------------- 1 | Thumbs.db 2 | *.suo 3 | *.user 4 | obj/ 5 | bin/ 6 | -------------------------------------------------------------------------------- /AUTHORS.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/poly2tri-cs/HEAD/AUTHORS.txt -------------------------------------------------------------------------------- /ExampleData/Data/custom.dat: -------------------------------------------------------------------------------- 1 | 0 130 2 | -270 0 3 | 130 -40 4 | 10 -60 5 | -10 -20 6 | 100 30 7 | 40 -40 -------------------------------------------------------------------------------- /ExampleData/Data/star.dat: -------------------------------------------------------------------------------- 1 | 350 75 2 | 379 161 3 | 469 161 4 | 397 215 5 | 423 301 6 | 350 250 7 | 277 301 8 | 303 215 9 | 231 161 10 | 321 161 11 | -------------------------------------------------------------------------------- /ExampleData/Data/diamond.dat: -------------------------------------------------------------------------------- 1 | 0.0 0.0 2 | 2.0 1.0 3 | 4.0 2.0 4 | 6.0 3.0 5 | 8.0 4.0 6 | 1.0 5.0 7 | -8.0 4.0 8 | -6.0 3.0 9 | -4.0 2.0 10 | -2.0 1.0 11 | -------------------------------------------------------------------------------- /ExampleData/Data/test.dat: -------------------------------------------------------------------------------- 1 | 227.15518,452.33157 2 | 344.46202,352.32647 3 | 472.15156,452.33157 4 | 603.11967,352.32647 5 | 344.46202,725.78132 6 | 81.390847,352.32647 -------------------------------------------------------------------------------- /ExampleData/Textures/poly2tri_logotype_256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/poly2tri-cs/HEAD/ExampleData/Textures/poly2tri_logotype_256x256.png -------------------------------------------------------------------------------- /ExampleData/Data/strange.dat: -------------------------------------------------------------------------------- 1 | 400 472 2 | 500 392 3 | 520 272 4 | 460 232 5 | 580 212 6 | 480 152 7 | 360 172 8 | 360 52 9 | 300 112 10 | 200 32 11 | 120 92 12 | 200 72 13 | 340 272 14 | 208 212 15 | 180 352 16 | 300 312 17 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | ------------ 2 | Dependencies 3 | ------------ 4 | 5 | Core Library: 6 | - .NET 3.5 7 | 8 | Testbed: 9 | - WinForms 10 | 11 | ---------------------------------------------- 12 | Building the Testbed 13 | ---------------------------------------------- 14 | 15 | Poly2Tri.sln contains everything. Just build it. 16 | 17 | ---------------------------------------------- 18 | Running the Examples 19 | ---------------------------------------------- 20 | 21 | Poly2Tri.sln contains everything. 22 | To run an example from the solution: 23 | Right click on one of the example projects in the solution explorer: 24 | SwfTest 25 | Click "Set as StartUp Project" in the menu 26 | Run the project: 27 | Click the green run arrow icon 28 | or go to the Debug menu -> Start Debugging 29 | or use a keyboard shortcut (F5 or F6(?) by default depending on configuration) 30 | 31 | ---------------------------------------------- 32 | Links 33 | ---------------------------------------------- 34 | 35 | poly2tri Project Page http://code.google.com/p/poly2tri/ 36 | C# port project page http://github.com/MaulingMonkey/poly2tri-cs 37 | -------------------------------------------------------------------------------- /ExampleData/Data/tank.dat: -------------------------------------------------------------------------------- 1 | -37.317758 260.65677 2 | -37.317758 317.44301 3 | -34.741139 339.73612 4 | -27.330761 354.21222 5 | 59.525828 406.25724 6 | 444.17643 404.87856 7 | 538.9604 368.68832 8 | 555.15984 355.59089 9 | 558.95121 344.90615 10 | 559.64054 325.94936 11 | 568.19908 315.85885 12 | 572.586 322.56108 13 | 584.65003 322.31737 14 | 568.80837 296.11771 15 | 557.59736 289.78104 16 | 539.56224 286.49085 17 | 443.31476 286.82943 18 | 389.89106 280.79772 19 | 405.74583 272.00866 20 | 412.98388 262.01326 21 | 475.5413 262.1856 22 | 480.71134 267.01096 23 | 514.66123 266.66629 24 | 520.34827 262.01326 25 | 669.93463 262.01326 26 | 670.45162 264.08127 27 | 676.91417 263.82277 28 | 678.03434 262.09943 29 | 680.61936 261.66859 30 | 683.03204 255.46455 31 | 682.51504 249.94985 32 | 677.862 243.91814 33 | 668.81445 243.4873 34 | 665.28159 247.02016 35 | 520.86527 246.33082 36 | 514.66123 240.12678 37 | 479.67733 239.95444 38 | 475.5413 243.57347 39 | 412.98388 243.05647 40 | 397.64611 227.54636 41 | 324.74862 221.16998 42 | 323.88695 214.79361 43 | 328.36764 211.86392 44 | 326.6443 207.03856 45 | 300.79412 207.03856 46 | 295.62409 211.69159 47 | 285.28402 208.2449 48 | 272.01426 211.17458 49 | 96.577738 209.62357 50 | 80.205961 211.86392 51 | 58.491817 232.7164 52 | 74.863594 254.94755 53 | 168.61356 269.25131 54 | 175.16228 276.83403 55 | 87.271676 260.11758 56 | -------------------------------------------------------------------------------- /ExampleData/Data/2.dat: -------------------------------------------------------------------------------- 1 | 2158.9981,2350.2286 2 | 2158.9981,3245.4557 3 | -1042.9463,3245.4557 4 | -1042.9463,2496.1895 5 | 91.149593,800.20639 6 | 441.75649,251.73749 7 | 648.06929,-97.04991 8 | 765.46219,-332.30851 9 | 849.31479,-540.20071 10 | 899.62689,-720.72671 11 | 916.39869,-873.88651 12 | 896.13819,-1060.7944 13 | 835.35969,-1193.3788 14 | 789.54889,-1239.4959 15 | 733.15879,-1272.4376 16 | 666.18939,-1292.204 17 | 588.64059,-1298.7951 18 | 511.08979,-1291.4964 19 | 444.11959,-1269.6012 20 | 387.73029,-1233.1107 21 | 341.92169,-1182.0263 22 | 306.46619,-1109.2461 23 | 281.14119,-1007.6808 24 | 260.88259,-718.19491 25 | 260.88259,-218.68401 26 | -1042.9463,-218.68401 27 | -1042.9463,-410.05511 28 | -1030.3404,-804.55201 29 | -992.52205,-1105.8022 30 | -958.08057,-1232.6032 31 | -905.18018,-1358.3923 32 | -833.82067,-1483.1695 33 | -744.00213,-1606.9348 34 | -637.5262,-1722.6871 35 | -516.1928,-1823.4397 36 | -380.00205,-1909.1927 37 | -228.95374,-1979.9461 38 | -62.599167,-2035.2866 39 | 119.51329,-2074.8167 40 | 317.38399,-2098.5364 41 | 531.01279,-2106.4456 42 | 938.57049,-2082.2155 43 | 1122.512,-2051.9328 44 | 1293.2285,-2009.5383 45 | 1450.7202,-1955.0316 46 | 1594.987,-1888.4129 47 | 1726.0289,-1809.6817 48 | 1843.846,-1718.8382 49 | 2038.4505,-1512.159 50 | 2177.4543,-1279.7356 51 | 2260.8578,-1021.5681 52 | 2288.6606,-737.65631 53 | 2273.0151,-508.98211 54 | 2226.0792,-273.82221 55 | 2147.8538,-32.17651 56 | 2038.3398,215.95519 57 | 1852.2859,537.88159 58 | 1544.4495,1000.9025 59 | 1114.8304,1605.018 60 | 563.42839,2350.2286 61 | -------------------------------------------------------------------------------- /Debug/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Debug")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Poly2Tri Contributors")] 12 | [assembly: AssemblyProduct("Debug")] 13 | [assembly: AssemblyCopyright("Copyright © Poly2Tri Contributors 2009-2010")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("87dc59e4-c17c-4c6c-8213-29363a9b3c15")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Poly2Tri")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Poly2Tri Contributors")] 12 | [assembly: AssemblyProduct("Poly2Tri")] 13 | [assembly: AssemblyCopyright("Copyright © Poly2Tri Contributors 2009-2010")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("d1e24f2b-ea85-471a-af97-b431ca71b75c")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /SwfTest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SwfTest")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Poly2Tri Contributors")] 12 | [assembly: AssemblyProduct("SwfTest")] 13 | [assembly: AssemblyCopyright("Copyright © Poly2Tri Contributors 2009-2010")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("1f8738ba-9378-4efb-8872-8e134b6e3e5a")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ExampleData/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ExampleData")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Poly2Tri Contributors")] 12 | [assembly: AssemblyProduct("ExampleData")] 13 | [assembly: AssemblyCopyright("Copyright © Poly2Tri Contributors 2009-2010")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("8bec23ba-c906-4ad6-9e8c-33e01adcb629")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors 2 | http://code.google.com/p/poly2tri/ 3 | 4 | All rights reserved. 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | * Neither the name of Poly2Tri nor the names of its contributors may be 14 | used to endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 21 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /Triangulation/Orientation.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | namespace Poly2Tri { 33 | public enum Orientation { 34 | CW, CCW, Collinear 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Triangulation/TriangulationAlgorithm.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | namespace Poly2Tri { 33 | public enum TriangulationAlgorithm { 34 | DTSweep 35 | } 36 | } -------------------------------------------------------------------------------- /Triangulation/TriangulationMode.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | namespace Poly2Tri { 33 | public enum TriangulationMode { 34 | Unconstrained,Constrained,Polygon 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Triangulation/Delaunay/Sweep/DTSweepEdgeEvent.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /// Changes from the Java version 33 | /// Turned DTSweepEdgeEvent into a value type 34 | 35 | namespace Poly2Tri { 36 | public class DTSweepEdgeEvent { 37 | public DTSweepConstraint ConstrainedEdge; 38 | public bool Right; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Triangulation/Delaunay/Sweep/DTSweepBasin.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | namespace Poly2Tri { 33 | public class DTSweepBasin { 34 | public AdvancingFrontNode leftNode; 35 | public AdvancingFrontNode bottomNode; 36 | public AdvancingFrontNode rightNode; 37 | public double width; 38 | public bool leftHighest; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Triangulation/TriangulationDebugContext.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | namespace Poly2Tri { 33 | public abstract class TriangulationDebugContext { 34 | protected TriangulationContext _tcx; 35 | 36 | public TriangulationDebugContext(TriangulationContext tcx) { 37 | _tcx = tcx; 38 | } 39 | 40 | public abstract void Clear(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Triangulation/Delaunay/Sweep/PointOnEdgeException.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System; 33 | 34 | namespace Poly2Tri { 35 | public class PointOnEdgeException : NotImplementedException { 36 | public readonly TriangulationPoint A,B,C; 37 | 38 | public PointOnEdgeException( string message, TriangulationPoint a, TriangulationPoint b, TriangulationPoint c ) 39 | : base(message) 40 | { 41 | A=a; 42 | B=b; 43 | C=c; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Triangulation/TriangulationConstraint.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * Forces a triangle edge between two points p and q 33 | * when triangulating. For example used to enforce 34 | * Polygon Edges during a polygon triangulation. 35 | * 36 | * @author Thomas Åhlén, thahlen@gmail.com 37 | */ 38 | 39 | namespace Poly2Tri { 40 | public class TriangulationConstraint { 41 | public TriangulationPoint P; 42 | public TriangulationPoint Q; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Polygon/PolygonPoint.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /// Changes from the Java version 33 | /// Replaced get/set Next/Previous with attributes 34 | /// Future possibilities 35 | /// Documentation! 36 | 37 | namespace Poly2Tri { 38 | public class PolygonPoint : TriangulationPoint { 39 | public PolygonPoint( double x, double y, int index = INSERTED_INDEX ) : base(x, y, index) { } 40 | 41 | public PolygonPoint Next { get; set; } 42 | public PolygonPoint Previous { get; set; } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /ExampleData/Data/dude.dat: -------------------------------------------------------------------------------- 1 | 280.35714 648.79075 2 | 286.78571 662.8979 3 | 263.28607 661.17871 4 | 262.31092 671.41548 5 | 250.53571 677.00504 6 | 250.53571 683.43361 7 | 256.42857 685.21933 8 | 297.14286 669.50504 9 | 289.28571 649.50504 10 | 285 631.6479 11 | 285 608.79075 12 | 292.85714 585.21932 13 | 306.42857 563.79075 14 | 323.57143 548.79075 15 | 339.28571 545.21932 16 | 357.85714 547.36218 17 | 375 550.21932 18 | 391.42857 568.07647 19 | 404.28571 588.79075 20 | 413.57143 612.36218 21 | 417.14286 628.07647 22 | 438.57143 619.1479 23 | 438.03572 618.96932 24 | 437.5 609.50504 25 | 426.96429 609.86218 26 | 424.64286 615.57647 27 | 419.82143 615.04075 28 | 420.35714 605.04075 29 | 428.39286 598.43361 30 | 437.85714 599.68361 31 | 443.57143 613.79075 32 | 450.71429 610.21933 33 | 431.42857 575.21932 34 | 405.71429 550.21932 35 | 372.85714 534.50504 36 | 349.28571 531.6479 37 | 346.42857 521.6479 38 | 346.42857 511.6479 39 | 350.71429 496.6479 40 | 367.85714 476.6479 41 | 377.14286 460.93361 42 | 385.71429 445.21932 43 | 388.57143 404.50504 44 | 360 352.36218 45 | 337.14286 325.93361 46 | 330.71429 334.50504 47 | 347.14286 354.50504 48 | 337.85714 370.21932 49 | 333.57143 359.50504 50 | 319.28571 353.07647 51 | 312.85714 366.6479 52 | 350.71429 387.36218 53 | 368.57143 408.07647 54 | 375.71429 431.6479 55 | 372.14286 454.50504 56 | 366.42857 462.36218 57 | 352.85714 462.36218 58 | 336.42857 456.6479 59 | 332.85714 438.79075 60 | 338.57143 423.79075 61 | 338.57143 411.6479 62 | 327.85714 405.93361 63 | 320.71429 407.36218 64 | 315.71429 423.07647 65 | 314.28571 440.21932 66 | 325 447.71932 67 | 324.82143 460.93361 68 | 317.85714 470.57647 69 | 304.28571 483.79075 70 | 287.14286 491.29075 71 | 263.03571 498.61218 72 | 251.60714 503.07647 73 | 251.25 533.61218 74 | 260.71429 533.61218 75 | 272.85714 528.43361 76 | 286.07143 518.61218 77 | 297.32143 508.25504 78 | 297.85714 507.36218 79 | 298.39286 506.46932 80 | 307.14286 496.6479 81 | 312.67857 491.6479 82 | 317.32143 503.07647 83 | 322.5 514.1479 84 | 325.53571 521.11218 85 | 327.14286 525.75504 86 | 326.96429 535.04075 87 | 311.78571 540.04075 88 | 291.07143 552.71932 89 | 274.82143 568.43361 90 | 259.10714 592.8979 91 | 254.28571 604.50504 92 | 251.07143 621.11218 93 | 250.53571 649.1479 94 | 268.1955 654.36208 95 | -------------------------------------------------------------------------------- /Triangulation/ITriangulatable.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System.Collections.Generic; 33 | 34 | namespace Poly2Tri { 35 | public interface Triangulatable { 36 | void Prepare(TriangulationContext tcx); 37 | 38 | IList Points { get; } // MM: Neither of these are used via interface (yet?) 39 | IList Triangles { get; } 40 | 41 | void AddTriangle(DelaunayTriangle t); 42 | void AddTriangles(IEnumerable list); 43 | void ClearTriangles(); 44 | 45 | TriangulationMode TriangulationMode { get; } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Triangulation/Delaunay/Sweep/DTSweepPointComparator.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System.Collections.Generic; 33 | 34 | namespace Poly2Tri { 35 | public class DTSweepPointComparator : IComparer { 36 | public int Compare(TriangulationPoint p1, TriangulationPoint p2) { 37 | if (p1.Y < p2.Y) { 38 | return -1; 39 | } else if (p1.Y > p2.Y) { 40 | return 1; 41 | } else { 42 | if (p1.X < p2.X) { 43 | return -1; 44 | } else if (p1.X > p2.X) { 45 | return 1; 46 | } else { 47 | return 0; 48 | } 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Polygon/PolygonSet.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /// Changes from the Java version 33 | /// Replaced getPolygons with attribute 34 | /// Future possibilities 35 | /// Replace Add(Polygon) with exposed container? 36 | /// Replace entire class with HashSet ? 37 | 38 | using System.Collections.Generic; 39 | 40 | namespace Poly2Tri { 41 | public class PolygonSet { 42 | protected List _polygons = new List(); 43 | 44 | public PolygonSet() {} 45 | 46 | public PolygonSet(Polygon poly) { 47 | _polygons.Add(poly); 48 | } 49 | 50 | public void Add(Polygon p) { 51 | _polygons.Add(p); 52 | } 53 | 54 | public IEnumerable Polygons { get { return _polygons; } } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Triangulation/Delaunay/Sweep/AdvancingFrontNode.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /// Changes from the Java version 33 | /// Removed getters 34 | /// Has* turned into attributes 35 | /// Future possibilities 36 | /// Comments! 37 | 38 | namespace Poly2Tri { 39 | public class AdvancingFrontNode { 40 | public AdvancingFrontNode Next; 41 | public AdvancingFrontNode Prev; 42 | public double Value; 43 | public TriangulationPoint Point; 44 | public DelaunayTriangle Triangle; 45 | 46 | public AdvancingFrontNode(TriangulationPoint point) { 47 | this.Point = point; 48 | Value = point.X; 49 | } 50 | 51 | public bool HasNext { get { return Next != null; } } 52 | public bool HasPrev { get { return Prev != null; } } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ExampleData/Data/funny.dat: -------------------------------------------------------------------------------- 1 | 100.317505 0.0 2 | 146.29202 9.203914 3 | 129.52948 16.363379 4 | 95.36635 18.192104 5 | 88.769775 22.792204 6 | 102.68762 33.36523 7 | 142.4203 56.388184 8 | 132.23712 62.22607 9 | 134.04555 73.69216 10 | 121.24752 76.946014 11 | 140.18803 101.85256 12 | 124.024445 102.601944 13 | 119.727 112.43114 14 | 144.82764 154.22577 15 | 155.76044 188.28203 16 | 146.94632 202.25424 17 | 133.9567 211.08199 18 | 120.438416 219.07668 19 | 103.53854 220.03061 20 | 90.72225 229.13826 21 | 77.25425 237.76413 22 | 54.851055 213.63075 23 | 46.84533 245.57181 24 | 31.33331 248.02867 25 | 15.69763 249.50668 26 | 1.5308084E-14 250.0 27 | -13.490268 214.42166 28 | -29.863472 236.39372 29 | -44.794296 234.81993 30 | -50.172047 195.40721 31 | -69.351425 213.44174 32 | -75.72414 191.25734 33 | -96.03964 204.09464 34 | -120.438416 219.07668 35 | -127.11785 200.30568 36 | -119.31813 164.22733 37 | -130.35721 157.57478 38 | -112.00853 119.27697 39 | -142.68515 133.99026 40 | -117.65654 97.333954 41 | -125.62218 91.26986 42 | -114.24053 72.499245 43 | -160.95981 88.4884 44 | -138.49583 65.171196 45 | -102.99021 40.776707 46 | -141.48434 45.97105 47 | -97.90232 25.137043 48 | -116.9116 22.30208 49 | -145.58727 18.391949 50 | -183.83247 11.565759 51 | -190.12851 2.3284026E-14 52 | -157.68095 -9.9204445 53 | -186.18002 -23.520008 54 | -160.72182 -30.659325 55 | -143.63857 -36.880116 56 | -143.12222 -46.50323 57 | -98.59685 -39.037254 58 | -86.89141 -40.887993 59 | -83.81993 -46.0804 60 | -42.216396 -26.79134 61 | -40.45085 -29.389263 62 | -38.52566 -31.871199 63 | -46.53258 -43.697002 64 | -34.227356 -36.448433 65 | -38.017994 -45.95586 66 | -29.389263 -40.45085 67 | -26.79134 -42.216396 68 | -31.430187 -57.1713 69 | -22.040213 -46.837833 70 | -27.75829 -70.109436 71 | -26.90105 -82.79292 72 | -13.713537 -53.4107 73 | -10.41509 -54.59781 74 | -6.2666616 -49.605736 75 | -3.139526 -49.901337 76 | -9.184851E-15 -50.0 77 | 3.5057213 -55.721844 78 | 6.2666616 -49.605736 79 | 14.274147 -74.8277 80 | 19.75647 -76.946365 81 | 24.69724 -76.01029 82 | 24.807446 -62.656456 83 | 28.282286 -60.102917 84 | 37.102608 -67.489395 85 | 51.878616 -81.74762 86 | 46.092445 -63.440807 87 | 34.334026 -41.502712 88 | 34.227356 -36.448433 89 | 43.65427 -40.99409 90 | 38.52566 -31.871199 91 | 40.45085 -29.389263 92 | 42.216396 -26.79134 93 | 52.668476 -28.95474 94 | 86.38597 -40.650154 95 | 126.91717 -50.25006 96 | 83.21832 -27.039272 97 | 109.77473 -28.185358 98 | 105.45997 -20.117565 99 | 119.66038 -15.116621 100 | 74.30321 -4.674762 101 | -------------------------------------------------------------------------------- /Triangulation/Delaunay/Sweep/DTSweepConstraint.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | namespace Poly2Tri { 33 | public class DTSweepConstraint : TriangulationConstraint { 34 | /// 35 | /// Give two points in any order. Will always be ordered so 36 | /// that q.y > p.y and q.x > p.x if same y value 37 | /// 38 | public DTSweepConstraint( TriangulationPoint p1, TriangulationPoint p2 ) { 39 | P = p1; 40 | Q = p2; 41 | if (p1.Y > p2.Y) { 42 | Q = p1; 43 | P = p2; 44 | } else if (p1.Y == p2.Y) { 45 | if (p1.X > p2.X) { 46 | Q = p1; 47 | P = p2; 48 | } else if (p1.X == p2.X) { 49 | // logger.info( "Failed to create constraint {}={}", p1, p2 ); 50 | // throw new DuplicatePointException( p1 + "=" + p2 ); 51 | // return; 52 | } 53 | } 54 | Q.AddEdge(this); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Triangulation/Util/PointGenerator.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System; 33 | using System.Collections.Generic; 34 | 35 | namespace Poly2Tri { 36 | public class PointGenerator { 37 | static readonly Random RNG = new Random(); 38 | 39 | public static List UniformDistribution(int n, double scale) { 40 | List points = new List(); 41 | for (int i = 0; i < n; i++) points.Add(new TriangulationPoint(scale * (0.5 - RNG.NextDouble()), scale * (0.5 - RNG.NextDouble()), i)); 42 | return points; 43 | } 44 | 45 | public static List UniformGrid(int n, double scale) { 46 | double x = 0; 47 | double size = scale / n; 48 | double halfScale = 0.5 * scale; 49 | 50 | List points = new List(); 51 | for (int i = 0; i < n + 1; i++) { 52 | x = halfScale - i * size; 53 | for (int j = 0; j < n + 1; j++) points.Add(new TriangulationPoint(x, halfScale - j * size, i)); 54 | } 55 | return points; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Triangulation/Sets/ConstrainedPointSet.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System.Collections.Generic; 33 | namespace Poly2Tri { 34 | /* 35 | * Extends the PointSet by adding some Constraints on how it will be triangulated
36 | * A constraint defines an edge between two points in the set, these edges can not 37 | * be crossed. They will be enforced triangle edges after a triangulation. 38 | *

39 | * 40 | * 41 | * @author Thomas Åhlén, thahlen@gmail.com 42 | */ 43 | public class ConstrainedPointSet : PointSet { 44 | public int[] EdgeIndex { get; private set; } 45 | 46 | public ConstrainedPointSet(List points, int[] index) 47 | : base(points) { 48 | EdgeIndex = index; 49 | } 50 | 51 | public override TriangulationMode TriangulationMode { get { return TriangulationMode.Constrained; } } 52 | 53 | public override void Prepare(TriangulationContext tcx) { 54 | base.Prepare(tcx); 55 | for (int i = 0; i < EdgeIndex.Length; i += 2) { 56 | // XXX: must change!! 57 | tcx.NewConstraint(Points[EdgeIndex[i]], Points[EdgeIndex[i + 1]]); 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Triangulation/Sets/PointSet.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System.Collections.Generic; 33 | 34 | namespace Poly2Tri { 35 | public class PointSet : Triangulatable { 36 | public IList Points { get; private set; } 37 | public IList Triangles { get; private set; } 38 | 39 | public PointSet(List points) { 40 | Points = new List(points); 41 | } 42 | 43 | public virtual TriangulationMode TriangulationMode { get { return TriangulationMode.Unconstrained; }} 44 | 45 | public void AddTriangle(DelaunayTriangle t) { 46 | Triangles.Add(t); 47 | } 48 | 49 | public void AddTriangles(IEnumerable list) { 50 | foreach ( var tri in list ) Triangles.Add(tri); 51 | } 52 | 53 | public void ClearTriangles() { 54 | Triangles.Clear(); 55 | } 56 | 57 | public virtual void Prepare(TriangulationContext tcx) { 58 | if (Triangles == null) { 59 | Triangles = new List(Points.Count); 60 | } else { 61 | Triangles.Clear(); 62 | } 63 | tcx.Points.AddRange(Points); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Triangulation/TriangulationPoint.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System.Collections.Generic; 33 | 34 | namespace Poly2Tri { 35 | 36 | public class TriangulationPoint { 37 | 38 | // This point was an inserted index. 39 | public const int INSERTED_INDEX = -1; 40 | 41 | // This point is not a valid index. 42 | public const int INVALID_INDEX = -2; 43 | 44 | // List of edges this point constitutes an upper ending point (CDT) 45 | public List Edges { get; private set; } 46 | 47 | public TriangulationPoint( double x, double y, int index = INSERTED_INDEX) { X=x; Y=y; Index = index; } 48 | 49 | public override string ToString() { 50 | return "[" + X + "," + Y + "]"; 51 | } 52 | 53 | public double X,Y; 54 | public int Index; 55 | public float Xf { get { return (float)X; } set { X=value; } } 56 | public float Yf { get { return (float)Y; } set { Y=value; } } 57 | 58 | public void AddEdge(DTSweepConstraint e) { 59 | if (Edges == null) Edges = new List(); 60 | Edges.Add(e); 61 | } 62 | 63 | public bool HasEdges { get { return Edges != null; } } 64 | } 65 | } -------------------------------------------------------------------------------- /ExampleData/Data/Pointsets/example1.dat: -------------------------------------------------------------------------------- 1 | 983.000000 31.000000 2 | 960.000000 52.000000 3 | 62.000000 63.000000 4 | 173.000000 66.000000 5 | 1938.000000 76.000000 6 | 216.000000 162.000000 7 | 943.000000 162.000000 8 | 1724.000000 189.000000 9 | 1754.000000 196.000000 10 | 1788.000000 196.000000 11 | 1159.000000 217.000000 12 | 281.000000 223.000000 13 | 1917.000000 243.000000 14 | 1499.000000 285.000000 15 | 554.000000 299.000000 16 | 152.000000 302.000000 17 | 766.000000 317.000000 18 | 1575.000000 341.000000 19 | 1726.000000 350.000000 20 | 697.000000 379.000000 21 | 1232.000000 386.000000 22 | 381.000000 387.000000 23 | 1869.000000 400.000000 24 | 334.000000 455.000000 25 | 1882.000000 465.000000 26 | 125.000000 468.000000 27 | 279.000000 495.000000 28 | 1020.000000 508.000000 29 | 638.000000 515.000000 30 | 1927.000000 520.000000 31 | 824.000000 532.000000 32 | 1620.000000 545.000000 33 | 552.000000 584.000000 34 | 1367.000000 588.000000 35 | 572.000000 624.000000 36 | 1215.000000 633.000000 37 | 375.000000 655.000000 38 | 1594.000000 684.000000 39 | 1043.000000 703.000000 40 | 935.000000 707.000000 41 | 1151.000000 716.000000 42 | 1616.000000 728.000000 43 | 509.000000 732.000000 44 | 295.000000 793.000000 45 | 1928.000000 802.000000 46 | 1745.000000 802.000000 47 | 26.000000 803.000000 48 | 1395.000000 836.000000 49 | 1194.000000 866.000000 50 | 185.000000 917.000000 51 | 1955.000000 929.000000 52 | 1905.000000 962.000000 53 | 1827.000000 990.000000 54 | 1414.000000 1014.000000 55 | 1598.000000 1064.000000 56 | 410.000000 1133.000000 57 | 1551.000000 1156.000000 58 | 958.000000 1204.000000 59 | 1239.000000 1210.000000 60 | 1259.000000 1224.000000 61 | 211.000000 1227.000000 62 | 1124.000000 1228.000000 63 | 640.000000 1354.000000 64 | 1547.000000 1382.000000 65 | 787.000000 1383.000000 66 | 1981.000000 1429.000000 67 | 579.000000 1447.000000 68 | 171.000000 1482.000000 69 | 778.000000 1511.000000 70 | 1161.000000 1533.000000 71 | 1602.000000 1549.000000 72 | 501.000000 1601.000000 73 | 1981.000000 1617.000000 74 | 1016.000000 1633.000000 75 | 169.000000 1648.000000 76 | 1641.000000 1668.000000 77 | 1314.000000 1673.000000 78 | 1888.000000 1698.000000 79 | 1364.000000 1701.000000 80 | 516.000000 1705.000000 81 | 233.000000 1707.000000 82 | 1335.000000 1717.000000 83 | 1175.000000 1733.000000 84 | 554.000000 1734.000000 85 | 1516.000000 1739.000000 86 | 765.000000 1744.000000 87 | 395.000000 1749.000000 88 | 1483.000000 1757.000000 89 | 900.000000 1771.000000 90 | 383.000000 1841.000000 91 | 35.000000 1863.000000 92 | 99.000000 1875.000000 93 | 634.000000 1897.000000 94 | 1903.000000 1899.000000 95 | 402.000000 1907.000000 96 | 1092.000000 1935.000000 97 | 151.000000 1954.000000 98 | 1649.000000 1965.000000 99 | 1982.000000 1976.000000 100 | 232.000000 1995.000000 -------------------------------------------------------------------------------- /Debug/PolygonInfo.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System; 33 | using System.Linq; 34 | 35 | namespace Poly2Tri { 36 | class PolygonInfo { 37 | public string Name { get; private set; } 38 | public TimeSpan LastTriangulationDuration { get; private set; } 39 | public Exception LastTriangulationException { get; private set; } 40 | 41 | public Polygon Polygon { get; private set; } 42 | 43 | public PolygonInfo( string name, Polygon polygon ) { 44 | Name = name; 45 | Polygon = polygon; 46 | Triangulate(); 47 | } 48 | 49 | static Polygon CleanClone( Polygon polygon ) { 50 | var n = new Polygon(polygon.Points.Select( p => new PolygonPoint(p.X,p.Y) ) ); 51 | if ( polygon.Holes!=null ) foreach ( var hole in polygon.Holes ) n.AddHole(CleanClone(hole)); 52 | return n; 53 | } 54 | 55 | public void Triangulate() { 56 | var start = DateTime.Now; 57 | try { 58 | LastTriangulationException = null; 59 | var newpoly = CleanClone(Polygon); 60 | P2T.Triangulate(newpoly); 61 | Polygon = newpoly; 62 | } catch ( Exception e ) { 63 | LastTriangulationException = e; 64 | } 65 | var stop = DateTime.Now; 66 | LastTriangulationDuration = (stop-start); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Utility/FixedArray3.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System; 33 | using System.Collections; 34 | using System.Collections.Generic; 35 | 36 | namespace Poly2Tri { 37 | public struct FixedArray3 : IEnumerable where T:class { 38 | public T _0, _1, _2; 39 | public T this[ int index ] { get { 40 | switch ( index ) { 41 | case 0: return _0; 42 | case 1: return _1; 43 | case 2: return _2; 44 | default: throw new IndexOutOfRangeException(); 45 | } 46 | } set { 47 | switch ( index ) { 48 | case 0: _0 = value; break; 49 | case 1: _1 = value; break; 50 | case 2: _2 = value; break; 51 | default: throw new IndexOutOfRangeException(); 52 | } 53 | }} 54 | public bool Contains( T value ) { 55 | for ( int i = 0 ; i < 3 ; ++i ) if ( this[i]==value ) return true; 56 | return false; 57 | } 58 | public int IndexOf( T value ) { 59 | for ( int i = 0 ; i < 3 ; ++i ) if ( this[i]==value ) return i; 60 | return -1; 61 | } 62 | public void Clear() { 63 | _0=_1=_2=null; 64 | } 65 | public void Clear( T value ) { 66 | for ( int i = 0 ; i < 3 ; ++i ) if ( this[i]==value ) this[i] = null; 67 | } 68 | 69 | private IEnumerable Enumerate() { 70 | for ( int i=0 ; i<3 ; ++i ) yield return this[i]; 71 | } 72 | public IEnumerator GetEnumerator() { return Enumerate().GetEnumerator(); } 73 | IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Triangulation/TriangulationContext.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System.Collections.Generic; 33 | 34 | namespace Poly2Tri { 35 | public abstract class TriangulationContext { 36 | public TriangulationDebugContext DebugContext { get; protected set; } 37 | 38 | public readonly List Triangles = new List(); 39 | public readonly List Points = new List(200); 40 | public TriangulationMode TriangulationMode { get; protected set; } 41 | public Triangulatable Triangulatable { get; private set; } 42 | 43 | public int StepCount { get; private set; } 44 | 45 | public void Done() { 46 | StepCount++; 47 | } 48 | 49 | public abstract TriangulationAlgorithm Algorithm { get; } 50 | 51 | public virtual void PrepareTriangulation(Triangulatable t) { 52 | Triangulatable = t; 53 | TriangulationMode = t.TriangulationMode; 54 | t.Prepare(this); 55 | } 56 | 57 | public abstract TriangulationConstraint NewConstraint(TriangulationPoint a, TriangulationPoint b); 58 | 59 | public void Update(string message) {} 60 | 61 | public virtual void Clear() { 62 | Points.Clear(); 63 | if (DebugContext != null) DebugContext.Clear(); 64 | StepCount = 0; 65 | } 66 | 67 | public virtual bool IsDebugEnabled { get; protected set; } 68 | 69 | public DTSweepDebugContext DTDebugContext { get { return DebugContext as DTSweepDebugContext; } } 70 | } 71 | } -------------------------------------------------------------------------------- /Utility/FixedBitArray3.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System; 33 | using System.Collections; 34 | using System.Collections.Generic; 35 | 36 | namespace Poly2Tri { 37 | public struct FixedBitArray3 : IEnumerable { 38 | public bool _0, _1, _2; 39 | public bool this[ int index ] { get { 40 | switch ( index ) { 41 | case 0: return _0; 42 | case 1: return _1; 43 | case 2: return _2; 44 | default: throw new IndexOutOfRangeException(); 45 | } 46 | } set { 47 | switch ( index ) { 48 | case 0: _0 = value; break; 49 | case 1: _1 = value; break; 50 | case 2: _2 = value; break; 51 | default: throw new IndexOutOfRangeException(); 52 | } 53 | }} 54 | public bool Contains( bool value ) { 55 | for ( int i = 0 ; i < 3 ; ++i ) if ( this[i]==value ) return true; 56 | return false; 57 | } 58 | public int IndexOf( bool value ) { 59 | for ( int i = 0 ; i < 3 ; ++i ) if ( this[i]==value ) return i; 60 | return -1; 61 | } 62 | public void Clear() { 63 | _0=_1=_2=false; 64 | } 65 | public void Clear( bool value ) { 66 | for ( int i = 0 ; i < 3 ; ++i ) if ( this[i]==value ) this[i] = false; 67 | } 68 | 69 | private IEnumerable Enumerate() { 70 | for ( int i=0 ; i<3 ; ++i ) yield return this[i]; 71 | } 72 | public IEnumerator GetEnumerator() { return Enumerate().GetEnumerator(); } 73 | IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Triangulation/Delaunay/Sweep/DTSweepDebugContext.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | namespace Poly2Tri { 33 | public class DTSweepDebugContext : TriangulationDebugContext { 34 | /* 35 | * Fields used for visual representation of current triangulation 36 | */ 37 | 38 | public DelaunayTriangle PrimaryTriangle { get { return _primaryTriangle ; } set { _primaryTriangle = value; _tcx.Update("set PrimaryTriangle"); } } 39 | public DelaunayTriangle SecondaryTriangle { get { return _secondaryTriangle; } set { _secondaryTriangle = value; _tcx.Update("set SecondaryTriangle"); } } 40 | public TriangulationPoint ActivePoint { get { return _activePoint ; } set { _activePoint = value; _tcx.Update("set ActivePoint"); } } 41 | public AdvancingFrontNode ActiveNode { get { return _activeNode ; } set { _activeNode = value; _tcx.Update("set ActiveNode"); } } 42 | public DTSweepConstraint ActiveConstraint { get { return _activeConstraint ; } set { _activeConstraint = value; _tcx.Update("set ActiveConstraint"); } } 43 | 44 | public DTSweepDebugContext( DTSweepContext tcx ) : base(tcx) { } 45 | 46 | public bool IsDebugContext { get { return true; } } 47 | 48 | public override void Clear() { 49 | PrimaryTriangle = null; 50 | SecondaryTriangle = null; 51 | ActivePoint = null; 52 | ActiveNode = null; 53 | ActiveConstraint = null; 54 | } 55 | 56 | private DelaunayTriangle _primaryTriangle; 57 | private DelaunayTriangle _secondaryTriangle; 58 | private TriangulationPoint _activePoint; 59 | private AdvancingFrontNode _activeNode; 60 | private DTSweepConstraint _activeConstraint; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Triangulation/Util/PolygonGenerator.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System; 33 | 34 | namespace Poly2Tri { 35 | public class PolygonGenerator { 36 | static readonly Random RNG = new Random(); 37 | 38 | private static double PI_2 = 2.0 * Math.PI; 39 | 40 | public static Polygon RandomCircleSweep(double scale, int vertexCount) { 41 | PolygonPoint point; 42 | PolygonPoint[] points; 43 | double radius = scale / 4; 44 | 45 | points = new PolygonPoint[vertexCount]; 46 | for (int i = 0; i < vertexCount; i++) { 47 | do { 48 | if (i % 250 == 0) { 49 | radius += scale / 2 * (0.5 - RNG.NextDouble()); 50 | } else if (i % 50 == 0) { 51 | radius += scale / 5 * (0.5 - RNG.NextDouble()); 52 | } else { 53 | radius += 25 * scale / vertexCount * (0.5 - RNG.NextDouble()); 54 | } 55 | radius = radius > scale / 2 ? scale / 2 : radius; 56 | radius = radius < scale / 10 ? scale / 10 : radius; 57 | } while (radius < scale / 10 || radius > scale / 2); 58 | point = new PolygonPoint(radius * Math.Cos((PI_2 * i) / vertexCount), 59 | radius * Math.Sin((PI_2 * i) / vertexCount), i); 60 | points[i] = point; 61 | } 62 | return new Polygon(points); 63 | } 64 | 65 | public static Polygon RandomCircleSweep2(double scale, int vertexCount) { 66 | PolygonPoint point; 67 | PolygonPoint[] points; 68 | double radius = scale / 4; 69 | 70 | points = new PolygonPoint[vertexCount]; 71 | for (int i = 0; i < vertexCount; i++) { 72 | do { 73 | radius += scale / 5 * (0.5 - RNG.NextDouble()); 74 | radius = radius > scale / 2 ? scale / 2 : radius; 75 | radius = radius < scale / 10 ? scale / 10 : radius; 76 | } while (radius < scale / 10 || radius > scale / 2); 77 | point = new PolygonPoint(radius * Math.Cos((PI_2 * i) / vertexCount), 78 | radius * Math.Sin((PI_2 * i) / vertexCount), i); 79 | points[i] = point; 80 | } 81 | return new Polygon(points); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /SwfTest/SwfTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.30729 7 | 2.0 8 | {AA9A76CB-40AD-49F5-BD67-EFB4E529A7D8} 9 | WinExe 10 | Properties 11 | SwfTest 12 | SwfTest 13 | v3.5 14 | 512 15 | 16 | 17 | 18 | 19 | 3.5 20 | 21 | 22 | true 23 | full 24 | false 25 | bin\Debug\ 26 | DEBUG;TRACE 27 | prompt 28 | 4 29 | 30 | 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | 38 | 39 | true 40 | bin\x86\Debug\ 41 | DEBUG;TRACE 42 | full 43 | x86 44 | prompt 45 | 46 | 47 | bin\x86\Release\ 48 | TRACE 49 | true 50 | pdbonly 51 | x86 52 | prompt 53 | 54 | 55 | 56 | 57 | 3.5 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | {FC6F045E-7112-44BF-A491-99D987D9C6D2} 69 | ExampleData 70 | 71 | 72 | {C5E5802D-6A45-4FE9-BAE7-5F0AE91D72C1} 73 | Poly2Tri 74 | 75 | 76 | 77 | 84 | -------------------------------------------------------------------------------- /Debug/Debug.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.30729 7 | 2.0 8 | {D4FE7CE8-E032-4D57-993A-048651FA8872} 9 | WinExe 10 | Properties 11 | Poly2Tri 12 | Debug 13 | v3.5 14 | 512 15 | 16 | 17 | 18 | 19 | 3.5 20 | 21 | 22 | true 23 | full 24 | false 25 | bin\Debug\ 26 | DEBUG;TRACE 27 | prompt 28 | 4 29 | 30 | 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | 38 | 39 | true 40 | bin\x86\Debug\ 41 | DEBUG;TRACE 42 | full 43 | x86 44 | prompt 45 | 46 | 47 | bin\x86\Release\ 48 | TRACE 49 | true 50 | pdbonly 51 | x86 52 | prompt 53 | 54 | 55 | 56 | 57 | 3.5 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | {FC6F045E-7112-44BF-A491-99D987D9C6D2} 73 | ExampleData 74 | 75 | 76 | {C5E5802D-6A45-4FE9-BAE7-5F0AE91D72C1} 77 | Poly2Tri 78 | 79 | 80 | 81 | 88 | -------------------------------------------------------------------------------- /Poly2Tri.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{976C79A3-D387-4C65-9558-E454F8890021}" 7 | ProjectSection(SolutionItems) = preProject 8 | AUTHORS.txt = AUTHORS.txt 9 | LICENSE.txt = LICENSE.txt 10 | README.txt = README.txt 11 | EndProjectSection 12 | EndProject 13 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Poly2Tri", "Poly2Tri.csproj", "{C5E5802D-6A45-4FE9-BAE7-5F0AE91D72C1}" 14 | EndProject 15 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SwfTest", "SwfTest\SwfTest.csproj", "{AA9A76CB-40AD-49F5-BD67-EFB4E529A7D8}" 16 | EndProject 17 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleData", "ExampleData\ExampleData.csproj", "{FC6F045E-7112-44BF-A491-99D987D9C6D2}" 18 | EndProject 19 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Debug", "Debug\Debug.csproj", "{D4FE7CE8-E032-4D57-993A-048651FA8872}" 20 | EndProject 21 | Global 22 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 23 | Debug|Any CPU = Debug|Any CPU 24 | Debug|x86 = Debug|x86 25 | Release|Any CPU = Release|Any CPU 26 | Release|x86 = Release|x86 27 | EndGlobalSection 28 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 29 | {C5E5802D-6A45-4FE9-BAE7-5F0AE91D72C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 30 | {C5E5802D-6A45-4FE9-BAE7-5F0AE91D72C1}.Debug|Any CPU.Build.0 = Debug|Any CPU 31 | {C5E5802D-6A45-4FE9-BAE7-5F0AE91D72C1}.Debug|x86.ActiveCfg = Debug|x86 32 | {C5E5802D-6A45-4FE9-BAE7-5F0AE91D72C1}.Debug|x86.Build.0 = Debug|x86 33 | {C5E5802D-6A45-4FE9-BAE7-5F0AE91D72C1}.Release|Any CPU.ActiveCfg = Release|Any CPU 34 | {C5E5802D-6A45-4FE9-BAE7-5F0AE91D72C1}.Release|Any CPU.Build.0 = Release|Any CPU 35 | {C5E5802D-6A45-4FE9-BAE7-5F0AE91D72C1}.Release|x86.ActiveCfg = Release|x86 36 | {C5E5802D-6A45-4FE9-BAE7-5F0AE91D72C1}.Release|x86.Build.0 = Release|x86 37 | {AA9A76CB-40AD-49F5-BD67-EFB4E529A7D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 38 | {AA9A76CB-40AD-49F5-BD67-EFB4E529A7D8}.Debug|Any CPU.Build.0 = Debug|Any CPU 39 | {AA9A76CB-40AD-49F5-BD67-EFB4E529A7D8}.Debug|x86.ActiveCfg = Debug|x86 40 | {AA9A76CB-40AD-49F5-BD67-EFB4E529A7D8}.Debug|x86.Build.0 = Debug|x86 41 | {AA9A76CB-40AD-49F5-BD67-EFB4E529A7D8}.Release|Any CPU.ActiveCfg = Release|Any CPU 42 | {AA9A76CB-40AD-49F5-BD67-EFB4E529A7D8}.Release|Any CPU.Build.0 = Release|Any CPU 43 | {AA9A76CB-40AD-49F5-BD67-EFB4E529A7D8}.Release|x86.ActiveCfg = Release|x86 44 | {AA9A76CB-40AD-49F5-BD67-EFB4E529A7D8}.Release|x86.Build.0 = Release|x86 45 | {FC6F045E-7112-44BF-A491-99D987D9C6D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 46 | {FC6F045E-7112-44BF-A491-99D987D9C6D2}.Debug|Any CPU.Build.0 = Debug|Any CPU 47 | {FC6F045E-7112-44BF-A491-99D987D9C6D2}.Debug|x86.ActiveCfg = Debug|x86 48 | {FC6F045E-7112-44BF-A491-99D987D9C6D2}.Debug|x86.Build.0 = Debug|x86 49 | {FC6F045E-7112-44BF-A491-99D987D9C6D2}.Release|Any CPU.ActiveCfg = Release|Any CPU 50 | {FC6F045E-7112-44BF-A491-99D987D9C6D2}.Release|Any CPU.Build.0 = Release|Any CPU 51 | {FC6F045E-7112-44BF-A491-99D987D9C6D2}.Release|x86.ActiveCfg = Release|x86 52 | {FC6F045E-7112-44BF-A491-99D987D9C6D2}.Release|x86.Build.0 = Release|x86 53 | {D4FE7CE8-E032-4D57-993A-048651FA8872}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 54 | {D4FE7CE8-E032-4D57-993A-048651FA8872}.Debug|Any CPU.Build.0 = Debug|Any CPU 55 | {D4FE7CE8-E032-4D57-993A-048651FA8872}.Debug|x86.ActiveCfg = Debug|x86 56 | {D4FE7CE8-E032-4D57-993A-048651FA8872}.Debug|x86.Build.0 = Debug|x86 57 | {D4FE7CE8-E032-4D57-993A-048651FA8872}.Release|Any CPU.ActiveCfg = Release|Any CPU 58 | {D4FE7CE8-E032-4D57-993A-048651FA8872}.Release|Any CPU.Build.0 = Release|Any CPU 59 | {D4FE7CE8-E032-4D57-993A-048651FA8872}.Release|x86.ActiveCfg = Release|x86 60 | {D4FE7CE8-E032-4D57-993A-048651FA8872}.Release|x86.Build.0 = Release|x86 61 | EndGlobalSection 62 | GlobalSection(SolutionProperties) = preSolution 63 | HideSolutionNode = FALSE 64 | EndGlobalSection 65 | EndGlobal 66 | -------------------------------------------------------------------------------- /P2T.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | namespace Poly2Tri { 33 | public static class P2T { 34 | private static TriangulationAlgorithm _defaultAlgorithm = TriangulationAlgorithm.DTSweep; 35 | 36 | public static void Triangulate(PolygonSet ps) { 37 | TriangulationContext tcx = CreateContext(_defaultAlgorithm); 38 | foreach (Polygon p in ps.Polygons) { 39 | tcx.PrepareTriangulation(p); 40 | Triangulate(tcx); 41 | tcx.Clear(); 42 | } 43 | } 44 | 45 | public static void Triangulate(Polygon p) { 46 | Triangulate(_defaultAlgorithm, p); 47 | } 48 | 49 | public static void Triangulate(ConstrainedPointSet cps) { 50 | Triangulate(_defaultAlgorithm, cps); 51 | } 52 | 53 | public static void Triangulate(PointSet ps) { 54 | Triangulate(_defaultAlgorithm, ps); 55 | } 56 | 57 | public static TriangulationContext CreateContext(TriangulationAlgorithm algorithm) { 58 | switch (algorithm) { 59 | case TriangulationAlgorithm.DTSweep: 60 | default: 61 | return new DTSweepContext(); 62 | } 63 | } 64 | 65 | public static void Triangulate(TriangulationAlgorithm algorithm, Triangulatable t) { 66 | TriangulationContext tcx; 67 | 68 | // long time = System.nanoTime(); 69 | tcx = CreateContext(algorithm); 70 | tcx.PrepareTriangulation(t); 71 | Triangulate(tcx); 72 | // logger.info( "Triangulation of {} points [{}ms]", tcx.getPoints().size(), ( System.nanoTime() - time ) / 1e6 ); 73 | } 74 | 75 | public static void Triangulate(TriangulationContext tcx) { 76 | switch (tcx.Algorithm) { 77 | case TriangulationAlgorithm.DTSweep: 78 | default: 79 | DTSweep.Triangulate((DTSweepContext)tcx); 80 | break; 81 | } 82 | } 83 | 84 | 85 | ///

86 | /// Will do a warmup run to let the JVM optimize the triangulation code -- or would if this were Java --MM 87 | /// 88 | public static void Warmup() { 89 | #if false 90 | /* 91 | * After a method is run 10000 times, the Hotspot compiler will compile 92 | * it into native code. Periodically, the Hotspot compiler may recompile 93 | * the method. After an unspecified amount of time, then the compilation 94 | * system should become quiet. 95 | */ 96 | Polygon poly = PolygonGenerator.RandomCircleSweep2(50, 50000); 97 | TriangulationProcess process = new TriangulationProcess(); 98 | process.triangulate(poly); 99 | #endif 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /SwfTest/TestForm.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System; 33 | using System.Collections.Generic; 34 | using System.Drawing; 35 | using System.Linq; 36 | using System.Windows.Forms; 37 | using Poly2Tri; 38 | 39 | namespace SwfTest { 40 | [System.ComponentModel.DesignerCategory("")] class TestForm : Form { 41 | List Polygons; 42 | 43 | int i; 44 | 45 | Timer rotation; 46 | 47 | public TestForm() { 48 | ClientSize = new Size(1000, 1000); 49 | DoubleBuffered = true; 50 | Text = "Just a test"; 51 | Visible = true; 52 | 53 | Polygons = ExampleData.Polygons.ToList(); 54 | foreach ( var poly in Polygons ) try { 55 | P2T.Triangulate(poly); 56 | } catch ( Exception ) {} 57 | 58 | rotation = new Timer() 59 | { Enabled = true 60 | , Interval = 500 61 | }; 62 | rotation.Tick += (o,e) => { 63 | i = (i+1)%Polygons.Count; 64 | Invalidate(); 65 | }; 66 | 67 | Invalidate(); 68 | } 69 | 70 | protected override void OnPaint( PaintEventArgs e ) { 71 | float xmin = float.MaxValue, xmax = float.MinValue; 72 | float ymin = float.MaxValue, ymax = float.MinValue; 73 | 74 | foreach ( var point in Polygons[i].Points ) { 75 | xmin = Math.Min(xmin,point.Xf); 76 | xmax = Math.Max(xmax,point.Xf); 77 | ymin = Math.Min(ymin,point.Yf); 78 | ymax = Math.Max(ymax,point.Yf); 79 | } 80 | 81 | if ( xmin"); 66 | node = node.Next; 67 | } 68 | sb.Append(Tail.Point.X); 69 | return sb.ToString(); 70 | } 71 | 72 | /// 73 | /// MM: This seems to be used by LocateNode to guess a position in the implicit linked list of AdvancingFrontNodes near x 74 | /// Removed an overload that depended on this being exact 75 | /// 76 | private AdvancingFrontNode FindSearchNode( double x ) { 77 | return Search; 78 | } 79 | 80 | /// 81 | /// We use a balancing tree to locate a node smaller or equal to given key value (in theory) 82 | /// 83 | public AdvancingFrontNode LocateNode( TriangulationPoint point ) { 84 | return LocateNode(point.X); 85 | } 86 | 87 | private AdvancingFrontNode LocateNode( double x ) { 88 | AdvancingFrontNode node = FindSearchNode(x); 89 | if (x < node.Value) { 90 | while ((node = node.Prev) != null) 91 | if (x >= node.Value) { 92 | Search = node; 93 | return node; 94 | } 95 | } else { 96 | while ((node = node.Next) != null) 97 | if (x < node.Value) { 98 | Search = node.Prev; 99 | return node.Prev; 100 | } 101 | } 102 | return null; 103 | } 104 | 105 | /// 106 | /// This implementation will use simple node traversal algorithm to find a point on the front 107 | /// 108 | public AdvancingFrontNode LocatePoint( TriangulationPoint point ) { 109 | double px = point.X; 110 | AdvancingFrontNode node = FindSearchNode(px); 111 | double nx = node.Point.X; 112 | 113 | if (px == nx) { 114 | if (point != node.Point) { 115 | // We might have two nodes with same x value for a short time 116 | if (point == node.Prev.Point) { 117 | node = node.Prev; 118 | } else if (point == node.Next.Point) { 119 | node = node.Next; 120 | } else { 121 | throw new Exception("Failed to find Node for given afront point"); 122 | } 123 | } 124 | } else if (px < nx) { 125 | while ((node = node.Prev) != null) if (point == node.Point) break; 126 | } else { 127 | while ((node = node.Next) != null) if (point == node.Point) break; 128 | } 129 | Search = node; 130 | return node; 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /ExampleData/Data/debug.dat: -------------------------------------------------------------------------------- 1 | 1.2277408 0.0 2 | 1.3243141 0.041618247 3 | 1.0635862 0.06691518 4 | 0.952708 0.09005742 5 | 0.9624486 0.12158553 6 | 1.3459457 0.21317686 7 | 0.94439876 0.1801537 8 | 0.58555007 0.13088594 9 | 0.5811499 0.14921393 10 | 0.82454175 0.23955151 11 | 0.62284756 0.20237544 12 | 0.56452847 0.20324275 13 | 0.5578659 0.22087473 14 | 0.6222525 0.2692727 15 | 0.5428962 0.25546756 16 | 0.6560448 0.33427152 17 | 0.525784 0.28905222 18 | 0.71199375 0.42107195 19 | 0.8918749 0.56600106 20 | 0.93826324 0.63764304 21 | 0.5041431 0.36628145 22 | 0.74085724 0.57466775 23 | 0.55901116 0.46245426 24 | 0.45006666 0.3967871 25 | 0.43738118 0.41072828 26 | 0.42426407 0.42426407 27 | 0.41072828 0.43738118 28 | 0.3967871 0.45006666 29 | 0.41002733 0.4956379 30 | 0.7536917 0.9716534 31 | 1.0196112 1.4033744 32 | 0.66767913 0.98246 33 | 0.7202045 1.1348608 34 | 0.44231245 0.7479095 35 | 0.28905222 0.525784 36 | 0.2723943 0.5346039 37 | 0.5011288 1.0649529 38 | 0.27308202 0.6310553 39 | 0.22087473 0.5578659 40 | 0.20460863 0.56832236 41 | 0.3397839 1.0457473 42 | 0.26354295 0.9071208 43 | 0.2884009 1.1232473 44 | 0.15593462 0.69761133 45 | 0.16937841 0.88791275 46 | 0.21818724 1.37758 47 | 0.1523747 1.20617 48 | 0.11806885 1.249038 49 | 0.06135568 0.97522056 50 | 0.018846456 0.5997039 51 | 6.8178847E-17 1.113445 52 | -0.028901286 0.91965383 53 | -0.06209223 0.98692775 54 | -0.05646499 0.5973372 55 | -0.10701424 0.84710497 56 | -0.09386068 0.592613 57 | -0.1636339 0.8577989 58 | -0.29984477 1.3414284 59 | -0.45487383 1.7716166 60 | -0.6387838 2.1987083 61 | -0.6129905 1.8865908 62 | -0.8446652 2.3461478 63 | -0.9281012 2.344116 64 | -1.0037318 2.3194876 65 | -1.0196298 2.1668236 66 | -0.8902802 1.7472732 67 | -1.2330354 2.242883 68 | -1.4297054 2.4174998 69 | -1.6074804 2.5329838 70 | -1.4688258 2.1613116 71 | -1.7633557 2.427051 72 | -1.6571896 2.136436 73 | -1.912272 2.3115396 74 | -1.6086806 1.82469 75 | -1.6045313 1.7086523 76 | -2.0598311 2.0598311 77 | -1.8296968 1.7181997 78 | -2.2503333 1.9839356 79 | -2.1353924 1.7665502 80 | -2.370465 1.8387212 81 | -2.427051 1.7633557 82 | -2.4812417 1.6862501 83 | -2.5329838 1.6074804 84 | -2.5773842 1.5242608 85 | -2.62892 1.445261 86 | -2.6730196 1.3619715 87 | -2.714481 1.2773379 88 | -2.753264 1.1914437 89 | -2.7893295 1.1043737 90 | -2.8226423 1.0162138 91 | -2.8531694 0.927051 92 | -2.5261154 0.73390436 93 | -2.6257684 0.6741827 94 | -2.9277503 0.65442973 95 | -2.8118498 0.53638905 96 | -2.963065 0.4693034 97 | -2.976344 0.3759997 98 | -2.617039 0.24738303 99 | -2.99408 0.18837155 100 | -2.860681 0.08990052 101 | -3.0 3.6739403E-16 102 | -2.6968896 -0.08475317 103 | -2.99408 -0.18837155 104 | -2.431072 -0.22980396 105 | -2.4993353 -0.31573948 106 | -2.3772683 -0.3765223 107 | -2.523671 -0.48141596 108 | -2.4523084 -0.54815584 109 | -1.9428126 -0.49882948 110 | -1.980212 -0.57530475 111 | -1.6508379 -0.53638977 112 | -1.7593161 -0.63339275 113 | -1.1899233 -0.47112396 114 | -0.8138197 -0.35217124 115 | -0.5630522 -0.26495224 116 | -0.5346039 -0.2723943 117 | -0.878033 -0.4827027 118 | -0.85542375 -0.5058962 119 | -1.2059882 -0.76534337 120 | -0.97923774 -0.66548926 121 | -1.0108875 -0.7344528 122 | -0.7830176 -0.6073707 123 | -0.90356225 -0.74749166 124 | -1.0288435 -0.90704757 125 | -1.1261301 -1.0575066 126 | -0.9001703 -0.9001703 127 | -0.8477716 -0.902785 128 | -0.5851195 -0.66368777 129 | -0.47532755 -0.5745723 130 | -0.6310177 -0.8135031 131 | -0.40265256 -0.5542037 132 | -0.33725002 -0.49624833 133 | -0.32149607 -0.50659674 134 | -0.46425027 -0.7850044 135 | -0.38156003 -0.69405514 136 | -0.2723943 -0.5346039 137 | -0.25546756 -0.5428962 138 | -0.23828873 -0.5506528 139 | -0.22087473 -0.5578659 140 | -0.20324275 -0.56452847 141 | -0.20844458 -0.64152646 142 | -0.16739467 -0.5761762 143 | -0.14921393 -0.5811499 144 | -0.13088594 -0.58555007 145 | -0.14249685 -0.7469947 146 | -0.11622784 -0.73383373 147 | -0.081517614 -0.64527833 148 | -0.07004014 -0.7409472 149 | -0.05557717 -0.88337386 150 | -0.025127873 -0.7995819 151 | -1.1021821E-16 -0.6 152 | 0.029305225 -0.9325074 153 | 0.05083992 -0.8080774 154 | 0.10585039 -1.1197802 155 | 0.18259653 -1.4454004 156 | 0.21030101 -1.3277884 157 | 0.17551 -0.9200556 158 | 0.17963327 -0.8036331 159 | 0.14921393 -0.5811499 160 | 0.26661414 -0.9176919 161 | 0.1854102 -0.5706339 162 | 0.24760589 -0.6877518 163 | 0.251998 -0.6364744 164 | 0.23828873 -0.5506528 165 | 0.4822611 -1.024857 166 | 0.479923 -0.9419019 167 | 0.34421936 -0.62613267 168 | 0.55215293 -0.9336396 169 | 0.70164776 -1.1056199 170 | 0.9243659 -1.3601631 171 | 1.1842307 -1.6299537 172 | 1.4756334 -1.9023752 173 | 1.6572317 -2.003249 174 | 1.669321 -1.893473 175 | 1.8840985 -2.0063612 176 | 2.1213202 -2.1213202 177 | 2.1869059 -2.0536413 178 | 2.2503333 -1.9839356 179 | 2.3115396 -1.912272 180 | 2.2131321 -1.7166812 181 | 2.3906639 -1.7369189 182 | 2.0770426 -1.4115567 183 | 2.2302797 -1.4153785 184 | 2.4940982 -1.4750056 185 | 2.62892 -1.445261 186 | 2.23299 -1.1377653 187 | 2.5385184 -1.1945361 188 | 2.4313858 -1.0521545 189 | 2.686942 -1.0638356 190 | 2.8226423 -1.0162138 191 | 2.6503394 -0.86114746 192 | 2.6646125 -0.77414155 193 | 2.1942327 -0.56338316 194 | 1.7811928 -0.39814374 195 | 1.9936028 -0.38030007 196 | 1.5980223 -0.2531019 197 | 1.77933 -0.22478165 198 | 1.192731 -0.112746276 199 | 1.358207 -0.08545114 200 | 1.7209803 -0.054083984 201 | -------------------------------------------------------------------------------- /Poly2Tri.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.30729 7 | 2.0 8 | {C5E5802D-6A45-4FE9-BAE7-5F0AE91D72C1} 9 | Library 10 | Properties 11 | Poly2Tri 12 | Poly2Tri 13 | v3.5 14 | 512 15 | 16 | 17 | 18 | 19 | 3.5 20 | 21 | 22 | true 23 | full 24 | false 25 | bin\Debug\ 26 | DEBUG;TRACE 27 | prompt 28 | 4 29 | 30 | 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | 38 | 39 | true 40 | bin\x86\Debug\ 41 | DEBUG;TRACE 42 | full 43 | x86 44 | prompt 45 | 46 | 47 | bin\x86\Release\ 48 | TRACE 49 | true 50 | pdbonly 51 | x86 52 | prompt 53 | 54 | 55 | 56 | 57 | 3.5 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 104 | -------------------------------------------------------------------------------- /ExampleData/Data/Pointsets/example2.dat: -------------------------------------------------------------------------------- 1 | 1359.000000 10.000000 2 | 1535.000000 42.000000 3 | 104.000000 73.000000 4 | 389.000000 89.000000 5 | 1983.000000 92.000000 6 | 28.000000 112.000000 7 | 682.000000 117.000000 8 | 378.000000 120.000000 9 | 265.000000 140.000000 10 | 261.000000 142.000000 11 | 328.000000 160.000000 12 | 1492.000000 186.000000 13 | 1929.000000 199.000000 14 | 885.000000 200.000000 15 | 882.000000 205.000000 16 | 624.000000 209.000000 17 | 903.000000 227.000000 18 | 1709.000000 234.000000 19 | 1573.000000 236.000000 20 | 1718.000000 252.000000 21 | 846.000000 256.000000 22 | 1154.000000 262.000000 23 | 1358.000000 272.000000 24 | 657.000000 279.000000 25 | 353.000000 279.000000 26 | 357.000000 279.000000 27 | 197.000000 291.000000 28 | 281.000000 304.000000 29 | 109.000000 309.000000 30 | 1681.000000 313.000000 31 | 1596.000000 316.000000 32 | 1180.000000 326.000000 33 | 985.000000 343.000000 34 | 1117.000000 358.000000 35 | 1491.000000 370.000000 36 | 1975.000000 374.000000 37 | 270.000000 401.000000 38 | 762.000000 405.000000 39 | 114.000000 415.000000 40 | 77.000000 421.000000 41 | 177.000000 424.000000 42 | 1375.000000 435.000000 43 | 370.000000 436.000000 44 | 845.000000 438.000000 45 | 1337.000000 440.000000 46 | 113.000000 448.000000 47 | 149.000000 450.000000 48 | 1643.000000 451.000000 49 | 1188.000000 451.000000 50 | 1200.000000 452.000000 51 | 40.000000 454.000000 52 | 1164.000000 454.000000 53 | 1013.000000 504.000000 54 | 1829.000000 505.000000 55 | 1261.000000 511.000000 56 | 997.000000 524.000000 57 | 993.000000 536.000000 58 | 1201.000000 538.000000 59 | 1693.000000 550.000000 60 | 596.000000 562.000000 61 | 483.000000 570.000000 62 | 1628.000000 587.000000 63 | 1978.000000 589.000000 64 | 1148.000000 593.000000 65 | 1425.000000 612.000000 66 | 1998.000000 613.000000 67 | 1508.000000 628.000000 68 | 787.000000 634.000000 69 | 455.000000 652.000000 70 | 728.000000 664.000000 71 | 1787.000000 673.000000 72 | 953.000000 713.000000 73 | 266.000000 716.000000 74 | 1443.000000 731.000000 75 | 763.000000 735.000000 76 | 1968.000000 741.000000 77 | 1270.000000 751.000000 78 | 716.000000 758.000000 79 | 1784.000000 769.000000 80 | 442.000000 786.000000 81 | 1552.000000 793.000000 82 | 1759.000000 794.000000 83 | 1237.000000 844.000000 84 | 480.000000 845.000000 85 | 191.000000 864.000000 86 | 1190.000000 870.000000 87 | 1205.000000 877.000000 88 | 131.000000 881.000000 89 | 1666.000000 891.000000 90 | 468.000000 912.000000 91 | 573.000000 927.000000 92 | 762.000000 942.000000 93 | 149.000000 967.000000 94 | 310.000000 972.000000 95 | 647.000000 997.000000 96 | 467.000000 1016.000000 97 | 981.000000 1034.000000 98 | 1497.000000 1044.000000 99 | 1328.000000 1092.000000 100 | 1540.000000 1095.000000 101 | 599.000000 1096.000000 102 | 1418.000000 1099.000000 103 | 1423.000000 1132.000000 104 | 102.000000 1133.000000 105 | 618.000000 1134.000000 106 | 93.000000 1138.000000 107 | 576.000000 1141.000000 108 | 384.000000 1141.000000 109 | 1246.000000 1145.000000 110 | 1951.000000 1157.000000 111 | 908.000000 1178.000000 112 | 1988.000000 1187.000000 113 | 1689.000000 1219.000000 114 | 560.000000 1232.000000 115 | 1418.000000 1233.000000 116 | 1408.000000 1235.000000 117 | 52.000000 1257.000000 118 | 1826.000000 1298.000000 119 | 707.000000 1300.000000 120 | 1295.000000 1304.000000 121 | 1556.000000 1312.000000 122 | 1075.000000 1315.000000 123 | 440.000000 1319.000000 124 | 883.000000 1321.000000 125 | 1446.000000 1323.000000 126 | 1485.000000 1336.000000 127 | 772.000000 1338.000000 128 | 1716.000000 1341.000000 129 | 1580.000000 1353.000000 130 | 44.000000 1356.000000 131 | 313.000000 1358.000000 132 | 1770.000000 1365.000000 133 | 918.000000 1366.000000 134 | 881.000000 1372.000000 135 | 517.000000 1374.000000 136 | 297.000000 1380.000000 137 | 1366.000000 1382.000000 138 | 1930.000000 1418.000000 139 | 312.000000 1432.000000 140 | 1399.000000 1436.000000 141 | 118.000000 1438.000000 142 | 1969.000000 1449.000000 143 | 1619.000000 1451.000000 144 | 384.000000 1493.000000 145 | 1473.000000 1513.000000 146 | 1308.000000 1536.000000 147 | 380.000000 1539.000000 148 | 1273.000000 1540.000000 149 | 50.000000 1563.000000 150 | 847.000000 1568.000000 151 | 369.000000 1579.000000 152 | 1043.000000 1584.000000 153 | 1705.000000 1606.000000 154 | 26.000000 1619.000000 155 | 556.000000 1625.000000 156 | 904.000000 1626.000000 157 | 760.000000 1631.000000 158 | 1248.000000 1632.000000 159 | 776.000000 1634.000000 160 | 215.000000 1666.000000 161 | 1983.000000 1672.000000 162 | 8.000000 1678.000000 163 | 137.000000 1686.000000 164 | 1362.000000 1688.000000 165 | 1989.000000 1689.000000 166 | 41.000000 1700.000000 167 | 997.000000 1732.000000 168 | 406.000000 1733.000000 169 | 313.000000 1734.000000 170 | 1867.000000 1741.000000 171 | 43.000000 1749.000000 172 | 541.000000 1749.000000 173 | 951.000000 1758.000000 174 | 1821.000000 1762.000000 175 | 148.000000 1762.000000 176 | 499.000000 1771.000000 177 | 923.000000 1807.000000 178 | 1455.000000 1810.000000 179 | 238.000000 1830.000000 180 | 785.000000 1835.000000 181 | 1657.000000 1837.000000 182 | 1864.000000 1837.000000 183 | 503.000000 1858.000000 184 | 1902.000000 1859.000000 185 | 548.000000 1873.000000 186 | 1887.000000 1874.000000 187 | 981.000000 1884.000000 188 | 984.000000 1891.000000 189 | 807.000000 1892.000000 190 | 924.000000 1907.000000 191 | 1379.000000 1911.000000 192 | 1605.000000 1918.000000 193 | 1298.000000 1920.000000 194 | 1433.000000 1928.000000 195 | 1162.000000 1955.000000 196 | 1625.000000 1958.000000 197 | 1851.000000 1978.000000 198 | 1628.000000 1979.000000 199 | 1218.000000 1979.000000 200 | 173.000000 1986.000000 -------------------------------------------------------------------------------- /ExampleData/Data/Pointsets/example3.dat: -------------------------------------------------------------------------------- 1 | 1779.000000 1.000000 2 | 1542.000000 5.000000 3 | 975.000000 8.000000 4 | 1522.000000 17.000000 5 | 570.000000 20.000000 6 | 1247.000000 38.000000 7 | 435.000000 47.000000 8 | 1451.000000 56.000000 9 | 948.000000 60.000000 10 | 572.000000 72.000000 11 | 1257.000000 107.000000 12 | 1755.000000 136.000000 13 | 203.000000 143.000000 14 | 1336.000000 146.000000 15 | 804.000000 152.000000 16 | 1254.000000 163.000000 17 | 99.000000 165.000000 18 | 1816.000000 166.000000 19 | 1833.000000 177.000000 20 | 1709.000000 177.000000 21 | 1831.000000 177.000000 22 | 387.000000 201.000000 23 | 721.000000 204.000000 24 | 657.000000 209.000000 25 | 336.000000 216.000000 26 | 613.000000 227.000000 27 | 456.000000 234.000000 28 | 1088.000000 236.000000 29 | 981.000000 250.000000 30 | 1280.000000 253.000000 31 | 1466.000000 266.000000 32 | 1574.000000 278.000000 33 | 1444.000000 278.000000 34 | 1396.000000 302.000000 35 | 1194.000000 302.000000 36 | 1856.000000 314.000000 37 | 1194.000000 359.000000 38 | 1197.000000 366.000000 39 | 605.000000 398.000000 40 | 1017.000000 406.000000 41 | 105.000000 409.000000 42 | 1090.000000 411.000000 43 | 1126.000000 433.000000 44 | 1317.000000 439.000000 45 | 118.000000 443.000000 46 | 1941.000000 458.000000 47 | 1255.000000 488.000000 48 | 617.000000 492.000000 49 | 1248.000000 501.000000 50 | 175.000000 504.000000 51 | 1202.000000 514.000000 52 | 1893.000000 527.000000 53 | 416.000000 552.000000 54 | 1481.000000 558.000000 55 | 262.000000 560.000000 56 | 349.000000 560.000000 57 | 801.000000 574.000000 58 | 601.000000 581.000000 59 | 115.000000 584.000000 60 | 1546.000000 587.000000 61 | 592.000000 597.000000 62 | 1295.000000 600.000000 63 | 647.000000 604.000000 64 | 1447.000000 605.000000 65 | 1032.000000 606.000000 66 | 85.000000 613.000000 67 | 487.000000 632.000000 68 | 897.000000 658.000000 69 | 1758.000000 671.000000 70 | 1140.000000 672.000000 71 | 1767.000000 674.000000 72 | 1387.000000 696.000000 73 | 1722.000000 697.000000 74 | 761.000000 713.000000 75 | 977.000000 721.000000 76 | 540.000000 736.000000 77 | 1108.000000 761.000000 78 | 1909.000000 772.000000 79 | 1783.000000 776.000000 80 | 1469.000000 806.000000 81 | 726.000000 833.000000 82 | 502.000000 840.000000 83 | 169.000000 851.000000 84 | 502.000000 866.000000 85 | 963.000000 877.000000 86 | 1537.000000 941.000000 87 | 920.000000 943.000000 88 | 507.000000 956.000000 89 | 1014.000000 959.000000 90 | 1263.000000 964.000000 91 | 340.000000 973.000000 92 | 1556.000000 985.000000 93 | 240.000000 1004.000000 94 | 101.000000 1012.000000 95 | 1200.000000 1051.000000 96 | 1212.000000 1058.000000 97 | 471.000000 1065.000000 98 | 491.000000 1069.000000 99 | 185.000000 1085.000000 100 | 80.000000 1091.000000 101 | 1381.000000 1092.000000 102 | 1891.000000 1095.000000 103 | 64.000000 1097.000000 104 | 758.000000 1100.000000 105 | 801.000000 1122.000000 106 | 593.000000 1135.000000 107 | 270.000000 1136.000000 108 | 236.000000 1138.000000 109 | 1890.000000 1144.000000 110 | 688.000000 1164.000000 111 | 1262.000000 1169.000000 112 | 1944.000000 1199.000000 113 | 1605.000000 1201.000000 114 | 1802.000000 1206.000000 115 | 340.000000 1214.000000 116 | 37.000000 1222.000000 117 | 1257.000000 1229.000000 118 | 106.000000 1235.000000 119 | 389.000000 1243.000000 120 | 716.000000 1259.000000 121 | 1725.000000 1266.000000 122 | 852.000000 1299.000000 123 | 1858.000000 1304.000000 124 | 379.000000 1309.000000 125 | 1430.000000 1312.000000 126 | 1433.000000 1336.000000 127 | 343.000000 1346.000000 128 | 97.000000 1354.000000 129 | 1980.000000 1364.000000 130 | 84.000000 1370.000000 131 | 1232.000000 1385.000000 132 | 1999.000000 1397.000000 133 | 448.000000 1401.000000 134 | 272.000000 1402.000000 135 | 1800.000000 1412.000000 136 | 472.000000 1415.000000 137 | 1807.000000 1441.000000 138 | 1613.000000 1451.000000 139 | 1663.000000 1452.000000 140 | 880.000000 1464.000000 141 | 881.000000 1467.000000 142 | 1106.000000 1468.000000 143 | 271.000000 1513.000000 144 | 1332.000000 1528.000000 145 | 321.000000 1534.000000 146 | 1324.000000 1540.000000 147 | 474.000000 1545.000000 148 | 363.000000 1551.000000 149 | 1548.000000 1552.000000 150 | 715.000000 1555.000000 151 | 272.000000 1574.000000 152 | 313.000000 1576.000000 153 | 34.000000 1582.000000 154 | 1699.000000 1589.000000 155 | 6.000000 1592.000000 156 | 1881.000000 1595.000000 157 | 1031.000000 1597.000000 158 | 656.000000 1609.000000 159 | 142.000000 1610.000000 160 | 687.000000 1631.000000 161 | 1292.000000 1634.000000 162 | 192.000000 1637.000000 163 | 1622.000000 1649.000000 164 | 843.000000 1654.000000 165 | 1983.000000 1656.000000 166 | 255.000000 1676.000000 167 | 1043.000000 1677.000000 168 | 378.000000 1678.000000 169 | 1963.000000 1734.000000 170 | 996.000000 1755.000000 171 | 290.000000 1770.000000 172 | 1662.000000 1779.000000 173 | 1738.000000 1794.000000 174 | 1061.000000 1815.000000 175 | 270.000000 1819.000000 176 | 3.000000 1822.000000 177 | 180.000000 1827.000000 178 | 386.000000 1836.000000 179 | 1250.000000 1858.000000 180 | 1912.000000 1867.000000 181 | 1241.000000 1872.000000 182 | 1184.000000 1875.000000 183 | 1641.000000 1877.000000 184 | 1221.000000 1878.000000 185 | 1734.000000 1893.000000 186 | 645.000000 1898.000000 187 | 1975.000000 1899.000000 188 | 296.000000 1907.000000 189 | 400.000000 1907.000000 190 | 195.000000 1914.000000 191 | 122.000000 1928.000000 192 | 1238.000000 1935.000000 193 | 254.000000 1937.000000 194 | 395.000000 1939.000000 195 | 193.000000 1939.000000 196 | 1226.000000 1945.000000 197 | 1143.000000 1949.000000 198 | 726.000000 1951.000000 199 | 1642.000000 1998.000000 200 | 1008.000000 1998.000000 -------------------------------------------------------------------------------- /ExampleData/Data/Pointsets/example4.dat: -------------------------------------------------------------------------------- 1 | 1779.000000 1.000000 2 | 1542.000000 5.000000 3 | 975.000000 8.000000 4 | 1522.000000 17.000000 5 | 570.000000 20.000000 6 | 1247.000000 38.000000 7 | 435.000000 47.000000 8 | 1451.000000 56.000000 9 | 948.000000 60.000000 10 | 572.000000 72.000000 11 | 1257.000000 107.000000 12 | 1755.000000 136.000000 13 | 203.000000 143.000000 14 | 1336.000000 146.000000 15 | 804.000000 152.000000 16 | 1254.000000 163.000000 17 | 99.000000 165.000000 18 | 1816.000000 166.000000 19 | 1833.000000 177.000000 20 | 1709.000000 177.000000 21 | 1831.000000 177.000000 22 | 387.000000 201.000000 23 | 721.000000 204.000000 24 | 657.000000 209.000000 25 | 336.000000 216.000000 26 | 613.000000 227.000000 27 | 456.000000 234.000000 28 | 1088.000000 236.000000 29 | 981.000000 250.000000 30 | 1280.000000 253.000000 31 | 1466.000000 266.000000 32 | 1574.000000 278.000000 33 | 1444.000000 278.000000 34 | 1396.000000 302.000000 35 | 1194.000000 302.000000 36 | 1856.000000 314.000000 37 | 1194.000000 359.000000 38 | 1197.000000 366.000000 39 | 605.000000 398.000000 40 | 1017.000000 406.000000 41 | 105.000000 409.000000 42 | 1090.000000 411.000000 43 | 1126.000000 433.000000 44 | 1317.000000 439.000000 45 | 118.000000 443.000000 46 | 1941.000000 458.000000 47 | 1255.000000 488.000000 48 | 617.000000 492.000000 49 | 1248.000000 501.000000 50 | 175.000000 504.000000 51 | 1202.000000 514.000000 52 | 1893.000000 527.000000 53 | 416.000000 552.000000 54 | 1481.000000 558.000000 55 | 262.000000 560.000000 56 | 349.000000 560.000000 57 | 801.000000 574.000000 58 | 601.000000 581.000000 59 | 115.000000 584.000000 60 | 1546.000000 587.000000 61 | 592.000000 597.000000 62 | 1295.000000 600.000000 63 | 647.000000 604.000000 64 | 1447.000000 605.000000 65 | 1032.000000 606.000000 66 | 85.000000 613.000000 67 | 487.000000 632.000000 68 | 897.000000 658.000000 69 | 1758.000000 671.000000 70 | 1140.000000 672.000000 71 | 1767.000000 674.000000 72 | 1387.000000 696.000000 73 | 1722.000000 697.000000 74 | 761.000000 713.000000 75 | 977.000000 721.000000 76 | 540.000000 736.000000 77 | 1108.000000 761.000000 78 | 1909.000000 772.000000 79 | 1783.000000 776.000000 80 | 1469.000000 806.000000 81 | 726.000000 833.000000 82 | 502.000000 840.000000 83 | 169.000000 851.000000 84 | 502.000000 866.000000 85 | 963.000000 877.000000 86 | 1537.000000 941.000000 87 | 920.000000 943.000000 88 | 507.000000 956.000000 89 | 1014.000000 959.000000 90 | 1263.000000 964.000000 91 | 340.000000 973.000000 92 | 1556.000000 985.000000 93 | 240.000000 1004.000000 94 | 101.000000 1012.000000 95 | 1200.000000 1051.000000 96 | 1212.000000 1058.000000 97 | 471.000000 1065.000000 98 | 491.000000 1069.000000 99 | 185.000000 1085.000000 100 | 80.000000 1091.000000 101 | 1381.000000 1092.000000 102 | 1891.000000 1095.000000 103 | 64.000000 1097.000000 104 | 758.000000 1100.000000 105 | 801.000000 1122.000000 106 | 593.000000 1135.000000 107 | 270.000000 1136.000000 108 | 236.000000 1138.000000 109 | 1890.000000 1144.000000 110 | 688.000000 1164.000000 111 | 1262.000000 1169.000000 112 | 1944.000000 1199.000000 113 | 1605.000000 1201.000000 114 | 1802.000000 1206.000000 115 | 340.000000 1214.000000 116 | 37.000000 1222.000000 117 | 1257.000000 1229.000000 118 | 106.000000 1235.000000 119 | 389.000000 1243.000000 120 | 716.000000 1259.000000 121 | 1725.000000 1266.000000 122 | 852.000000 1299.000000 123 | 1858.000000 1304.000000 124 | 379.000000 1309.000000 125 | 1430.000000 1312.000000 126 | 1433.000000 1336.000000 127 | 343.000000 1346.000000 128 | 97.000000 1354.000000 129 | 1980.000000 1364.000000 130 | 84.000000 1370.000000 131 | 1232.000000 1385.000000 132 | 1999.000000 1397.000000 133 | 448.000000 1401.000000 134 | 272.000000 1402.000000 135 | 1800.000000 1412.000000 136 | 472.000000 1415.000000 137 | 1807.000000 1441.000000 138 | 1613.000000 1451.000000 139 | 1663.000000 1452.000000 140 | 880.000000 1464.000000 141 | 881.000000 1467.000000 142 | 1106.000000 1468.000000 143 | 271.000000 1513.000000 144 | 1332.000000 1528.000000 145 | 321.000000 1534.000000 146 | 1324.000000 1540.000000 147 | 474.000000 1545.000000 148 | 363.000000 1551.000000 149 | 1548.000000 1552.000000 150 | 715.000000 1555.000000 151 | 272.000000 1574.000000 152 | 313.000000 1576.000000 153 | 34.000000 1582.000000 154 | 1699.000000 1589.000000 155 | 6.000000 1592.000000 156 | 1881.000000 1595.000000 157 | 1031.000000 1597.000000 158 | 656.000000 1609.000000 159 | 142.000000 1610.000000 160 | 687.000000 1631.000000 161 | 1292.000000 1634.000000 162 | 192.000000 1637.000000 163 | 1622.000000 1649.000000 164 | 843.000000 1654.000000 165 | 1983.000000 1656.000000 166 | 255.000000 1676.000000 167 | 1043.000000 1677.000000 168 | 378.000000 1678.000000 169 | 1963.000000 1734.000000 170 | 996.000000 1755.000000 171 | 290.000000 1770.000000 172 | 1662.000000 1779.000000 173 | 1738.000000 1794.000000 174 | 1061.000000 1815.000000 175 | 270.000000 1819.000000 176 | 3.000000 1822.000000 177 | 180.000000 1827.000000 178 | 386.000000 1836.000000 179 | 1250.000000 1858.000000 180 | 1912.000000 1867.000000 181 | 1241.000000 1872.000000 182 | 1184.000000 1875.000000 183 | 1641.000000 1877.000000 184 | 1221.000000 1878.000000 185 | 1734.000000 1893.000000 186 | 645.000000 1898.000000 187 | 1975.000000 1899.000000 188 | 296.000000 1907.000000 189 | 400.000000 1907.000000 190 | 195.000000 1914.000000 191 | 122.000000 1928.000000 192 | 1238.000000 1935.000000 193 | 254.000000 1937.000000 194 | 395.000000 1939.000000 195 | 193.000000 1939.000000 196 | 1226.000000 1945.000000 197 | 1143.000000 1949.000000 198 | 726.000000 1951.000000 199 | 1642.000000 1998.000000 200 | 1008.000000 1998.000000 -------------------------------------------------------------------------------- /Triangulation/TriangulationUtil.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | namespace Poly2Tri { 33 | /** 34 | * @author Thomas Åhlén, thahlen@gmail.com 35 | */ 36 | public class TriangulationUtil { 37 | public static double EPSILON = 1e-12; 38 | /// 39 | /// Requirements: 40 | /// 1. a,b and c form a triangle. 41 | /// 2. a and d is know to be on opposite side of bc 42 | /// 43 | /// a 44 | /// + 45 | /// / \ 46 | /// / \ 47 | /// b/ \c 48 | /// +-------+ 49 | /// / B \ 50 | /// / \ 51 | /// 52 | /// Facts: 53 | /// d has to be in area B to have a chance to be inside the circle formed by a,b and c 54 | /// d is outside B if orient2d(a,b,d) or orient2d(c,a,d) is CW 55 | /// This preknowledge gives us a way to optimize the incircle test 56 | /// 57 | /// triangle point, opposite d 58 | /// triangle point 59 | /// triangle point 60 | /// point opposite a 61 | /// true if d is inside circle, false if on circle edge 62 | public static bool SmartIncircle( TriangulationPoint pa, TriangulationPoint pb, TriangulationPoint pc, TriangulationPoint pd ) { 63 | double pdx = pd.X; 64 | double pdy = pd.Y; 65 | double adx = pa.X - pdx; 66 | double ady = pa.Y - pdy; 67 | double bdx = pb.X - pdx; 68 | double bdy = pb.Y - pdy; 69 | 70 | double adxbdy = adx * bdy; 71 | double bdxady = bdx * ady; 72 | double oabd = adxbdy - bdxady; 73 | // oabd = orient2d(pa,pb,pd); 74 | if (oabd <= 0) return false; 75 | 76 | double cdx = pc.X - pdx; 77 | double cdy = pc.Y - pdy; 78 | 79 | double cdxady = cdx * ady; 80 | double adxcdy = adx * cdy; 81 | double ocad = cdxady - adxcdy; 82 | // ocad = orient2d(pc,pa,pd); 83 | if (ocad <= 0) return false; 84 | 85 | double bdxcdy = bdx * cdy; 86 | double cdxbdy = cdx * bdy; 87 | 88 | double alift = adx * adx + ady * ady; 89 | double blift = bdx * bdx + bdy * bdy; 90 | double clift = cdx * cdx + cdy * cdy; 91 | 92 | double det = alift * (bdxcdy - cdxbdy) + blift * ocad + clift * oabd; 93 | 94 | return det > 0; 95 | } 96 | 97 | public static bool InScanArea( TriangulationPoint pa, TriangulationPoint pb, TriangulationPoint pc, TriangulationPoint pd ) { 98 | double pdx = pd.X; 99 | double pdy = pd.Y; 100 | double adx = pa.X - pdx; 101 | double ady = pa.Y - pdy; 102 | double bdx = pb.X - pdx; 103 | double bdy = pb.Y - pdy; 104 | 105 | double adxbdy = adx * bdy; 106 | double bdxady = bdx * ady; 107 | double oabd = adxbdy - bdxady; 108 | // oabd = orient2d(pa,pb,pd); 109 | if (oabd <= 0) { 110 | return false; 111 | } 112 | 113 | double cdx = pc.X - pdx; 114 | double cdy = pc.Y - pdy; 115 | 116 | double cdxady = cdx * ady; 117 | double adxcdy = adx * cdy; 118 | double ocad = cdxady - adxcdy; 119 | // ocad = orient2d(pc,pa,pd); 120 | if (ocad <= 0) { 121 | return false; 122 | } 123 | return true; 124 | } 125 | 126 | /// Forumla to calculate signed area 127 | /// Positive if CCW 128 | /// Negative if CW 129 | /// 0 if collinear 130 | /// A[P1,P2,P3] = (x1*y2 - y1*x2) + (x2*y3 - y2*x3) + (x3*y1 - y3*x1) 131 | /// = (x1-x3)*(y2-y3) - (y1-y3)*(x2-x3) 132 | public static Orientation Orient2d( TriangulationPoint pa, TriangulationPoint pb, TriangulationPoint pc ) { 133 | double detleft = (pa.X - pc.X) * (pb.Y - pc.Y); 134 | double detright = (pa.Y - pc.Y) * (pb.X - pc.X); 135 | double val = detleft - detright; 136 | if (val > -EPSILON && val < EPSILON) { 137 | return Orientation.Collinear; 138 | } else if (val > 0) { 139 | return Orientation.CCW; 140 | } 141 | return Orientation.CW; 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /ExampleData/ExampleData.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System; 33 | using System.Collections.Generic; 34 | using System.Drawing; 35 | using System.IO; 36 | using System.Globalization; 37 | 38 | namespace Poly2Tri { 39 | public static class ExampleData { 40 | public static Polygon LoadDat( string filename, bool xflip, bool yflip ) { 41 | var points = new List(); 42 | foreach ( var line_ in File.ReadAllLines(filename) ) { 43 | string line = line_.Trim(); 44 | if ( string.IsNullOrEmpty(line) ) continue; 45 | var xy = line.Split( new[]{' ',','}, StringSplitOptions.RemoveEmptyEntries ); 46 | points.Add( new PolygonPoint( (xflip?-1:+1) * double.Parse(xy[0],CultureInfo.InvariantCulture), (yflip?-1:+1) * double.Parse(xy[1],CultureInfo.InvariantCulture) ) ); 47 | } 48 | return new Polygon(points); 49 | } 50 | 51 | public static Polygon LoadDat( string filename ) { return LoadDat(filename,false,false); } 52 | 53 | static readonly Dictionary DatCache = new Dictionary(); 54 | 55 | static Polygon CacheLoadDat( string filename, bool xflip, bool yflip ) { 56 | if (!DatCache.ContainsKey(filename)) DatCache.Add( filename, LoadDat(filename,xflip,yflip) ); 57 | return DatCache[filename]; 58 | } 59 | 60 | static Polygon CacheLoadDat( string filename ) { return CacheLoadDat(filename,false,false); } 61 | 62 | static readonly Dictionary ImageCache = new Dictionary(); 63 | 64 | static Image CacheLoadImage( string filename ) { 65 | if (!ImageCache.ContainsKey(filename)) ImageCache.Add( filename, new Bitmap(filename) ); 66 | return ImageCache[filename]; 67 | } 68 | 69 | // These should all use +x = right, +y = up 70 | public static Polygon Two { get { return CacheLoadDat(@"Data/2.dat"); } } 71 | public static Polygon Bird { get { return CacheLoadDat(@"Data/bird.dat",false,true); } } 72 | public static Polygon Custom { get { return CacheLoadDat(@"Data/custom.dat"); } } 73 | public static Polygon Debug { get { return CacheLoadDat(@"Data/debug.dat"); } } 74 | public static Polygon Debug2 { get { return CacheLoadDat(@"Data/debug2.dat"); } } 75 | public static Polygon Diamond { get { return CacheLoadDat(@"Data/diamond.dat"); } } 76 | public static Polygon Dude { get { 77 | if (!ImageCache.ContainsKey(@"Data/dude.dat")) { 78 | var p = CacheLoadDat(@"Data/dude.dat"); 79 | p.AddHole( new Polygon 80 | ( new PolygonPoint(325,437) 81 | , new PolygonPoint(320,423) 82 | , new PolygonPoint(329,413) 83 | , new PolygonPoint(332,423) 84 | )); 85 | p.AddHole( new Polygon 86 | ( new PolygonPoint(320.72342,480) 87 | , new PolygonPoint(338.90617,465.96863) 88 | , new PolygonPoint(347.99754,480.61584) 89 | , new PolygonPoint(329.8148,510.41534) 90 | , new PolygonPoint(339.91632,480.11077) 91 | , new PolygonPoint(334.86556,478.09046) 92 | )); 93 | } 94 | return CacheLoadDat(@"Data\dude.dat"); 95 | }} 96 | public static Polygon Funny { get { return CacheLoadDat(@"Data/funny.dat"); } } 97 | public static Polygon NazcaHeron { get { return CacheLoadDat(@"Data/nazca_heron.dat"); } } 98 | public static Polygon NazcaMonkey { get { return CacheLoadDat(@"Data/nazca_monkey.dat",false,true); } } 99 | public static Polygon Sketchup { get { return CacheLoadDat(@"Data/sketchup.dat"); } } 100 | public static Polygon Star { get { return CacheLoadDat(@"Data/star.dat"); } } 101 | public static Polygon Strange { get { return CacheLoadDat(@"Data/strange.dat"); } } 102 | public static Polygon Tank { get { return CacheLoadDat(@"Data/tank.dat"); } } 103 | public static Polygon Test { get { return CacheLoadDat(@"Data/test.dat"); } } 104 | 105 | public static IEnumerable Polygons { get { return new[] { Two, Bird, Custom, Debug, Debug2, Diamond, Dude, Funny, NazcaHeron, NazcaMonkey, Sketchup, Star, Strange, Tank, Test }; }} 106 | 107 | public static Image Logo256x256 { get { return CacheLoadImage(@"Textures/poly2tri_logotype_256x256.png"); } } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /ExampleData/Data/bird.dat: -------------------------------------------------------------------------------- 1 | 4.57998 4.03402 2 | 4.06435 4.06435 3 | 3.51839 4.21601 4 | 3.09376 4.42832 5 | 2.60846 4.57998 6 | 2.09284 4.7013 7 | 1.51655 4.82263 8 | 0.909929 4.94395 9 | 0.242648 5.06527 10 | -0.30331 5.0956 11 | -1.15258 5.12594 12 | -1.72887 5.12594 13 | -2.48714 5.12594 14 | -2.85111 5.03494 15 | -3.36674 5.30792 16 | -3.70038 5.52024 17 | -4.15534 5.9752 18 | -4.7013 6.27851 19 | -5.0956 6.61215 20 | -5.73255 6.67281 21 | -6.55149 6.73348 22 | -6.88513 6.61215 23 | -7.46142 6.36951 24 | -7.88605 6.18752 25 | -8.25003 5.91454 26 | -8.64433 5.61123 27 | -8.88698 5.30792 28 | -9.06896 5.00461 29 | -9.25095 4.88329 30 | -9.94856 4.73163 31 | -10.6462 4.64064 32 | -11.1011 4.54965 33 | -11.3741 4.42832 34 | -11.5561 4.21601 35 | -11.0101 4.21601 36 | -10.1305 3.94303 37 | -9.61492 3.73071 38 | -9.15996 3.4274 39 | -8.73532 3.00277 40 | -8.34102 2.6388 41 | -7.97705 2.36582 42 | -7.61308 2.03218 43 | -7.18844 1.45589 44 | -6.79414 1.12225 45 | -6.64248 0.788605 46 | -6.36951 0.242648 47 | -6.24818 -0.212317 48 | -6.00553 -0.515627 49 | -5.73255 -0.818936 50 | -5.24726 -1.2739 51 | -4.7923 -1.60754 52 | -4.42832 -2.00184 53 | -3.67005 -2.21416 54 | -3.18475 -2.39615 55 | -2.5478 -2.69946 56 | -1.91085 -2.79045 57 | -1.06158 -2.88144 58 | -0.333641 -2.88144 59 | 0.242648 -2.85111 60 | 0.94026 -2.82078 61 | 1.2739 -2.85111 62 | 1.42556 -3.0331 63 | 1.42556 -3.30608 64 | 1.33456 -3.57905 65 | 1.15258 -4.00369 66 | 1.03125 -4.57998 67 | 0.849267 -5.15627 68 | 0.63695 -5.5809 69 | 0.30331 -5.91454 70 | 0.060662 -6.15719 71 | -0.333641 -6.27851 72 | -0.697612 -6.27851 73 | -1.15258 -6.36951 74 | -1.57721 -6.39984 75 | -2.09284 -6.52116 76 | -2.36582 -6.79414 77 | -2.48714 -7.06712 78 | -2.18383 -6.97612 79 | -1.85019 -6.79414 80 | -1.42556 -6.76381 81 | -1.15258 -6.79414 82 | -1.36489 -6.88513 83 | -1.69853 -6.97612 84 | -1.97151 -7.12778 85 | -2.12317 -7.37043 86 | -2.27482 -7.64341 87 | -2.39615 -7.91639 88 | -2.36582 -8.21969 89 | -2.03218 -7.85572 90 | -1.81986 -7.7344 91 | -1.57721 -7.67374 92 | -1.36489 -7.49175 93 | -1.21324 -7.40076 94 | -0.849267 -7.2491 95 | -0.60662 -7.12778 96 | -0.242648 -6.91546 97 | 0.030331 -6.70315 98 | 0.363972 -6.4605 99 | 0.242648 -6.61215 100 | 0.152837 -6.72007 101 | -0.092855 -6.88818 102 | -0.506653 -7.15974 103 | -0.765276 -7.31491 104 | -1.01097 -7.41836 105 | -1.16614 -7.5606 106 | -1.32132 -7.71577 107 | -1.45063 -7.81922 108 | -1.50235 -8.06492 109 | -1.50235 -8.29768 110 | -1.46356 -8.53044 111 | -1.38597 -8.29768 112 | -1.28252 -8.05199 113 | -1.14028 -7.87095 114 | -0.985106 -7.84509 115 | -0.817001 -7.84509 116 | -0.623033 -7.70284 117 | -0.390272 -7.52181 118 | -0.105787 -7.31491 119 | 0.178699 -7.06922 120 | 0.489047 -6.84939 121 | 0.670083 -6.66835 122 | 0.928707 -6.47438 123 | 1.16147 -6.33214 124 | 1.47182 -6.13817 125 | 1.82096 -5.91834 126 | 2.04079 -5.84076 127 | 2.15717 -5.71144 128 | 2.18303 -5.45282 129 | 2.06665 -5.28472 130 | 1.87268 -5.3623 131 | 1.49768 -5.63386 132 | 1.22612 -5.81489 133 | 1.03216 -5.91834 134 | 0.876982 -5.95714 135 | 0.954569 -5.80196 136 | 1.00629 -5.60799 137 | 1.16147 -5.29765 138 | 1.3425 -4.9873 139 | 1.45888 -4.65109 140 | 1.47182 -4.4054 141 | 1.73044 -3.95281 142 | 1.84682 -3.6166 143 | 1.98906 -3.30625 144 | 2.14424 -2.95711 145 | 2.26062 -2.75021 146 | 2.42872 -2.59503 147 | 2.63562 -2.50452 148 | 2.98476 -2.51745 149 | 3.12701 -2.71141 150 | 3.06235 -3.09935 151 | 2.9589 -3.4097 152 | 2.86838 -3.75884 153 | 2.79079 -4.12091 154 | 2.70028 -4.43126 155 | 2.55803 -4.75454 156 | 2.48045 -5.03902 157 | 2.3382 -5.37523 158 | 2.29941 -5.59506 159 | 2.23475 -5.90541 160 | 2.11837 -6.21576 161 | 1.7951 -6.65542 162 | 1.39423 -7.05628 163 | 1.09681 -7.26318 164 | 0.838188 -7.37956 165 | 0.41146 -7.49594 166 | -0.002337 -7.62526 167 | -0.416135 -7.7675 168 | -0.687689 -8.05199 169 | -0.907519 -8.40113 170 | -0.70062 -8.19423 171 | -0.312685 -8.05199 172 | -0.015268 -7.89681 173 | 0.217493 -7.89681 174 | 0.243355 -7.90974 175 | 0.023525 -8.1425 176 | -0.157511 -8.25888 177 | -0.403203 -8.43992 178 | -0.648896 -8.75027 179 | -0.778207 -8.90544 180 | -0.881657 -9.18993 181 | -0.80407 -9.60372 182 | -0.597171 -9.177 183 | -0.14458 -8.9701 184 | 0.269217 -8.62096 185 | 0.695946 -8.28475 186 | 1.13561 -8.00026 187 | 1.52354 -7.62526 188 | 1.82096 -7.26318 189 | 1.95027 -7.09508 190 | 1.9632 -7.15974 191 | 1.66578 -7.58646 192 | 1.45888 -7.84509 193 | 1.13561 -8.20716 194 | 0.760601 -8.65975 195 | 0.450253 -8.99596 196 | 0.269217 -9.28045 197 | 0.126974 -9.65545 198 | 0.19163 -10.2761 199 | 0.333873 -9.84942 200 | 0.63129 -9.68131 201 | 0.980431 -9.26751 202 | 1.26492 -8.72441 203 | 1.60113 -8.31061 204 | 1.98906 -7.7675 205 | 2.36407 -7.34077 206 | 2.79079 -7.00456 207 | 3.13994 -6.7718 208 | 3.68304 -6.46145 209 | 4.14857 -6.33214 210 | 4.7434 -6.09938 211 | 5.19599 -6.13817 212 | 4.85978 -5.87955 213 | 4.29081 -5.76317 214 | 3.77356 -5.81489 215 | 3.34683 -6.07352 216 | 2.77786 -6.47438 217 | 2.41579 -6.60369 218 | 2.41579 -6.28042 219 | 2.59683 -5.84076 220 | 2.79079 -5.42696 221 | 2.99769 -4.90971 222 | 3.25632 -4.30195 223 | 3.50201 -3.52608 224 | 3.83822 -2.63383 225 | 4.07098 -2.40107 226 | 4.39426 -2.28469 227 | 4.79512 -2.23296 228 | 4.54943 -2.02606 229 | 4.49771 -1.6252 230 | 4.54943 -1.50882 231 | 4.91151 -1.50882 232 | 5.54513 -1.45709 233 | 6.12704 -1.39244 234 | 6.85118 -1.32778 235 | 7.44601 -1.14674 236 | 7.85981 -0.78467 237 | 7.79516 -0.409667 238 | 7.49774 -0.151043 239 | 7.84688 0.042924 240 | 8.23481 0.314479 241 | 8.64861 0.702414 242 | 8.70034 1.09035 243 | 8.41585 1.42656 244 | 8.11843 1.62053 245 | 8.3512 2.06019 246 | 8.53223 2.38347 247 | 8.67447 2.74554 248 | 8.66154 3.22399 249 | 8.80379 3.87055 250 | 8.90724 4.36193 251 | 9.1012 4.85332 252 | 9.43741 5.40936 253 | 9.90293 6.04298 254 | 10.3167 6.58609 255 | 10.7047 7.3749 256 | 10.9374 7.96973 257 | 11.1573 8.40939 258 | 11.1573 8.84905 259 | 10.9374 9.05595 260 | 10.6659 9.28871 261 | 10.3426 9.37922 262 | 9.99345 9.34043 263 | 9.63138 8.97836 264 | 9.20465 8.48697 265 | 8.86844 8.1249 266 | 8.50637 7.72404 267 | 8.17016 7.28438 268 | 7.74343 6.88351 269 | 7.43308 6.5473 270 | 7.16153 6.1723 271 | 6.70894 5.71971 272 | 6.20462 5.25418 273 | 5.72617 4.80159 274 | 5.13134 4.41366 275 | 4.87271 4.16797 -------------------------------------------------------------------------------- /ExampleData/ExampleData.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.30729 7 | 2.0 8 | {FC6F045E-7112-44BF-A491-99D987D9C6D2} 9 | Library 10 | Properties 11 | Poly2Tri 12 | ExampleData 13 | v3.5 14 | 512 15 | 16 | 17 | 18 | 19 | 3.5 20 | 21 | 22 | true 23 | full 24 | false 25 | bin\Debug\ 26 | DEBUG;TRACE 27 | prompt 28 | 4 29 | 30 | 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | 38 | 39 | true 40 | bin\x86\Debug\ 41 | DEBUG;TRACE 42 | full 43 | x86 44 | prompt 45 | 46 | 47 | bin\x86\Release\ 48 | TRACE 49 | true 50 | pdbonly 51 | x86 52 | prompt 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | PreserveNewest 65 | 66 | 67 | PreserveNewest 68 | 69 | 70 | PreserveNewest 71 | 72 | 73 | PreserveNewest 74 | 75 | 76 | PreserveNewest 77 | 78 | 79 | PreserveNewest 80 | 81 | 82 | PreserveNewest 83 | 84 | 85 | PreserveNewest 86 | 87 | 88 | PreserveNewest 89 | 90 | 91 | PreserveNewest 92 | 93 | 94 | PreserveNewest 95 | 96 | 97 | PreserveNewest 98 | 99 | 100 | PreserveNewest 101 | 102 | 103 | PreserveNewest 104 | 105 | 106 | PreserveNewest 107 | 108 | 109 | PreserveNewest 110 | 111 | 112 | 113 | 114 | PreserveNewest 115 | 116 | 117 | PreserveNewest 118 | 119 | 120 | PreserveNewest 121 | 122 | 123 | PreserveNewest 124 | 125 | 126 | PreserveNewest 127 | 128 | 129 | 130 | 131 | {C5E5802D-6A45-4FE9-BAE7-5F0AE91D72C1} 132 | Poly2Tri 133 | 134 | 135 | 136 | 143 | -------------------------------------------------------------------------------- /Triangulation/Delaunay/Sweep/DTSweepContext.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | namespace Poly2Tri { 33 | /** 34 | * 35 | * @author Thomas Åhlén, thahlen@gmail.com 36 | * 37 | */ 38 | public class DTSweepContext : TriangulationContext { 39 | // Inital triangle factor, seed triangle will extend 30% of 40 | // PointSet width to both left and right. 41 | private readonly float ALPHA = 0.3f; 42 | 43 | public AdvancingFront Front; 44 | public TriangulationPoint Head { get; set; } 45 | public TriangulationPoint Tail { get; set; } 46 | 47 | public DTSweepBasin Basin = new DTSweepBasin(); 48 | public DTSweepEdgeEvent EdgeEvent = new DTSweepEdgeEvent(); 49 | 50 | private DTSweepPointComparator _comparator = new DTSweepPointComparator(); 51 | 52 | public DTSweepContext() { 53 | Clear(); 54 | } 55 | 56 | public override bool IsDebugEnabled { get { 57 | return base.IsDebugEnabled; 58 | } protected set { 59 | if (value && DebugContext == null) DebugContext = new DTSweepDebugContext(this); 60 | base.IsDebugEnabled = value; 61 | }} 62 | 63 | public void RemoveFromList( DelaunayTriangle triangle ) { 64 | Triangles.Remove(triangle); 65 | // TODO: remove all neighbor pointers to this triangle 66 | // for( int i=0; i<3; i++ ) 67 | // { 68 | // if( triangle.neighbors[i] != null ) 69 | // { 70 | // triangle.neighbors[i].clearNeighbor( triangle ); 71 | // } 72 | // } 73 | // triangle.clearNeighbors(); 74 | } 75 | 76 | public void MeshClean( DelaunayTriangle triangle ) { 77 | MeshCleanReq(triangle); 78 | } 79 | 80 | private void MeshCleanReq( DelaunayTriangle triangle ) { 81 | if (triangle != null && !triangle.IsInterior) { 82 | triangle.IsInterior = true; 83 | Triangulatable.AddTriangle(triangle); 84 | 85 | for (int i = 0; i < 3; i++) 86 | if (!triangle.EdgeIsConstrained[i]) 87 | { 88 | MeshCleanReq(triangle.Neighbors[i]); 89 | } 90 | } 91 | } 92 | 93 | public override void Clear() { 94 | base.Clear(); 95 | Triangles.Clear(); 96 | } 97 | 98 | public void AddNode( AdvancingFrontNode node ) { 99 | // Console.WriteLine( "add:" + node.key + ":" + System.identityHashCode(node.key)); 100 | // m_nodeTree.put( node.getKey(), node ); 101 | Front.AddNode(node); 102 | } 103 | 104 | public void RemoveNode( AdvancingFrontNode node ) { 105 | // Console.WriteLine( "remove:" + node.key + ":" + System.identityHashCode(node.key)); 106 | // m_nodeTree.delete( node.getKey() ); 107 | Front.RemoveNode(node); 108 | } 109 | 110 | public AdvancingFrontNode LocateNode( TriangulationPoint point ) { 111 | return Front.LocateNode(point); 112 | } 113 | 114 | public void CreateAdvancingFront() { 115 | AdvancingFrontNode head, tail, middle; 116 | // Initial triangle 117 | DelaunayTriangle iTriangle = new DelaunayTriangle(Points[0], Tail, Head); 118 | Triangles.Add(iTriangle); 119 | 120 | head = new AdvancingFrontNode(iTriangle.Points[1]); 121 | head.Triangle = iTriangle; 122 | middle = new AdvancingFrontNode(iTriangle.Points[0]); 123 | middle.Triangle = iTriangle; 124 | tail = new AdvancingFrontNode(iTriangle.Points[2]); 125 | 126 | Front = new AdvancingFront(head, tail); 127 | Front.AddNode(middle); 128 | 129 | // TODO: I think it would be more intuitive if head is middles next and not previous 130 | // so swap head and tail 131 | Front.Head.Next = middle; 132 | middle.Next = Front.Tail; 133 | middle.Prev = Front.Head; 134 | Front.Tail.Prev = middle; 135 | } 136 | 137 | 138 | 139 | 140 | 141 | /// 142 | /// Try to map a node to all sides of this triangle that don't have 143 | /// a neighbor. 144 | /// 145 | public void MapTriangleToNodes( DelaunayTriangle t ) { 146 | for (int i = 0; i < 3; i++) 147 | if (t.Neighbors[i] == null) 148 | { 149 | AdvancingFrontNode n = Front.LocatePoint(t.PointCWFrom(t.Points[i])); 150 | if (n != null) n.Triangle = t; 151 | } 152 | } 153 | 154 | public override void PrepareTriangulation( Triangulatable t ) { 155 | base.PrepareTriangulation(t); 156 | 157 | double xmax, xmin; 158 | double ymax, ymin; 159 | 160 | xmax = xmin = Points[0].X; 161 | ymax = ymin = Points[0].Y; 162 | 163 | // Calculate bounds. Should be combined with the sorting 164 | foreach (TriangulationPoint p in Points) { 165 | if (p.X > xmax) xmax = p.X; 166 | if (p.X < xmin) xmin = p.X; 167 | if (p.Y > ymax) ymax = p.Y; 168 | if (p.Y < ymin) ymin = p.Y; 169 | } 170 | 171 | double deltaX = ALPHA * (xmax - xmin); 172 | double deltaY = ALPHA * (ymax - ymin); 173 | TriangulationPoint p1 = new TriangulationPoint(xmax + deltaX, ymin - deltaY, -1); 174 | TriangulationPoint p2 = new TriangulationPoint(xmin - deltaX, ymin - deltaY, -1); 175 | 176 | Head = p1; 177 | Tail = p2; 178 | 179 | // long time = System.nanoTime(); 180 | // Sort the points along y-axis 181 | Points.Sort(_comparator); 182 | // logger.info( "Triangulation setup [{}ms]", ( System.nanoTime() - time ) / 1e6 ); 183 | } 184 | 185 | 186 | public void FinalizeTriangulation() { 187 | Triangulatable.AddTriangles(Triangles); 188 | Triangles.Clear(); 189 | } 190 | 191 | public override TriangulationConstraint NewConstraint( TriangulationPoint a, TriangulationPoint b ) { 192 | return new DTSweepConstraint(a, b); 193 | } 194 | 195 | public override TriangulationAlgorithm Algorithm { get { return TriangulationAlgorithm.DTSweep; }} 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /ExampleData/Data/sketchup.dat: -------------------------------------------------------------------------------- 1 | -112.9393 -5.134218 2 | -115.783 -26.39329 3 | -116.1693 -15.52189 4 | -115.783 -26.39329 5 | -112.9393 -5.134218 6 | -111.8239 -36.52552 7 | -111.8239 -36.52552 8 | -112.9393 -5.134218 9 | -106.4564 3.601217 10 | -111.8239 -36.52552 11 | -106.4564 3.601217 12 | -104.7373 -44.7788 13 | -66.76277 70.05491 14 | -68.21937 53.83701 15 | -68.55863 62.04185 16 | -68.21937 53.83701 17 | -66.76277 70.05491 18 | -65.7681 45.99956 19 | -65.7681 45.99956 20 | -66.76277 70.05491 21 | -62.95416 77.33014 22 | -65.7681 45.99956 23 | -62.95416 77.33014 24 | -61.37187 39.0636 25 | -61.37187 39.0636 26 | -62.95416 77.33014 27 | -57.39237 83.37173 28 | -61.37187 39.0636 29 | -57.39237 83.37173 30 | -55.33028 33.5018 31 | -55.33028 33.5018 32 | -57.39237 83.37173 33 | -50.4564 87.76796 34 | -55.33028 33.5018 35 | -50.4564 87.76796 36 | -54.18848 31.40854 37 | -54.18848 31.40854 38 | -50.4564 87.76796 39 | -52.54381 29.68213 40 | -52.54381 29.68213 41 | -50.4564 87.76796 42 | -50.50835 28.44022 43 | -50.50835 28.44022 44 | -50.4564 87.76796 45 | -48.22082 27.76744 46 | -48.22082 27.76744 47 | -50.4564 87.76796 48 | -42.61895 90.21923 49 | -48.22082 27.76744 50 | -42.61895 90.21923 51 | -45.8371 27.70964 52 | -45.8371 27.70964 53 | -42.61895 90.21923 54 | -43.51965 28.27076 55 | -43.51965 28.27076 56 | -42.61895 90.21923 57 | -41.4264 29.41256 58 | -41.4264 29.41256 59 | -42.61895 90.21923 60 | -34.41412 90.55849 61 | -41.4264 29.41256 62 | -34.41412 90.55849 63 | -38.42946 47.11159 64 | -41.4264 29.41256 65 | -38.42946 47.11159 66 | -39.69999 31.05723 67 | -39.69999 31.05723 68 | -38.42946 47.11159 69 | -38.45807 33.09269 70 | -38.42946 47.11159 71 | -34.41412 90.55849 72 | -36.86605 53.9672 73 | -36.86605 53.9672 74 | -34.41412 90.55849 75 | -33.69118 60.24126 76 | -33.69118 60.24126 77 | -34.41412 90.55849 78 | -26.40105 88.76263 79 | -33.69118 60.24126 80 | -26.40105 88.76263 81 | -29.09332 65.56134 82 | -29.09332 65.56134 83 | -26.40105 88.76263 84 | -23.3454 69.61164 85 | -23.3454 69.61164 86 | -26.40105 88.76263 87 | -19.12582 84.95402 88 | -23.3454 69.61164 89 | -19.12582 84.95402 90 | -16.7886 72.15173 91 | -16.7886 72.15173 92 | -19.12582 84.95402 93 | -13.74167 81.56284 94 | -16.7886 72.15173 95 | -13.74167 81.56284 96 | -9.81216 73.03084 97 | -9.81216 73.03084 98 | -13.74167 81.56284 99 | -8.03964 78.73864 100 | -9.81216 73.03084 101 | -8.03964 78.73864 102 | -2.830188 72.19677 103 | -2.830188 72.19677 104 | -8.03964 78.73864 105 | -2.079244 76.51087 106 | -2.830188 72.19677 107 | -2.079244 76.51087 108 | 3.742859 69.69904 109 | 3.742859 69.69904 110 | -2.079244 76.51087 111 | 4.077324 74.9028 112 | 3.742859 69.69904 113 | 4.077324 74.9028 114 | 9.516804 65.68592 115 | 9.516804 65.68592 116 | 4.077324 74.9028 117 | 10.36582 73.93119 118 | 9.516804 65.68592 119 | 10.36582 73.93119 120 | 14.1489 60.39562 121 | 14.1489 60.39562 122 | 10.36582 73.93119 123 | 16.72063 73.60619 124 | 14.1489 60.39562 125 | 16.72063 73.60619 126 | 17.36419 54.14218 127 | 17.36419 54.14218 128 | 16.72063 73.60619 129 | 23.07544 73.93119 130 | 17.36419 54.14218 131 | 23.07544 73.93119 132 | 19.14039 41.22425 133 | 92.15467 80.62257 134 | 88.83104 50.24595 135 | 88.0531 85.73196 136 | 88.83104 50.24595 137 | 92.15467 80.62257 138 | 92.70476 55.53018 139 | 92.70476 55.53018 140 | 92.15467 80.62257 141 | 94.79408 74.62572 142 | 92.70476 55.53018 143 | 94.79408 74.62572 144 | 95.07883 61.63694 145 | 95.07883 61.63694 146 | 94.79408 74.62572 147 | 95.79146 68.15007 148 | -138.3173 50.47565 149 | -137.432 24.73624 150 | -140.3168 37.52194 151 | -137.432 24.73624 152 | -138.3173 50.47565 153 | -131.7115 61.79639 154 | -137.432 24.73624 155 | -131.7115 61.79639 156 | -130.0639 13.89615 157 | -130.0639 13.89615 158 | -131.7115 61.79639 159 | -121.4177 69.91023 160 | -130.0639 13.89615 161 | -121.4177 69.91023 162 | -119.2369 6.508783 163 | -119.2369 6.508783 164 | -121.4177 69.91023 165 | -108.8671 73.6891 166 | -119.2369 6.508783 167 | -108.8671 73.6891 168 | -106.4564 3.601217 169 | -106.4564 3.601217 170 | -108.8671 73.6891 171 | -95.8047 72.60761 172 | -106.4564 3.601217 173 | -95.8047 72.60761 174 | -104.7373 -44.7788 175 | -104.7373 -44.7788 176 | -95.8047 72.60761 177 | -95.3204 -50.22474 178 | -95.3204 -50.22474 179 | -95.8047 72.60761 180 | -84.0465 66.81613 181 | -95.3204 -50.22474 182 | -84.0465 66.81613 183 | -84.63247 -52.25073 184 | -84.63247 -52.25073 185 | -84.0465 66.81613 186 | -73.87579 -50.62886 187 | -73.87579 -50.62886 188 | -84.0465 66.81613 189 | -75.22729 57.11985 190 | -73.87579 -50.62886 191 | -75.22729 57.11985 192 | -70.57319 44.86685 193 | -73.87579 -50.62886 194 | -70.57319 44.86685 195 | -64.26037 -45.54158 196 | -64.26037 -45.54158 197 | -70.57319 44.86685 198 | -69.61521 31.86262 199 | -64.26037 -45.54158 200 | -69.61521 31.86262 201 | -64.96236 19.68153 202 | -64.26037 -45.54158 203 | -64.96236 19.68153 204 | -57.00677 9.350201 205 | -64.26037 -45.54158 206 | -57.00677 9.350201 207 | -56.86785 -37.56115 208 | -56.86785 -37.56115 209 | -57.00677 9.350201 210 | -51.7342 -16.73615 211 | -51.7342 -16.73615 212 | -57.00677 9.350201 213 | -46.41893 1.739326 214 | -56.86785 -37.56115 215 | -51.7342 -16.73615 216 | -52.52979 -27.58529 217 | -51.7342 -16.73615 218 | -46.41893 1.739326 219 | -43.24859 -39.15101 220 | -43.24859 -39.15101 221 | -46.41893 1.739326 222 | -34.09116 -2.50966 223 | -43.24859 -39.15101 224 | -34.09116 -2.50966 225 | -28.50562 -58.04747 226 | -28.50562 -58.04747 227 | -34.09116 -2.50966 228 | -21.06243 -3.038659 229 | -28.50562 -58.04747 230 | -21.06243 -3.038659 231 | -8.827904 -71.73027 232 | -8.827904 -71.73027 233 | -21.06243 -3.038659 234 | -8.430764 0.1969107 235 | -8.827904 -71.73027 236 | -8.430764 0.1969107 237 | 14.01921 -78.97189 238 | 14.01921 -78.97189 239 | -8.430764 0.1969107 240 | 2.739249 6.924362 241 | 14.01921 -78.97189 242 | 2.739249 6.924362 243 | 11.50623 16.57672 244 | 14.01921 -78.97189 245 | 11.50623 16.57672 246 | 17.1313 28.34049 247 | 14.01921 -78.97189 248 | 17.1313 28.34049 249 | 37.98603 -79.12265 250 | 37.98603 -79.12265 251 | 17.1313 28.34049 252 | 19.14039 41.22425 253 | 37.98603 -79.12265 254 | 19.14039 41.22425 255 | 23.07544 73.93119 256 | 37.98603 -79.12265 257 | 23.07544 73.93119 258 | 29.36394 74.9028 259 | 37.98603 -79.12265 260 | 29.36394 74.9028 261 | 35.52051 76.51087 262 | 37.98603 -79.12265 263 | 35.52051 76.51087 264 | 41.48091 78.73864 265 | 37.98603 -79.12265 266 | 41.48091 78.73864 267 | 60.92244 -72.16905 268 | 60.92244 -72.16905 269 | 41.48091 78.73864 270 | 47.18293 81.56284 271 | 60.92244 -72.16905 272 | 47.18293 81.56284 273 | 52.56709 84.95402 274 | 60.92244 -72.16905 275 | 52.56709 84.95402 276 | 57.67648 89.0556 277 | 60.92244 -72.16905 278 | 57.67648 89.0556 279 | 63.67333 91.69501 280 | 60.92244 -72.16905 281 | 63.67333 91.69501 282 | 80.77074 -58.7349 283 | 80.77074 -58.7349 284 | 63.67333 91.69501 285 | 70.14898 92.69238 286 | 80.77074 -58.7349 287 | 70.14898 92.69238 288 | 76.66211 91.97975 289 | 80.77074 -58.7349 290 | 76.66211 91.97975 291 | 82.76887 89.60568 292 | 80.77074 -58.7349 293 | 82.76887 89.60568 294 | 95.75028 -40.02542 295 | 95.75028 -40.02542 296 | 82.76887 89.60568 297 | 88.83104 50.24595 298 | 88.83104 50.24595 299 | 82.76887 89.60568 300 | 88.0531 85.73196 301 | 95.75028 -40.02542 302 | 88.83104 50.24595 303 | 100.8951 29.53631 304 | 95.75028 -40.02542 305 | 100.8951 29.53631 306 | 104.5172 -17.71909 307 | 104.5172 -17.71909 308 | 100.8951 29.53631 309 | 106.285 6.182927 310 | -38.45807 33.09269 311 | -38.28861 40.08139 312 | -37.78529 35.38022 313 | -38.28861 40.08139 314 | -38.45807 33.09269 315 | -38.42946 47.11159 316 | -37.78529 35.38022 317 | -38.28861 40.08139 318 | -37.72749 37.76394 319 | 320 | -------------------------------------------------------------------------------- /Polygon/Polygon.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /// Changes from the Java version 33 | /// Polygon constructors sprused up, checks for 3+ polys 34 | /// Naming of everything 35 | /// getTriangulationMode() -> TriangulationMode { get; } 36 | /// Exceptions replaced 37 | /// Future possibilities 38 | /// We have a lot of Add/Clear methods -- we may prefer to just expose the container 39 | /// Some self-explanitory methods may deserve commenting anyways 40 | 41 | using System; 42 | using System.Collections.Generic; 43 | using System.Linq; 44 | 45 | namespace Poly2Tri { 46 | public class Polygon : Triangulatable { 47 | protected List _points = new List(); 48 | protected List _steinerPoints; 49 | protected List _holes; 50 | protected List _triangles; 51 | protected PolygonPoint _last; 52 | 53 | /// 54 | /// Create a polygon from a list of at least 3 points with no duplicates. 55 | /// 56 | /// A list of unique points 57 | public Polygon( IList points ) { 58 | if (points.Count < 3) throw new ArgumentException("List has fewer than 3 points", "points"); 59 | 60 | // Lets do one sanity check that first and last point hasn't got same position 61 | // Its something that often happen when importing polygon data from other formats 62 | if (points[0].Equals(points[points.Count - 1])) points.RemoveAt(points.Count - 1); 63 | 64 | _points.AddRange(points.Cast()); 65 | } 66 | 67 | /// 68 | /// Create a polygon from a list of at least 3 points with no duplicates. 69 | /// 70 | /// A list of unique points. 71 | public Polygon( IEnumerable points ): this( (points as IList) ?? points.ToArray() ) {} 72 | 73 | /// 74 | /// Create a polygon from a list of at least 3 points with no duplicates. 75 | /// 76 | /// A list of unique points. 77 | public Polygon( params PolygonPoint[] points ) : this((IList)points) { } 78 | 79 | public TriangulationMode TriangulationMode { get { return TriangulationMode.Polygon; } } 80 | 81 | public void AddSteinerPoint( TriangulationPoint point ) { 82 | if (_steinerPoints == null) _steinerPoints = new List(); 83 | _steinerPoints.Add(point); 84 | } 85 | 86 | public void AddSteinerPoints( List points ) { 87 | if (_steinerPoints == null) _steinerPoints = new List(); 88 | _steinerPoints.AddRange(points); 89 | } 90 | 91 | public void ClearSteinerPoints() { 92 | if (_steinerPoints != null) _steinerPoints.Clear(); 93 | } 94 | 95 | /// 96 | /// Add a hole to the polygon. 97 | /// 98 | /// A subtraction polygon fully contained inside this polygon. 99 | public void AddHole( Polygon poly ) { 100 | if (_holes == null) _holes = new List(); 101 | _holes.Add(poly); 102 | // XXX: tests could be made here to be sure it is fully inside 103 | // addSubtraction( poly.getPoints() ); 104 | } 105 | 106 | /// 107 | /// Inserts newPoint after point. 108 | /// 109 | /// The point to insert after in the polygon 110 | /// The point to insert into the polygon 111 | public void InsertPointAfter( PolygonPoint point, PolygonPoint newPoint ) { 112 | // Validate that 113 | int index = _points.IndexOf(point); 114 | if (index == -1) throw new ArgumentException("Tried to insert a point into a Polygon after a point not belonging to the Polygon", "point"); 115 | newPoint.Next = point.Next; 116 | newPoint.Previous = point; 117 | point.Next.Previous = newPoint; 118 | point.Next = newPoint; 119 | _points.Insert(index + 1, newPoint); 120 | } 121 | 122 | /// 123 | /// Inserts list (after last point in polygon?) 124 | /// 125 | /// 126 | public void AddPoints( IEnumerable list ) { 127 | PolygonPoint first; 128 | foreach (PolygonPoint p in list) { 129 | p.Previous = _last; 130 | if (_last != null) { 131 | p.Next = _last.Next; 132 | _last.Next = p; 133 | } 134 | _last = p; 135 | _points.Add(p); 136 | } 137 | first = (PolygonPoint)_points[0]; 138 | _last.Next = first; 139 | first.Previous = _last; 140 | } 141 | 142 | /// 143 | /// Adds a point after the last in the polygon. 144 | /// 145 | /// The point to add 146 | public void AddPoint( PolygonPoint p ) { 147 | p.Previous = _last; 148 | p.Next = _last.Next; 149 | _last.Next = p; 150 | _points.Add(p); 151 | } 152 | 153 | /// 154 | /// Removes a point from the polygon. 155 | /// 156 | /// 157 | public void RemovePoint( PolygonPoint p ) { 158 | PolygonPoint next, prev; 159 | 160 | next = p.Next; 161 | prev = p.Previous; 162 | prev.Next = next; 163 | next.Previous = prev; 164 | _points.Remove(p); 165 | } 166 | 167 | public IList Points { get { return _points; } } 168 | public IList Triangles { get { return _triangles; } } 169 | public IList Holes { get { return _holes; }} 170 | 171 | public void AddTriangle( DelaunayTriangle t ) { 172 | _triangles.Add(t); 173 | } 174 | 175 | public void AddTriangles( IEnumerable list ) { 176 | _triangles.AddRange(list); 177 | } 178 | 179 | public void ClearTriangles() { 180 | if (_triangles != null) _triangles.Clear(); 181 | } 182 | 183 | /// 184 | /// Creates constraints and populates the context with points 185 | /// 186 | /// The context 187 | public void Prepare( TriangulationContext tcx ) { 188 | if (_triangles == null) { 189 | _triangles = new List(_points.Count); 190 | } else { 191 | _triangles.Clear(); 192 | } 193 | 194 | // Outer constraints 195 | for (int i = 0; i < _points.Count - 1; i++) tcx.NewConstraint(_points[i], _points[i + 1]); 196 | tcx.NewConstraint(_points[0], _points[_points.Count - 1]); 197 | tcx.Points.AddRange(_points); 198 | 199 | // Hole constraints 200 | if (_holes != null) { 201 | foreach (Polygon p in _holes) { 202 | for (int i = 0; i < p._points.Count - 1; i++) tcx.NewConstraint(p._points[i], p._points[i + 1]); 203 | tcx.NewConstraint(p._points[0], p._points[p._points.Count - 1]); 204 | tcx.Points.AddRange(p._points); 205 | } 206 | } 207 | 208 | if (_steinerPoints != null) { 209 | tcx.Points.AddRange(_steinerPoints); 210 | } 211 | } 212 | 213 | } 214 | } 215 | -------------------------------------------------------------------------------- /Triangulation/Delaunay/DelaunayTriangle.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /// Changes from the Java version 33 | /// attributification 34 | /// Future possibilities 35 | /// Flattening out the number of indirections 36 | /// Replacing arrays of 3 with fixed-length arrays? 37 | /// Replacing bool[3] with a bit array of some sort? 38 | /// Bundling everything into an AoS mess? 39 | /// Hardcode them all as ABC ? 40 | 41 | using System; 42 | using System.Diagnostics; 43 | using System.Collections.Generic; 44 | 45 | namespace Poly2Tri { 46 | public class DelaunayTriangle { 47 | public FixedArray3 Points; 48 | public FixedArray3 Neighbors; 49 | public FixedBitArray3 EdgeIsConstrained, EdgeIsDelaunay; 50 | public bool IsInterior { get; set; } 51 | 52 | public DelaunayTriangle(TriangulationPoint p1, TriangulationPoint p2, TriangulationPoint p3) { 53 | Points[0] = p1; 54 | Points[1] = p2; 55 | Points[2] = p3; 56 | } 57 | 58 | public int IndexOf(TriangulationPoint p) { 59 | int i = Points.IndexOf(p); 60 | if (i==-1) throw new Exception("Calling index with a point that doesn't exist in triangle"); 61 | return i; 62 | } 63 | 64 | public int IndexCWFrom (TriangulationPoint p) { return (IndexOf(p)+2)%3; } 65 | public int IndexCCWFrom(TriangulationPoint p) { return (IndexOf(p)+1)%3; } 66 | 67 | public bool Contains(TriangulationPoint p) { return Points.Contains(p); } 68 | 69 | /// 70 | /// Update neighbor pointers 71 | /// 72 | /// Point 1 of the shared edge 73 | /// Point 2 of the shared edge 74 | /// This triangle's new neighbor 75 | private void MarkNeighbor( TriangulationPoint p1, TriangulationPoint p2, DelaunayTriangle t ) { 76 | int i = EdgeIndex(p1,p2); 77 | if ( i==-1 ) throw new Exception( "Error marking neighbors -- t doesn't contain edge p1-p2!" ); 78 | Neighbors[i] = t; 79 | } 80 | 81 | /// 82 | /// Exhaustive search to update neighbor pointers 83 | /// 84 | public void MarkNeighbor( DelaunayTriangle t ) { 85 | // Points of this triangle also belonging to t 86 | bool a = t.Contains(Points[0]); 87 | bool b = t.Contains(Points[1]); 88 | bool c = t.Contains(Points[2]); 89 | 90 | if (b&&c) { Neighbors[0]=t; t.MarkNeighbor(Points[1],Points[2],this); } 91 | else if (a&&c) { Neighbors[1]=t; t.MarkNeighbor(Points[0],Points[2],this); } 92 | else if (a&&b) { Neighbors[2]=t; t.MarkNeighbor(Points[0],Points[1],this); } 93 | else throw new Exception( "Failed to mark neighbor, doesn't share an edge!"); 94 | } 95 | 96 | /// Opposite triangle 97 | /// The point in t that isn't shared between the triangles 98 | public TriangulationPoint OppositePoint(DelaunayTriangle t, TriangulationPoint p) { 99 | Debug.Assert(t != this, "self-pointer error"); 100 | return PointCWFrom(t.PointCWFrom(p)); 101 | } 102 | 103 | public DelaunayTriangle NeighborCWFrom (TriangulationPoint point) { return Neighbors[(Points.IndexOf(point)+1)%3]; } 104 | public DelaunayTriangle NeighborCCWFrom (TriangulationPoint point) { return Neighbors[(Points.IndexOf(point)+2)%3]; } 105 | public DelaunayTriangle NeighborAcrossFrom(TriangulationPoint point) { return Neighbors[ Points.IndexOf(point) ]; } 106 | 107 | public TriangulationPoint PointCCWFrom(TriangulationPoint point) { return Points[(IndexOf(point)+1)%3]; } 108 | public TriangulationPoint PointCWFrom (TriangulationPoint point) { return Points[(IndexOf(point)+2)%3]; } 109 | 110 | private void RotateCW() { 111 | var t = Points[2]; 112 | Points[2] = Points[1]; 113 | Points[1] = Points[0]; 114 | Points[0] = t; 115 | } 116 | 117 | /// 118 | /// Legalize triangle by rotating clockwise around oPoint 119 | /// 120 | /// The origin point to rotate around 121 | /// ??? 122 | public void Legalize(TriangulationPoint oPoint, TriangulationPoint nPoint) { 123 | RotateCW(); 124 | Points[IndexCCWFrom(oPoint)] = nPoint; 125 | } 126 | 127 | public override string ToString() { return Points[0] + "," + Points[1] + "," + Points[2]; } 128 | 129 | /// 130 | /// Finalize edge marking 131 | /// 132 | public void MarkNeighborEdges() { 133 | for (int i = 0; i < 3; i++) if ( EdgeIsConstrained[i] && Neighbors[i] != null ) { 134 | Neighbors[i].MarkConstrainedEdge(Points[(i+1)%3], Points[(i+2)%3]); 135 | } 136 | } 137 | 138 | public void MarkEdge(DelaunayTriangle triangle) { 139 | for (int i = 0; i < 3; i++) if ( EdgeIsConstrained[i] ) { 140 | triangle.MarkConstrainedEdge(Points[(i+1)%3], Points[(i+2)%3]); 141 | } 142 | } 143 | 144 | public void MarkEdge(List tList) { 145 | foreach ( DelaunayTriangle t in tList ) 146 | for ( int i = 0; i < 3; i++ ) 147 | if ( t.EdgeIsConstrained[i] ) 148 | { 149 | MarkConstrainedEdge( t.Points[(i+1)%3], t.Points[(i+2)%3] ); 150 | } 151 | } 152 | 153 | public void MarkConstrainedEdge(int index) { 154 | EdgeIsConstrained[index] = true; 155 | } 156 | 157 | public void MarkConstrainedEdge(DTSweepConstraint edge) { 158 | MarkConstrainedEdge(edge.P, edge.Q); 159 | } 160 | 161 | /// 162 | /// Mark edge as constrained 163 | /// 164 | public void MarkConstrainedEdge(TriangulationPoint p, TriangulationPoint q) { 165 | int i = EdgeIndex(p,q); 166 | if ( i != -1 ) EdgeIsConstrained[i] = true; 167 | } 168 | 169 | public double Area() { 170 | double b = Points[0].X - Points[1].X; 171 | double h = Points[2].Y - Points[1].Y; 172 | 173 | return Math.Abs((b * h * 0.5f)); 174 | } 175 | 176 | public TriangulationPoint Centroid() { 177 | double cx = (Points[0].X + Points[1].X + Points[2].X) / 3f; 178 | double cy = (Points[0].Y + Points[1].Y + Points[2].Y) / 3f; 179 | return new TriangulationPoint(cx, cy); 180 | } 181 | 182 | /// 183 | /// Get the index of the neighbor that shares this edge (or -1 if it isn't shared) 184 | /// 185 | /// index of the shared edge or -1 if edge isn't shared 186 | public int EdgeIndex(TriangulationPoint p1, TriangulationPoint p2) { 187 | int i1 = Points.IndexOf(p1); 188 | int i2 = Points.IndexOf(p2); 189 | 190 | // Points of this triangle in the edge p1-p2 191 | bool a = (i1==0 || i2==0); 192 | bool b = (i1==1 || i2==1); 193 | bool c = (i1==2 || i2==2); 194 | 195 | if (b&&c) return 0; 196 | if (a&&c) return 1; 197 | if (a&&b) return 2; 198 | return -1; 199 | } 200 | 201 | public bool GetConstrainedEdgeCCW ( TriangulationPoint p ) { return EdgeIsConstrained[(IndexOf(p)+2)%3]; } 202 | public bool GetConstrainedEdgeCW ( TriangulationPoint p ) { return EdgeIsConstrained[(IndexOf(p)+1)%3]; } 203 | public bool GetConstrainedEdgeAcross( TriangulationPoint p ) { return EdgeIsConstrained[ IndexOf(p) ]; } 204 | public void SetConstrainedEdgeCCW ( TriangulationPoint p, bool ce ) { EdgeIsConstrained[(IndexOf(p)+2)%3] = ce; } 205 | public void SetConstrainedEdgeCW ( TriangulationPoint p, bool ce ) { EdgeIsConstrained[(IndexOf(p)+1)%3] = ce; } 206 | public void SetConstrainedEdgeAcross( TriangulationPoint p, bool ce ) { EdgeIsConstrained[ IndexOf(p) ] = ce; } 207 | 208 | public bool GetDelaunayEdgeCCW ( TriangulationPoint p ) { return EdgeIsDelaunay[(IndexOf(p)+2)%3]; } 209 | public bool GetDelaunayEdgeCW ( TriangulationPoint p ) { return EdgeIsDelaunay[(IndexOf(p)+1)%3]; } 210 | public bool GetDelaunayEdgeAcross( TriangulationPoint p ) { return EdgeIsDelaunay[ IndexOf(p) ]; } 211 | public void SetDelaunayEdgeCCW ( TriangulationPoint p, bool ce ) { EdgeIsDelaunay[(IndexOf(p)+2)%3] = ce; } 212 | public void SetDelaunayEdgeCW ( TriangulationPoint p, bool ce ) { EdgeIsDelaunay[(IndexOf(p)+1)%3] = ce; } 213 | public void SetDelaunayEdgeAcross( TriangulationPoint p, bool ce ) { EdgeIsDelaunay[ IndexOf(p) ] = ce; } 214 | } 215 | } 216 | -------------------------------------------------------------------------------- /ExampleData/Data/polygon.dae: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Google SketchUp 7.1.4871 6 | 7 | 2009-12-21T01:51:00Z 8 | 2009-12-21T01:51:00Z 9 | 10 | Z_UP 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -112.9393 -5.134218 -5.952325e-030 -115.783 -26.39329 -4.065249e-030 -116.1693 -15.52189 -5.174618e-030 -111.8239 -36.52552 -2.74901e-030 -106.4564 3.601217 -6.310887e-030 -104.7373 -44.7788 -1.373963e-030 -66.76277 70.05491 -5.637993e-014 -68.21937 53.83701 -4.127297e-014 -68.55863 62.04185 -5.054886e-014 -65.7681 45.99956 -2.91844e-014 -62.95416 77.33014 -5.83688e-014 -61.37187 39.0636 -1.510696e-014 -57.39237 83.37173 -5.637993e-014 -55.33028 33.5018 0 -50.4564 87.76796 -5.054886e-014 -54.18848 31.40854 0 -52.54381 29.68213 0 -50.50835 28.44022 0 -48.22082 27.76744 0 -42.61895 90.21923 -4.127297e-014 -45.8371 27.70964 0 -43.51965 28.27076 0 -41.4264 29.41256 0 -34.41412 90.55849 -2.91844e-014 -38.42946 47.11159 0 -39.69999 31.05723 0 -38.45807 33.09269 0 -36.86605 53.9672 0 -33.69118 60.24126 0 -26.40105 88.76263 -1.510696e-014 -29.09332 65.56134 0 -23.3454 69.61164 0 -19.12582 84.95402 1.877284e-029 -16.7886 72.15173 0 -13.74167 81.56284 1.269697e-029 -9.81216 73.03084 0 -8.03964 78.73864 7.636926e-030 -2.830188 72.19677 0 -2.079244 76.51087 3.64551e-030 3.742859 69.69904 0 4.077324 74.9028 7.643719e-031 9.516804 65.68592 0 10.36582 73.93119 -9.764253e-031 14.1489 60.39562 0 16.72063 73.60619 -1.558716e-030 17.36419 54.14218 0 23.07544 73.93119 -9.764253e-031 19.14039 41.22425 0 92.15467 80.62257 -5.238305e-014 88.83104 50.24595 2.085226e-030 88.0531 85.73196 -5.423092e-014 92.70476 55.53018 -1.403599e-014 94.79408 74.62572 -4.696535e-014 95.07883 61.63694 -2.711546e-014 95.79146 68.15007 -3.834705e-014 -138.3173 50.47565 -5.441105e-014 -137.432 24.73624 -3.697808e-014 -140.3168 37.52194 -4.746962e-014 -131.7115 61.79639 -5.68373e-014 -130.0639 13.89615 -2.439509e-014 -121.4177 69.91023 -5.441105e-014 -119.2369 6.508783 -1.147007e-014 -108.8671 73.6891 -4.746962e-014 -95.8047 72.60761 -3.697808e-014 -95.3204 -50.22474 -9.478654e-032 -84.0465 66.81613 -2.439509e-014 -84.63247 -52.25073 9.446271e-031 -73.87579 -50.62886 1.627355e-030 -75.22729 57.11985 -1.147007e-014 -70.57319 44.86685 0 -64.26037 -45.54158 1.876598e-030 -69.61521 31.86262 0 -64.96236 19.68153 0 -57.00677 9.350201 0 -56.86785 -37.56115 1.664318e-030 -51.7342 -16.73615 -6.04464e-035 -46.41893 1.739326 0 -52.52979 -27.58529 1.014396e-030 -43.24859 -39.15101 -3.163366e-031 -34.09116 -2.50966 0 -28.50562 -58.04747 -5.308165e-031 -21.06243 -3.038659 0 -8.827904 -71.73027 -6.242584e-031 -8.430764 0.1969107 0 14.01921 -78.97189 -5.882796e-031 2.739249 6.924362 0 11.50623 16.57672 0 17.1313 28.34049 0 37.98603 -79.12265 -4.261077e-031 29.36394 74.9028 7.643719e-031 35.52051 76.51087 3.64551e-030 41.48091 78.73864 7.636926e-030 60.92244 -72.16905 -1.522917e-031 47.18293 81.56284 1.269697e-029 52.56709 84.95402 1.877284e-029 57.67648 89.0556 -1.403599e-014 63.67333 91.69501 -2.711546e-014 80.77074 -58.7349 2.086037e-031 70.14898 92.69238 -3.834705e-014 76.66211 91.97975 -4.696535e-014 82.76887 89.60568 -5.238305e-014 95.75028 -40.02542 6.242015e-031 100.8951 29.53631 1.822036e-030 104.5172 -17.71909 1.057217e-030 106.285 6.182927 1.468804e-030 -38.28861 40.08139 0 -37.78529 35.38022 0 -37.72749 37.76394 0 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 5.652422e-017 -2.025185e-016 -1 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |

0 1 2 1 0 3 3 0 4 3 4 5 6 7 8 7 6 9 9 6 10 9 10 11 11 10 12 11 12 13 13 12 14 13 14 15 15 14 16 16 14 17 17 14 18 18 14 19 18 19 20 20 19 21 21 19 22 22 19 23 22 23 24 22 24 25 25 24 26 24 23 27 27 23 28 28 23 29 28 29 30 30 29 31 31 29 32 31 32 33 33 32 34 33 34 35 35 34 36 35 36 37 37 36 38 37 38 39 39 38 40 39 40 41 41 40 42 41 42 43 43 42 44 43 44 45 45 44 46 45 46 47 48 49 50 49 48 51 51 48 52 51 52 53 53 52 54 55 56 57 56 55 58 56 58 59 59 58 60 59 60 61 61 60 62 61 62 4 4 62 63 4 63 5 5 63 64 64 63 65 64 65 66 66 65 67 67 65 68 67 68 69 67 69 70 70 69 71 70 71 72 70 72 73 70 73 74 74 73 75 75 73 76 74 75 77 75 76 78 78 76 79 78 79 80 80 79 81 80 81 82 82 81 83 82 83 84 84 83 85 84 85 86 84 86 87 84 87 88 88 87 47 88 47 46 88 46 89 88 89 90 88 90 91 88 91 92 92 91 93 92 93 94 92 94 95 92 95 96 92 96 97 97 96 98 97 98 99 97 99 100 97 100 101 101 100 49 49 100 50 101 49 102 101 102 103 103 102 104 26 105 106 105 26 24 106 105 107

57 |
58 |
59 |
60 |
61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 1 1 1 1 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 |
83 | -------------------------------------------------------------------------------- /Debug/DebugForm.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System; 33 | using System.Collections.Generic; 34 | using System.Drawing; 35 | using System.Drawing.Drawing2D; 36 | using System.Linq; 37 | using System.Windows.Forms; 38 | using System.Drawing.Imaging; 39 | 40 | namespace Poly2Tri { 41 | [System.ComponentModel.DesignerCategory("")] class DebugForm : Form { 42 | List Infos = new List() 43 | { new PolygonInfo( "Two", (ExampleData.Two )) 44 | , new PolygonInfo( "Bird", (ExampleData.Bird )) 45 | , new PolygonInfo( "Custom", (ExampleData.Custom )) 46 | , new PolygonInfo( "Debug", (ExampleData.Debug )) 47 | , new PolygonInfo( "Debug2", (ExampleData.Debug2 )) 48 | , new PolygonInfo( "Diamond", (ExampleData.Diamond )) 49 | , new PolygonInfo( "Dude", (ExampleData.Dude )) 50 | , new PolygonInfo( "Funny", (ExampleData.Funny )) 51 | , new PolygonInfo( "NazcaHeron", (ExampleData.NazcaHeron )) 52 | , new PolygonInfo( "NazcaMonkey", (ExampleData.NazcaMonkey )) 53 | , new PolygonInfo( "Sketchup", (ExampleData.Sketchup )) 54 | , new PolygonInfo( "Star", (ExampleData.Star )) 55 | , new PolygonInfo( "Strange", (ExampleData.Strange )) 56 | , new PolygonInfo( "Tank", (ExampleData.Tank )) 57 | , new PolygonInfo( "Test", (ExampleData.Test )) 58 | }; 59 | 60 | int InfoI = 0; 61 | public PolygonInfo Info { get { return Infos[InfoI]; } } 62 | 63 | DateTime PointBounceStart = DateTime.Now; 64 | int PointBounceIndex; 65 | 66 | DebugForm() { 67 | ClientSize = new Size(800,600); 68 | BackColor = Color.Black; 69 | ForeColor = Color.White; 70 | DoubleBuffered = true; 71 | StartPosition = FormStartPosition.CenterScreen; 72 | Text = "Poly2Tri Example & Debug setup"; 73 | } 74 | 75 | int LineY; 76 | void AddText( Graphics fx, string text ) { 77 | TextRenderer.DrawText( fx, text, Font, new Point(10,LineY), ForeColor ); 78 | LineY += TextRenderer.MeasureText( text, Font ).Height; 79 | } 80 | 81 | void AddText( Graphics fx, string format, params object[] args ) { AddText(fx,String.Format(format,args)); } 82 | 83 | void AddText( Graphics fx, Exception e ) { 84 | if ( e == null ) return; 85 | 86 | string text = "Exception: "+e.Message; 87 | TextRenderer.DrawText( fx, text, Font, new Point(10,LineY), Color.Red ); 88 | LineY += TextRenderer.MeasureText( text, Font ).Height; 89 | 90 | while ( e.InnerException != null ) { 91 | e = e.InnerException; 92 | text = "Innert Exception: "+e.Message; 93 | TextRenderer.DrawText( fx, text, Font, new Point(10,LineY), Color.Red ); 94 | LineY += TextRenderer.MeasureText( text, Font ).Height; 95 | } 96 | } 97 | 98 | protected override void OnKeyDown( KeyEventArgs e ) { 99 | e.Handled = true; 100 | switch ( e.KeyCode ) { 101 | case Keys.G: GC.GetTotalMemory(true); break; 102 | case Keys.Left: 103 | if ( --InfoI < 0 ) InfoI += Infos.Count; 104 | break; 105 | case Keys.Right: 106 | if ( ++InfoI >= Infos.Count ) InfoI -= Infos.Count; 107 | break; 108 | default: 109 | e.Handled = false; 110 | base.OnKeyDown(e); 111 | break; 112 | } 113 | } 114 | 115 | static int FrameI=0; 116 | 117 | Bitmap FrameCache; 118 | DateTime PreviousFrame = DateTime.Now; 119 | Action EachFrame; // = (b) => { b.Save(string.Format(@"C:\frames\{0}.png",FrameI++),ImageFormat.Png); }; 120 | protected override void OnPaint( PaintEventArgs e ) { 121 | var now = (EachFrame==null) ? DateTime.Now : PreviousFrame.AddSeconds(1.0/60); // change logical framerate to 60fps if frame capturing 122 | 123 | var fx = e.Graphics; 124 | fx.Clear( BackColor ); 125 | 126 | var framestart = DateTime.Now; 127 | 128 | if ( Info == null ) 129 | { 130 | TextRenderer.DrawText( fx, "No polygon selected.", Font, ClientRectangle, ForeColor, Color.Transparent, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter ); 131 | } 132 | else 133 | using ( var pointpen = new Pen( Color.White, 1.0f ) ) 134 | using ( var outlinepen = new Pen( Color.Blue , 3.0f ) ) 135 | using ( var holepen = new Pen( Color.Red , 3.0f ) ) 136 | using ( var tripen = new Pen( Color.Green, 1.0f ) ) 137 | using ( var poeepen = new Pen( Color.Red , 10.0f ) ) 138 | using ( var boblinepen = new Pen( Color.Blue , 10.0f ) ) 139 | { 140 | foreach ( var pen in new[] { pointpen, outlinepen, holepen, tripen, poeepen, boblinepen } ) { 141 | pen.StartCap = pen.EndCap = LineCap.Round; 142 | pen.LineJoin = LineJoin.Round; 143 | } 144 | 145 | Info.Triangulate(); 146 | 147 | fx.SmoothingMode = SmoothingMode.AntiAlias; 148 | fx.TranslateTransform(ClientSize.Width/2,ClientSize.Height/2); 149 | 150 | float bounce = (float)((now-PointBounceStart).TotalSeconds*5); 151 | if ( bounce > 1 ) { 152 | bounce = 0; 153 | PointBounceStart = now; 154 | ++PointBounceIndex; 155 | } 156 | 157 | float xmin = float.MaxValue, xmax = float.MinValue; 158 | float ymin = float.MaxValue, ymax = float.MinValue; 159 | 160 | if ( Info.Polygon.Points != null ) foreach ( var point in Info.Polygon.Points ) { 161 | xmin = Math.Min(xmin,point.Xf); 162 | xmax = Math.Max(xmax,point.Xf); 163 | ymin = Math.Min(ymin,point.Yf); 164 | ymax = Math.Max(ymax,point.Yf); 165 | } 166 | 167 | float zoom = 0.8f * Math.Min(ClientSize.Width/(xmax-xmin),ClientSize.Height/(ymax-ymin)); 168 | float xmid = (xmin+xmax)/2; 169 | float ymid = (ymin+ymax)/2; 170 | 171 | Func f = (p) => new PointF( (p.Xf-xmid)*zoom, (p.Yf-ymid)*zoom ); 172 | 173 | if ( Info.Polygon.Points != null ) { 174 | PointBounceIndex %= Info.Polygon.Points.Count; 175 | fx.DrawPolygon( outlinepen, Info.Polygon.Points.Select(f).ToArray() ); 176 | 177 | if ( Info.Polygon.Holes != null ) foreach ( var hole in Info.Polygon.Holes ) fx.DrawPolygon( holepen, hole.Points.Select(f).ToArray() ); 178 | 179 | boblinepen.Width = 3.0f + 9-9*bounce; 180 | fx.DrawLine( boblinepen, f(Info.Polygon.Points[(PointBounceIndex+Info.Polygon.Points.Count-1)%Info.Polygon.Points.Count]), f(Info.Polygon.Points[PointBounceIndex]) ); 181 | } 182 | 183 | if ( Info.Polygon.Triangles != null ) 184 | foreach ( var tri in Info.Polygon.Triangles ) 185 | { 186 | fx.DrawPolygon( tripen, tri.Points.Select(f).ToArray() ); 187 | } 188 | 189 | if ( Info.Polygon.Points != null ) { 190 | foreach ( var poly in new[]{Info.Polygon}.Concat(Info.Polygon.Holes ?? new Polygon[]{}) ) 191 | for ( int i = 0 ; i < poly.Points.Count ; ++i ) 192 | { 193 | var point = f(poly.Points[i]); 194 | float r = 2.0f; 195 | if ( PointBounceIndex==i ) r += 2-2*bounce; 196 | fx.DrawEllipse( pointpen, point.X-r, point.Y-r, 2*r, 2*r ); 197 | } 198 | } 199 | 200 | var poee = Info.LastTriangulationException as PointOnEdgeException; 201 | if ( poee != null ) { 202 | var line = new PointF[] { f(poee.A), f(poee.B), f(poee.C) }; 203 | fx.DrawLines( poeepen, line ); 204 | foreach ( var p in line ) fx.DrawEllipse( poeepen, p.X-2, p.Y-2, 4, 4 ); 205 | } 206 | 207 | var polyrenderend = DateTime.Now; // not counting all the text processing 208 | fx.ResetTransform(); 209 | LineY=10; 210 | AddText(fx, "{0} Points: {1} Triangles: {2}" 211 | , Info.Name 212 | , (Info.Polygon.Points ==null ? 0 : Info.Polygon.Points.Count) 213 | , (Info.Polygon.Triangles==null ? 0 : Info.Polygon.Triangles.Count) 214 | ); 215 | AddText(fx," "); 216 | 217 | AddText(fx,"Memory: "+(GC.GetTotalMemory(false)/1000000).ToString("N0")+"MB"); 218 | string s = "Collections "; 219 | for ( int i=0, g=GC.MaxGeneration ; i < g ; ++i ) s = s + " Gen"+i+": "+GC.CollectionCount(i); 220 | AddText(fx,s); 221 | 222 | AddText(fx,"Time Triangulation: {0}ms Render: {1}ms" 223 | , Info.LastTriangulationDuration.TotalMilliseconds.ToString("N0") 224 | , (polyrenderend-framestart).TotalMilliseconds.ToString("N0") 225 | ); 226 | AddText(fx,Info.LastTriangulationException); 227 | 228 | fx.InterpolationMode = InterpolationMode.High; 229 | float size = Math.Min( 256.0f, Math.Min( ClientSize.Width, ClientSize.Height )/8.0f ); 230 | float pad = 10.0f; 231 | fx.DrawImage( ExampleData.Logo256x256, ClientSize.Width-size-pad, pad, size, size ); 232 | } 233 | 234 | if ( EachFrame==null ) { 235 | PreviousFrame = now; 236 | } else if ( PreviousFrame < now ) { 237 | if ( FrameCache == null || FrameCache.Size != Size ) { 238 | using ( FrameCache ) {} 239 | FrameCache = new Bitmap( Size.Width, Size.Height, PixelFormat.Format24bppRgb ); 240 | } 241 | 242 | using ( var g = Graphics.FromImage(FrameCache) ) g.CopyFromScreen( Location, Point.Empty, Size ); 243 | 244 | while ( PreviousFrame < now ) { 245 | EachFrame(FrameCache); 246 | PreviousFrame = PreviousFrame.AddSeconds(1.0/60); 247 | } 248 | } 249 | 250 | Invalidate(); 251 | base.OnPaint(e); 252 | } 253 | 254 | [STAThread] public static void Main() { 255 | Application.Run( new DebugForm() ); 256 | } 257 | } 258 | } 259 | --------------------------------------------------------------------------------