Exemplo n.º 1
0
        private KDTree getCrossPointsIndex(Polyline polyline)
        {
            List<MonotoneChain> chains = new List<MonotoneChain>();
            foreach (LinePath path in polyline.Paths)
                path.AppendMonotoneChains(chains);

            List<SDMinCrossPoint> crossPoints = new List<SDMinCrossPoint>();

            for (int i = 0; i < chains.Count - 1; i++)
                for (int j = i + 1; j < chains.Count; j++)
                    if (chains[i].BoundsIntersect(chains[j]))
                    {
                        List<ICoordinate> points = chains[i].GetCrossPoints(chains[j]);
                        foreach (ICoordinate p in points)
                        {
                            bool isChainIBoundsPoint = p.ExactEquals(chains[i].FirstPoint) ||
                                 p.ExactEquals(chains[i].LastPoint);

                            bool isChainJBoundsPoint = p.ExactEquals(chains[j].FirstPoint) ||
                                 p.ExactEquals(chains[j].LastPoint);

                            if (!(isChainIBoundsPoint && isChainJBoundsPoint))
                            {
                                SDMinCrossPoint cp = new SDMinCrossPoint();
                                cp.Point = p;
                                cp.BoundingRectangle = new PointD(p).GetBoundingRectangle();
                                cp.BoundingRectangle.Grow(PlanimetryAlgorithms.Tolerance);
                                crossPoints.Add(cp);
                            }
                        }
                    }

            BoundingRectangle br = new BoundingRectangle();
            foreach (SDMinCrossPoint p in crossPoints)
                br.Join(p.BoundingRectangle);

            KDTree result = new KDTree(br);
            result.MaxDepth = 10;
            result.MinObjectCount = 10;
            if (br.IsEmpty())
                br.Join(PlanimetryEnvironment.NewCoordinate(0, 0));
            result.BoxSquareThreshold = br.Width * br.Height / 10000;
            result.Build(crossPoints);
            return result;
        }
Exemplo n.º 2
0
 public object Clone()
 {
     SDMinCrossPoint result = new SDMinCrossPoint();
     result.Point = this.Point;
     result.BoundingRectangle = this.BoundingRectangle;
     return result;
 }