예제 #1
0
 static void MoveSites(CdtSite a, CdtSite b, CdtSite c, CdtSite s) {
     var del=new Point(20,-30);
     a.Point = a.Point + del;
     b.Point = b.Point + del;
     c.Point = c.Point + del;
     s.Point = s.Point + del;
 }
예제 #2
0
 static void RotateSites(CdtSite a, CdtSite b, CdtSite c, CdtSite s) {
     const double angle = Math.PI / 3;
     a.Point = a.Point.Rotate(angle);
     b.Point = b.Point.Rotate(angle);
     c.Point = c.Point.Rotate(angle);
     s.Point = s.Point.Rotate(angle);
 }
 internal CdtEdge EdgeBetweenUpperSiteAndLowerSite(CdtSite b)
 {
     Debug.Assert(Cdt.Above(this, b) > 0);
     if (Edges != null)
         foreach (var edge in Edges)
             if (edge.lowerSite == b)
                 return edge;
     return null;
 }
 static Dictionary<IntPair, CdtEdge> GetEdges(CdtSite[] siteArray, Dictionary<CdtSite, int> siteIndex) {
     var d = new Dictionary<IntPair, CdtEdge>();
     for (int i = 0; i < siteArray.Length; i++) {
         var site = siteArray[i];
         var sourceIndex = siteIndex[site];
         foreach (var e in site.Edges)
             d[new IntPair(sourceIndex, siteIndex[e.lowerSite])] = e;
     }
     return d;
 }
        ///<summary>
        ///</summary>
        ///<param name="a"></param>
        ///<param name="b"></param>
        public CdtEdge(CdtSite a, CdtSite b) {
            var above = Cdt.Above(a.Point, b.Point);
            if (above == 1) {
                upperSite = a;
                lowerSite = b;
            }
            else {
                Debug.Assert(above != 0);
                lowerSite = a;
                upperSite = b;
            }

            upperSite.AddEdgeToSite(this);
        }
예제 #6
0
 public void InCircleTest() {
     var a = new CdtSite(new Point());
     var b = new CdtSite(new Point(2, 0));
     var c = new CdtSite(new Point(1, 2));
     var s = new CdtSite(new Point(1, 1));
     Assert.IsTrue(CdtSweeper.InCircle(s, a, b, c));
     MoveSites(a, b, c, s);
     Assert.IsTrue(CdtSweeper.InCircle(s, a, b, c));
     RotateSites(a, b, c, s);
     Assert.IsTrue(CdtSweeper.InCircle(s, a, b, c));
     a = new CdtSite(new Point());
     b = new CdtSite(new Point(2, 0));
     c = new CdtSite(new Point(1, 2));
     s = new CdtSite(new Point(1, -1));
     Assert.IsTrue(!CdtSweeper.InCircle(s, a, b, c));
     MoveSites(a, b, c, s);
     Assert.IsTrue(!CdtSweeper.InCircle(s, a, b, c));
     RotateSites(a, b, c, s);
     Assert.IsTrue(!CdtSweeper.InCircle(s, a, b, c));
     a = new CdtSite(new Point());
     b = new CdtSite(new Point(1, 0));
     c = new CdtSite(new Point(5, 5));
     s = new CdtSite(new Point(3, 1));
     Assert.IsTrue(CdtSweeper.InCircle(s, a, b, c));
     MoveSites(a, b, c, s);
     Assert.IsTrue(CdtSweeper.InCircle(s, a, b, c));
     RotateSites(a, b, c, s);
     Assert.IsTrue(CdtSweeper.InCircle(s, a, b, c));
     Assert.IsTrue(CdtSweeper.InCircle(s, c, a, b));
     a = new CdtSite(new Point());
     b = new CdtSite(new Point(1, 0));
     c = new CdtSite(new Point(5, 5));
     s = new CdtSite(new Point(4, 1));
     Assert.IsTrue(!CdtSweeper.InCircle(s, a, b, c));
     MoveSites(a, b, c, s);
     Assert.IsTrue(!CdtSweeper.InCircle(s, a, b, c));
     RotateSites(a, b, c, s);
     Assert.IsTrue(!CdtSweeper.InCircle(s, a, b, c));
     a = new CdtSite(new Point());
     b = new CdtSite(new Point(1, 0));
     c = new CdtSite(new Point(5, 5));
     s = new CdtSite(new Point(3, 0.5));
     Assert.IsTrue(!CdtSweeper.InCircle(s, a, b, c));
     MoveSites(a, b, c, s);
     Assert.IsTrue(!CdtSweeper.InCircle(s, a, b, c));
     RotateSites(a, b, c, s);
     Assert.IsTrue(!CdtSweeper.InCircle(s, a, b, c));
     Assert.IsTrue(!CdtSweeper.InCircle(s, c, a, b)); 
 }
예제 #7
0
 internal CdtEdge EdgeBetweenUpperSiteAndLowerSite(CdtSite b)
 {
     Debug.Assert(Cdt.Above(this, b) > 0);
     if (Edges != null)
     {
         foreach (var edge in Edges)
         {
             if (edge.lowerSite == b)
             {
                 return(edge);
             }
         }
     }
     return(null);
 }
예제 #8
0
파일: CdtEdge.cs 프로젝트: sta1216/MsAGL
        ///<summary>
        ///</summary>
        ///<param name="a"></param>
        ///<param name="b"></param>
        public CdtEdge(CdtSite a, CdtSite b)
        {
            var above = Cdt.Above(a.Point, b.Point);

            if (above == 1)
            {
                upperSite = a;
                lowerSite = b;
            }
            else
            {
                Debug.Assert(above != 0);
                lowerSite = a;
                upperSite = b;
            }

            upperSite.AddEdgeToSite(this);
        }
 ///<summary>
 ///</summary>
 ///<param name="site"></param>
 ///<returns></returns>
 public CdtSite OtherSite(CdtSite site) {
     Debug.Assert(IsAdjacent(site));
     return upperSite == site ? lowerSite : upperSite;
 }
예제 #10
0
파일: CdtEdge.cs 프로젝트: sta1216/MsAGL
 /// <summary>
 /// returns the trianlge on the edge opposite to the site
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public CdtTriangle GetOtherTriangle(CdtSite p)
 {
     return(cwTriangle.Contains(p) ? ccwTriangle : cwTriangle);
 }
예제 #11
0
파일: CdtEdge.cs 프로젝트: sta1216/MsAGL
 ///<summary>
 ///</summary>
 ///<param name="pi"></param>
 ///<returns></returns>
 public bool IsAdjacent(CdtSite pi)
 {
     return(pi == upperSite || pi == lowerSite);
 }
예제 #12
0
파일: CdtEdge.cs 프로젝트: sta1216/MsAGL
 ///<summary>
 ///</summary>
 ///<param name="site"></param>
 ///<returns></returns>
 public CdtSite OtherSite(CdtSite site)
 {
     Debug.Assert(IsAdjacent(site));
     return(upperSite == site ? lowerSite : upperSite);
 }
 ///<summary>
 ///</summary>
 ///<param name="pi"></param>
 ///<returns></returns>
 public bool IsAdjacent(CdtSite pi) {
     return pi == upperSite || pi == lowerSite;
 }
 /// <summary>
 /// returns the trianlge on the edge opposite to the site 
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public CdtTriangle GetOtherTriangle(CdtSite p) {
     return cwTriangle.Contains(p) ? ccwTriangle : cwTriangle;
 }
예제 #15
0
 static bool SeparatedByEdge(CdtTriangle triangle, int i, CdtSite site) {
     var e = triangle.Edges[i];
     var s = triangle.Sites[i + 2];
     var a0 = ApproximateComparer.Sign(Point.SignedDoubledTriangleArea(s.Point, e.upperSite.Point, e.lowerSite.Point));
     var a1 = ApproximateComparer.Sign(Point.SignedDoubledTriangleArea(site.Point, e.upperSite.Point, e.lowerSite.Point));
     return a0 * a1 <= 0;
 }
예제 #16
0
 static bool SeparatedByConstrainedEdge(CdtTriangle triangle, CdtSite site) {
     for (int i = 0; i < 3; i++)
         if (SeparatedByEdge(triangle, i, site))
             return true;
     return false;
 }
예제 #17
0
        public void CdtTriangleCreationTest() {
            var a = new CdtSite(new Point());
            var b = new CdtSite(new Point(2, 0));
            var c = new CdtSite(new Point(1, 2));
            var tri = new CdtTriangle(a, b, c, Cdt.GetOrCreateEdge);
            var e = tri.Edges[0];
            Assert.IsTrue(e.upperSite == a);
            Assert.IsTrue(e.lowerSite == b);
            Assert.IsTrue(e.CcwTriangle == tri && e.CwTriangle == null);

            e = tri.Edges[1];
            Assert.IsTrue(e.upperSite == c);
            Assert.IsTrue(e.lowerSite == b);
            Assert.IsTrue(e.CwTriangle == tri && e.CcwTriangle == null);
            
            e = tri.Edges[2];
            Assert.IsTrue(e.upperSite == c);
            Assert.IsTrue(e.lowerSite == a);
            Assert.IsTrue(e.CcwTriangle == tri && e.CwTriangle == null);

            var tri0=new CdtTriangle(new CdtSite(new Point(2,2)), tri.Edges[1], Cdt.GetOrCreateEdge );
            Assert.IsTrue(tri0.Edges[0]==tri.Edges[1]);
            Assert.IsTrue(tri.Edges[1].CcwTriangle != null && tri.Edges[1].CwTriangle != null );
        }