Skip to content

Commit 82dd1c5

Browse files
committed
New demo & triangulation stress testing
- Something seems to be tanking long-term performance. Oddly, this is affecting triangulation, but spiking due to rendering. Could be a memory leak and the GC being orny. TODO: Profile.
1 parent 450d93f commit 82dd1c5

File tree

11 files changed

+316
-8
lines changed

11 files changed

+316
-8
lines changed

Debug/Debug.csproj

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>9.0.30729</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{D4FE7CE8-E032-4D57-993A-048651FA8872}</ProjectGuid>
9+
<OutputType>WinExe</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>Poly2Tri</RootNamespace>
12+
<AssemblyName>Debug</AssemblyName>
13+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="System" />
35+
<Reference Include="System.Core">
36+
<RequiredTargetFramework>3.5</RequiredTargetFramework>
37+
</Reference>
38+
<Reference Include="System.Data" />
39+
<Reference Include="System.Drawing" />
40+
<Reference Include="System.Windows.Forms" />
41+
<Reference Include="System.Xml" />
42+
</ItemGroup>
43+
<ItemGroup>
44+
<Compile Include="DebugForm.cs">
45+
</Compile>
46+
<Compile Include="PolygonInfo.cs" />
47+
<Compile Include="Properties\AssemblyInfo.cs" />
48+
</ItemGroup>
49+
<ItemGroup>
50+
<ProjectReference Include="..\ExampleData\ExampleData.csproj">
51+
<Project>{FC6F045E-7112-44BF-A491-99D987D9C6D2}</Project>
52+
<Name>ExampleData</Name>
53+
</ProjectReference>
54+
<ProjectReference Include="..\Poly2Tri.csproj">
55+
<Project>{C5E5802D-6A45-4FE9-BAE7-5F0AE91D72C1}</Project>
56+
<Name>Poly2Tri</Name>
57+
</ProjectReference>
58+
</ItemGroup>
59+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
60+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
61+
Other similar extension points exist, see Microsoft.Common.targets.
62+
<Target Name="BeforeBuild">
63+
</Target>
64+
<Target Name="AfterBuild">
65+
</Target>
66+
-->
67+
</Project>

Debug/DebugForm.cs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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.Drawing;
34+
using System.Drawing.Drawing2D;
35+
using System.Windows.Forms;
36+
37+
namespace Poly2Tri {
38+
[System.ComponentModel.DesignerCategory("")] class DebugForm : Form {
39+
PolygonInfo Info = new PolygonInfo( "Bird", new Polygon(ExampleData.Bird) );
40+
41+
DateTime PointBounceStart = DateTime.Now;
42+
int PointBounceIndex;
43+
44+
DebugForm() {
45+
ClientSize = new Size(800,600);
46+
BackColor = Color.Black;
47+
ForeColor = Color.White;
48+
DoubleBuffered = true;
49+
StartPosition = FormStartPosition.CenterScreen;
50+
Text = "Poly2Tri Example & Debug setup";
51+
}
52+
53+
int LineY;
54+
void AddText( Graphics fx, string text ) {
55+
TextRenderer.DrawText( fx, text, Font, new Point(10,LineY), ForeColor );
56+
LineY += TextRenderer.MeasureText( text, Font ).Height;
57+
}
58+
59+
protected override void OnPaint( PaintEventArgs e ) {
60+
var fx = e.Graphics;
61+
fx.Clear( BackColor );
62+
63+
if ( Info == null ) {
64+
TextRenderer.DrawText( fx, "No polygon selected.", Font, ClientRectangle, ForeColor, Color.Transparent, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter );
65+
}
66+
else
67+
using ( var pointpen = new Pen( Color.White, 1.0f ) )
68+
{
69+
var now = DateTime.Now;
70+
71+
Info.Triangulate();
72+
73+
fx.SmoothingMode = SmoothingMode.AntiAlias;
74+
fx.TranslateTransform(400,300);
75+
76+
double bounce = (now-PointBounceStart).TotalSeconds*5;
77+
if ( bounce > 1 ) {
78+
bounce = 0;
79+
PointBounceStart = now;
80+
++PointBounceIndex;
81+
}
82+
83+
PointBounceIndex %= Info.Polygon.Points.Count;
84+
85+
for ( int i = 0 ; i < Info.Polygon.Points.Count ; ++i ) {
86+
var point = Info.Polygon.Points[i];
87+
float r = 2.0f;
88+
if ( PointBounceIndex==i ) r += (float)(2-2*bounce);
89+
fx.DrawEllipse( pointpen, 20*point.Xf-r, 20*point.Yf-r, 2*r, 2*r );
90+
}
91+
92+
LineY=10;
93+
AddText(fx,"Name: "+Info.Name);
94+
AddText(fx,"Triangulation time: "+Info.LastTriangulationDuration.TotalMilliseconds.ToString("N0")+"ms");
95+
}
96+
97+
Invalidate();
98+
base.OnPaint(e);
99+
}
100+
101+
[STAThread] public static void Main() {
102+
Application.Run( new DebugForm() );
103+
}
104+
}
105+
}

Debug/PolygonInfo.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
40+
public Polygon Polygon { get; private set; }
41+
42+
public PolygonInfo( string name, Polygon polygon ) {
43+
Name = name;
44+
Polygon = polygon;
45+
Triangulate();
46+
}
47+
48+
static Polygon CleanClone( Polygon polygon ) {
49+
var n = new Polygon(polygon.Points.Cast<PolygonPoint>());
50+
if ( polygon.Holes!=null ) foreach ( var hole in polygon.Holes ) n.AddHole(CleanClone(hole));
51+
return n;
52+
}
53+
54+
public void Triangulate() {
55+
var start = DateTime.Now;
56+
var newpoly = CleanClone(Polygon);
57+
P2T.Triangulate(newpoly);
58+
var stop = DateTime.Now;
59+
LastTriangulationDuration = (stop-start);
60+
Polygon = newpoly;
61+
}
62+
}
63+
}

Debug/Properties/AssemblyInfo.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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")]

ExampleData/ExampleData.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<ProjectGuid>{FC6F045E-7112-44BF-A491-99D987D9C6D2}</ProjectGuid>
99
<OutputType>Library</OutputType>
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
11-
<RootNamespace>ExampleData</RootNamespace>
11+
<RootNamespace>Poly2Tri</RootNamespace>
1212
<AssemblyName>ExampleData</AssemblyName>
1313
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
1414
<FileAlignment>512</FileAlignment>

ExampleData/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
[assembly: AssemblyTitle("ExampleData")]
99
[assembly: AssemblyDescription("")]
1010
[assembly: AssemblyConfiguration("")]
11-
[assembly: AssemblyCompany("Microsoft")]
11+
[assembly: AssemblyCompany("Poly2Tri Contributors")]
1212
[assembly: AssemblyProduct("ExampleData")]
13-
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
13+
[assembly: AssemblyCopyright("Copyright © Poly2Tri Contributors 2009-2010")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

Poly2Tri.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1414
EndProject
1515
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleData", "ExampleData\ExampleData.csproj", "{FC6F045E-7112-44BF-A491-99D987D9C6D2}"
1616
EndProject
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Debug", "Debug\Debug.csproj", "{D4FE7CE8-E032-4D57-993A-048651FA8872}"
18+
EndProject
1719
Global
1820
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1921
Debug|Any CPU = Debug|Any CPU
@@ -32,6 +34,10 @@ Global
3234
{FC6F045E-7112-44BF-A491-99D987D9C6D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
3335
{FC6F045E-7112-44BF-A491-99D987D9C6D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
3436
{FC6F045E-7112-44BF-A491-99D987D9C6D2}.Release|Any CPU.Build.0 = Release|Any CPU
37+
{D4FE7CE8-E032-4D57-993A-048651FA8872}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38+
{D4FE7CE8-E032-4D57-993A-048651FA8872}.Debug|Any CPU.Build.0 = Debug|Any CPU
39+
{D4FE7CE8-E032-4D57-993A-048651FA8872}.Release|Any CPU.ActiveCfg = Release|Any CPU
40+
{D4FE7CE8-E032-4D57-993A-048651FA8872}.Release|Any CPU.Build.0 = Release|Any CPU
3541
EndGlobalSection
3642
GlobalSection(SolutionProperties) = preSolution
3743
HideSolutionNode = FALSE

Polygon/Polygon.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public void RemovePoint( PolygonPoint p ) {
166166

167167
public IList<TriangulationPoint> Points { get { return _points; } }
168168
public IList<DelaunayTriangle> Triangles { get { return _triangles; } }
169+
public IList<Polygon> Holes { get { return _holes; }}
169170

170171
public void AddTriangle( DelaunayTriangle t ) {
171172
_triangles.Add(t);

Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[assembly: AssemblyTitle("Poly2Tri")]
99
[assembly: AssemblyDescription("")]
1010
[assembly: AssemblyConfiguration("")]
11-
[assembly: AssemblyCompany("")]
11+
[assembly: AssemblyCompany("Poly2Tri Contributors")]
1212
[assembly: AssemblyProduct("Poly2Tri")]
1313
[assembly: AssemblyCopyright("Copyright © Poly2Tri Contributors 2009-2010")]
1414
[assembly: AssemblyTrademark("")]

SwfTest/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
[assembly: AssemblyTitle("SwfTest")]
99
[assembly: AssemblyDescription("")]
1010
[assembly: AssemblyConfiguration("")]
11-
[assembly: AssemblyCompany("Microsoft")]
11+
[assembly: AssemblyCompany("Poly2Tri Contributors")]
1212
[assembly: AssemblyProduct("SwfTest")]
13-
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
13+
[assembly: AssemblyCopyright("Copyright © Poly2Tri Contributors 2009-2010")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

0 commit comments

Comments
 (0)