Skip to content

Commit 88b1748

Browse files
committed
05: remove Points[]
more direct to P0,P1 and P2 'Furry Ball' example reduce triangulate time about 100 ms!
1 parent 77d83c4 commit 88b1748

File tree

11 files changed

+884
-573
lines changed

11 files changed

+884
-573
lines changed

Debug/DebugForm.cs

Lines changed: 233 additions & 202 deletions
Large diffs are not rendered by default.

Debug/PolygonInfo.cs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
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.
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.
3030
*/
3131

3232
using System;

ExampleData/ExampleData.cs

Lines changed: 91 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -27,83 +27,94 @@
2727
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2828
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2929
* 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<PolygonPoint>();
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<string,Polygon> DatCache = new Dictionary<string,Polygon>();
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<string,Image> ImageCache = new Dictionary<string,Image>();
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<Polygon> 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-
}
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+
{
40+
public static class ExampleData
41+
{
42+
public static Polygon LoadDat(string filename, bool xflip, bool yflip)
43+
{
44+
var points = new List<PolygonPoint>();
45+
foreach (var line_ in File.ReadAllLines(filename))
46+
{
47+
string line = line_.Trim();
48+
if (string.IsNullOrEmpty(line)) continue;
49+
var xy = line.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
50+
points.Add(new PolygonPoint((xflip ? -1 : +1) * double.Parse(xy[0], CultureInfo.InvariantCulture), (yflip ? -1 : +1) * double.Parse(xy[1], CultureInfo.InvariantCulture)));
51+
}
52+
return new Polygon(points);
53+
}
54+
55+
public static Polygon LoadDat(string filename) { return LoadDat(filename, false, false); }
56+
57+
static readonly Dictionary<string, Polygon> DatCache = new Dictionary<string, Polygon>();
58+
59+
static Polygon CacheLoadDat(string filename, bool xflip, bool yflip)
60+
{
61+
if (!DatCache.ContainsKey(filename)) DatCache.Add(filename, LoadDat(filename, xflip, yflip));
62+
return DatCache[filename];
63+
}
64+
65+
static Polygon CacheLoadDat(string filename) { return CacheLoadDat(filename, false, false); }
66+
67+
static readonly Dictionary<string, Image> ImageCache = new Dictionary<string, Image>();
68+
69+
static Image CacheLoadImage(string filename)
70+
{
71+
if (!ImageCache.ContainsKey(filename)) ImageCache.Add(filename, new Bitmap(filename));
72+
return ImageCache[filename];
73+
}
74+
75+
// These should all use +x = right, +y = up
76+
public static Polygon Two { get { return CacheLoadDat(@"Data\2.dat"); } }
77+
public static Polygon Bird { get { return CacheLoadDat(@"Data\bird.dat", false, true); } }
78+
public static Polygon Custom { get { return CacheLoadDat(@"Data\custom.dat"); } }
79+
public static Polygon Debug { get { return CacheLoadDat(@"Data\debug.dat"); } }
80+
public static Polygon Debug2 { get { return CacheLoadDat(@"Data\debug2.dat"); } }
81+
public static Polygon Diamond { get { return CacheLoadDat(@"Data\diamond.dat"); } }
82+
public static Polygon Dude
83+
{
84+
get
85+
{
86+
if (!ImageCache.ContainsKey(@"Data\dude.dat"))
87+
{
88+
var p = CacheLoadDat(@"Data\dude.dat");
89+
p.AddHole(new Polygon
90+
(new PolygonPoint(325, 437)
91+
, new PolygonPoint(320, 423)
92+
, new PolygonPoint(329, 413)
93+
, new PolygonPoint(332, 423)
94+
));
95+
p.AddHole(new Polygon
96+
(new PolygonPoint(320.72342, 480)
97+
, new PolygonPoint(338.90617, 465.96863)
98+
, new PolygonPoint(347.99754, 480.61584)
99+
, new PolygonPoint(329.8148, 510.41534)
100+
, new PolygonPoint(339.91632, 480.11077)
101+
, new PolygonPoint(334.86556, 478.09046)
102+
));
103+
}
104+
return CacheLoadDat(@"Data\dude.dat");
105+
}
106+
}
107+
public static Polygon Funny { get { return CacheLoadDat(@"Data\funny.dat"); } }
108+
public static Polygon NazcaHeron { get { return CacheLoadDat(@"Data\nazca_heron.dat"); } }
109+
public static Polygon NazcaMonkey { get { return CacheLoadDat(@"Data\nazca_monkey.dat", false, true); } }
110+
public static Polygon Sketchup { get { return CacheLoadDat(@"Data\sketchup.dat"); } }
111+
public static Polygon Star { get { return CacheLoadDat(@"Data\star.dat"); } }
112+
public static Polygon Strange { get { return CacheLoadDat(@"Data\strange.dat"); } }
113+
public static Polygon Tank { get { return CacheLoadDat(@"Data\tank.dat"); } }
114+
public static Polygon Test { get { return CacheLoadDat(@"Data\test.dat"); } }
115+
116+
public static IEnumerable<Polygon> Polygons { get { return new[] { Two, Bird, Custom, Debug, Debug2, Diamond, Dude, Funny, NazcaHeron, NazcaMonkey, Sketchup, Star, Strange, Tank, Test }; } }
117+
118+
public static Image Logo256x256 { get { return CacheLoadImage(@"Textures\poly2tri_logotype_256x256.png"); } }
119+
}
120+
}

0 commit comments

Comments
 (0)