예제 #1
0
        public override LineChainSet2 <double> ConstructLineSet(LineChain2 <double>[] chains)
        {
            if (chains == null || chains.Length < 1)
            {
                return(null);
            }

            LineChain2 <double>[]     Chains = new LineChain2 <double> [chains.Length];
            LineChain2 <double>       ch;
            PlanarChainGraph <double> graph = new PlanarChainGraph <double>();

            for (int i = 0; i < Chains.Length; i++)
            {
                ch = chains[i];
                if (ch == null)
                {
                    return(null); //can't have null chains
                }
                Chains[i] = ch;
                graph.Add(ch);
            }
            if (PlanarGraphUtils.AnyIntersections(graph)) //there must be overlap
            {
                return(null);
            }

            return(new LineChainSet2 <double>(Chains));
        }
예제 #2
0
        public bool HasCoincidentPoints()
        {
            if (this.Chains.Length < 2)
            {
                return(false); //duh, only one chain
            }
            HashSet <Point2 <T> > distinctPoints = new HashSet <Point2 <T> >();
            LineChain2 <T>        curChain       = this.Chains[0];

            foreach (Point2 <T> curPoint in curChain.Points)
            {
                distinctPoints.Add(curPoint);
            }

            for (int i = 1; i < this.Chains.Length; i++)
            {
                curChain = this.Chains[i];
                foreach (Point2 <T> curPoint in curChain.Points)
                {
                    if (distinctPoints.Contains(curPoint))
                    {
                        return(true); //found a dup!
                    }
                    distinctPoints.Add(curPoint);
                }
            }
            return(false);
        }
예제 #3
0
 //Trusted constructor -- uses array directly -- no nulls!
 internal LineChain2(LineChain2 <T> other, bool isReversed)
 {
     if (other == null)
     {
         throw new ArgumentNullException();
     }
     this.Points     = other.Points;
     this.IsReversed = isReversed;
 }
예제 #4
0
 public LineChain2(LineChain2 <T> other)
 {
     if (other == null)
     {
         throw new ArgumentNullException();
     }
     this.Points     = other.Points;
     this.IsReversed = other.IsReversed;
 }
예제 #5
0
 public int CompareTo(LineChain2 <T> other)
 {
     if (other == null)
     {
         return(1);
     }
     if (object.ReferenceEquals(this, other))
     {
         return(0);
     }
     if (object.ReferenceEquals(this.Points, other.Points))
     {
         return(0);
     }
     return(this.Envelope.CompareTo(other.Envelope));
 }
예제 #6
0
 //LINESTRING(0 0,1 1,1 2)
 public static string ToWkt(LineChain2 <double> geom)
 {
     if (geom != null)
     {
         StringBuilder sb = new StringBuilder();
         sb.Append("LINESTRING(");
         for (uint i = 0; i < geom.VertexCount; i++)
         {
             sb.Append(geom[i].X);
             sb.Append(' ');
             sb.Append(geom[i].Y);
             sb.Append(',');
         }
         sb[sb.Length - 1] = ')';
         return(sb.ToString());
     }
     return(string.Empty);
 }
예제 #7
0
        public override Ring2 <double> CloseChain(LineChain2 <double> chain)
        {
            if (chain == null)
            {
                return(null);
            }
            if (chain.Points.Length < 3)
            {
                return(null);
            }
            PlanarChainGraph <double> graph = new PlanarChainGraph <double>();

            graph.Add(chain.Points, true);
            if (PlanarGraphUtils.AnyIntersections(graph))
            {
                return(null);
            }
            Orientation o = Orientation.Clockwise;

            if (chain.IsReversed)
            {
                if (PointUtilsDouble.IsCCW(chain.Points))
                {
                    o = Orientation.Clockwise;
                }
                else
                {
                    o = Orientation.Counterclockwise;
                }
            }
            else
            {
                if (PointUtilsDouble.IsCCW(chain.Points))
                {
                    o = Orientation.Counterclockwise;
                }
                else
                {
                    o = Orientation.Counterclockwise;
                }
            }
            return(new Ring2 <double>(chain.Points, chain.IsReversed, o));
        }
예제 #8
0
 public bool Equals(LineChain2 <T> other)
 {
     if (other == null)
     {
         return(false);
     }
     if (object.ReferenceEquals(this, other))
     {
         return(true); //cheat for memory eqivalence
     }
     if (object.ReferenceEquals(this.Points, other.Points))
     {
         return(true);
     }
     if (this.Points.Length != other.Points.Length)
     {
         return(false);
     }
     if (this.IsReversed == other.IsReversed)
     {
         for (int i = 0; i < this.Points.Length; i++)
         {
             if (!this.Points[i].Equals(other.Points[i]))
             {
                 return(false);
             }
         }
     }
     else
     {
         int le = this.Points.Length - 1;
         for (int i = 0; i < this.Points.Length; i++)
         {
             if (!this.Points[i].Equals(other.Points[le - i]))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
예제 #9
0
 public bool EqualsNonDirectional(LineChain2 <T> other)
 {
     if (other == null)
     {
         return(false);
     }
     if (object.ReferenceEquals(this, other))
     {
         return(true); //cheat for memory eqivalence
     }
     if (this.Points.Length != other.Points.Length)
     {
         return(false);
     }
     if (this.Points[0].Equals(other.Points[0])) //forward compare
     {
         for (int i = 0; i < this.Points.Length; i++)
         {
             if (!this.Points[i].Equals(other.Points[i]))
             {
                 return(false);
             }
         }
         return(true);
     }
     else if (this.Points[this.Points.Length - 1].Equals(other.Points[0])) //reverse compare
     {
         int id = this.Points.Length - 1;
         for (int i = 0; i < this.Points.Length; i++)
         {
             if (!this.Points[id - i].Equals(other.Points[i]))
             {
                 return(false);
             }
         }
         return(true);
     }
     return(false);
 }
예제 #10
0
 public LineChainBag2 <T> ConstructLineBag(IList <Point2 <T> >[] chains)
 {
     if (chains != null)
     {
         List <LineChain2 <T> > constructed = new List <LineChain2 <T> >();
         foreach (Point2 <T>[] ch in chains)
         {
             if (ch == null)
             {
                 return(null);
             }
             LineChain2 <T> chn = ConstructLineChain(ch);
             if (chn == null)
             {
                 return(null);
             }
             constructed.Add(chn);
         }
         return(ConstructLineBag(constructed));
     }
     return(null);
 }
예제 #11
0
        public override LineChainSet2 <double> ConstructLineSet(IList <Point2 <double>[]> chains)
        {
            if (chains == null)
            {
                return(null);
            }
            List <LineChain2 <double> > constructed = new List <LineChain2 <double> >();

            foreach (Point2 <double>[] ch in chains)
            {
                if (ch == null)
                {
                    return(null);
                }
                LineChain2 <double> chn = ConstructLineChain(ch);
                if (chn == null)
                {
                    return(null);
                }
                constructed.Add(chn);
            }
            return(ConstructLineSet(constructed));
        }
예제 #12
0
        public PointSet2 <T> CoincidentPoints()
        {
            //since each line chain by definition has no coincident points, we only need to compare between chains
            if (this.Chains.Length < 2)
            {
                return(null); //duh, only one chain
            }
            HashSet <Point2 <T> > distinctPoints = new HashSet <Point2 <T> >();
            HashSet <Point2 <T> > dupPoints      = new HashSet <Point2 <T> >();
            LineChain2 <T>        curChain       = this.Chains[0];

            foreach (Point2 <T> curPoint in curChain.Points)
            {
                distinctPoints.Add(curPoint);
            }

            for (int i = 1; i < this.Chains.Length; i++)
            {
                curChain = this.Chains[i];
                foreach (Point2 <T> curPoint in curChain.Points)
                {
                    if (distinctPoints.Contains(curPoint))
                    {
                        dupPoints.Add(curPoint); //found a dup!
                    }
                    else
                    {
                        distinctPoints.Add(curPoint);
                    }
                }
            }
            if (dupPoints.Count < 1)
            {
                return(null);
            }
            return(new PointSet2 <T>(dupPoints.ToArray())); //avoid overhead checking for dups in constructor
        }
예제 #13
0
 //potentially unsafe, so must be done by a geometry factory
 public abstract Ring2 <T> CloseChain(LineChain2 <T> chain);