PolygonTests.cs
上传用户:sex100000
上传日期:2013-11-09
资源大小:1377k
文件大小:2k
源码类别:

GIS编程

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using NUnit.Framework;
  4. using SharpMap.Geometries;
  5. namespace UnitTests.Geometries
  6. {
  7. [TestFixture]
  8. public class PolygonTests
  9. {
  10. [Test]
  11. public void PolygonTest()
  12. {
  13. Polygon p = new Polygon();
  14. Assert.IsTrue(p.IsEmpty());
  15. Assert.AreEqual(0, p.NumInteriorRing);
  16. Assert.AreEqual(p.NumInteriorRing, p.InteriorRings.Count);
  17. Assert.IsFalse(p.Equals(null));
  18. Assert.IsTrue(p.Equals(new Polygon()));
  19. Assert.IsNull(p.GetBoundingBox());
  20. LinearRing ring = new LinearRing();
  21. ring.Vertices.Add(new Point(10, 10));
  22. ring.Vertices.Add(new Point(20, 10));
  23. ring.Vertices.Add(new Point(20, 20));
  24.             Assert.IsFalse(ring.IsCCW());
  25. ring.Vertices.Add(new Point(10, 20));
  26.             ring.Vertices.Add(ring.Vertices[0].Clone());
  27.             Assert.IsTrue(ring.IsPointWithin(new Point(15, 15)));
  28.             Assert.AreNotSame(ring.Clone(), ring);
  29. p.ExteriorRing = ring;
  30.             
  31.             
  32. Assert.AreEqual(100, p.Area);
  33. LinearRing ring2 = new LinearRing();
  34. ring2.Vertices.Add(new Point(11, 11));
  35. ring2.Vertices.Add(new Point(19, 11));
  36. ring2.Vertices.Add(new Point(19, 19));
  37. ring2.Vertices.Add(new Point(11, 19));
  38. ring2.Vertices.Add(ring2.Vertices[0].Clone());
  39. p.InteriorRings.Add(ring2);
  40. Assert.AreEqual(100 + 64, p.Area);
  41.             // Reverse() doesn't exist for Collections
  42. //ring2.Vertices.Reverse();
  43. //Assert.AreEqual(100 - 64, p.Area);
  44. Assert.AreEqual(1, p.NumInteriorRing);
  45. Assert.AreEqual(new BoundingBox(10, 10, 20, 20), p.GetBoundingBox());
  46. Polygon p2 = p.Clone();
  47. Assert.AreEqual(p, p2);
  48. Assert.AreNotSame(p, p2);
  49. p2.InteriorRings.RemoveAt(0);
  50. Assert.AreNotEqual(p, p2);
  51. }
  52. }
  53. }