|
27 | 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
28 | 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
29 | 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<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