IntersectsWith() public méthode

${WP_core_Rectangle2D_method_intersectsWith_D}
public IntersectsWith ( Rectangle2D rect ) : bool
rect Rectangle2D ${WP_core_Rectangle2D_method_intersectsWith_param_rect}
Résultat bool
 //比较计算后bounds和每个bounds的相交
 private bool computeIntersectWithAll(Rectangle2D bounds)
 {
     var boundsCollection = (Layer as ElementsLayer).BoundsCollection.Values;
     foreach (Rectangle2D rect in boundsCollection)
     {
         if (rect != null)
         {
             if (bounds.IntersectsWith(rect))
             {
                 return true;
             }
         }
     }
     foreach (Rectangle2D rect in orignalBounds)
     {
         if (rect != null)
         {
             if (bounds.IntersectsWith(rect))
             {
                 return true;
             }
         }
     }
     return false;
 }
 private IList<Point2DCollection> ClipPointCollection(Point2DCollection points, Rectangle2D box)
 {
     List<Point2DCollection> list = new List<Point2DCollection>();
     Rectangle2D rect = points.GetBounds();
     if (((rect.Right < box.Left) || (rect.Top < box.Bottom)) || ((rect.Left > box.Right) || (rect.Bottom > box.Top)))
     {
         return null;
     }//全部在外
     if (((rect.Left >= box.Left) && (rect.Bottom >= box.Bottom)) && ((rect.Right <= box.Right) && (rect.Top <= box.Top)))
     {
         list.Add(points);
         return list;
     }//全部在内
     if (points.Count < 2)
     {
         return null;
     }
     Point2DCollection item = null;
     bool flag = IsWithin(points[0], box);
     if (flag)
     {
         item = new Point2DCollection();
         list.Add(item);
         item.Add(points[0]);
     }
     for (int i = 0; i < (points.Count - 1); i++)
     {
         Point2D point = points[i];
         Point2D p = points[i + 1];
         bool flag2 = IsWithin(p, box);
         if (flag && flag2)
         {
             item.Add(p);
         }
         else
         {
             if (flag != flag2)
             {
                 if (flag)
                 {
                     item.Add(this.ClipLineSegment(point, p, box));
                 }
                 else
                 {
                     item = new Point2DCollection();
                     list.Add(item);
                     item.Add(this.ClipLineSegment(p, point, box));
                     item.Add(p);
                 }
             }
             else
             {
                 Rectangle2D box3 = new Rectangle2D(Math.Min(point.X, p.X), Math.Min(point.Y, p.Y), Math.Max(point.X, p.X), Math.Max(point.Y, p.Y));             
                 if (box3.IntersectsWith(box))
                 {
                     item = new Point2DCollection();
                     list.Add(item);
                     Point2D point3 = EdgeIntersection(point, p, box.Left, false);
                     Point2D point4 = EdgeIntersection(point, p, box.Right, false);
                     Point2D point5 = EdgeIntersection(point, p, box.Bottom, true);
                     Point2D point6 = EdgeIntersection(point, p, box.Top, true);
                     if ((point6.X >= box.Left) && (point6.X <= box.Right))
                     {
                         item.Add(point6);
                     }
                     if ((point5.X >= box.Left) && (point5.X <= box.Right))
                     {
                         item.Add(point5);
                     }
                     if ((point4.Y >= box.Bottom) && (point4.Y <= box.Top))
                     {
                         item.Add(point4);
                     }
                     if ((point3.Y >= box.Bottom) && (point3.Y <= box.Top))
                     {
                         item.Add(point3);
                     }
                     if (item.Count < 2)
                     {
                         list.Remove(item);
                     }
                 }
             }
             flag = flag2;
         }
     }
     for (int j = list.Count - 1; j >= 0; j--)
     {
         Point2DCollection points3 = list[j];
         if (points3.Count < 2)
         {
             list.RemoveAt(j);
         }
     }
     if (list.Count == 0)
     {
         return null;
     }
     return list;
 }
Exemple #3
0
        private void beginZoomToTargetBounds(Rectangle2D targetBounds, bool skipAnimation)
        {
            if (this.Layers == null)
            {
                return;
            }
            Rectangle2D startBounds = this.ViewBounds;
            if (Rectangle2D.IsNullOrEmpty(this.previousViewBounds))
            {
                this.previousViewBounds = startBounds;
            }

            double startResolution = this.mapResolution;
            if (((targetBounds.Width != 0.0) || (targetBounds.Height != 0.0)) && (!Rectangle2D.IsNullOrEmpty(targetBounds)))
            {
                //this.targetResolution = this.ClipResolution(Math.Max((double)(targetBounds.Width / viewSize.Width), (double)(targetBounds.Height / viewSize.Height)));
                this.targetResolution = Math.Max((double)(targetBounds.Width / currentSize.Width), (double)(targetBounds.Height / currentSize.Height));
                this.targetResolution = MathUtil.MinMaxCheck(targetResolution, MinResolution, MaxResolution);
                Point2D startOrigin = new Point2D(startBounds.Left, startBounds.Top);
                Point2D center = targetBounds.Center;
                if ((base.ActualHeight == 0.0) || (base.ActualWidth == 0.0))
                {
                    skipAnimation = true;
                }

                Point2D targetOrigin = new Point2D(targetBounds.Left, targetBounds.Top);

                this.Popup.IsOpen = false;

                if (this.CurrentZoomAnimationHandler != null)
                {
                    CompositionTarget.Rendering -= this.CurrentZoomAnimationHandler;
                    this.CurrentZoomAnimationHandler = null;
                }

                skipAnimation = skipAnimation || (this.ZoomDuration.Ticks == 0L);
                if (skipAnimation)
                {
                    this.panHelper.ResetTranslate();
                    this.SetOriginAndResolution(this.targetResolution, targetOrigin, true);
                }
                else
                {
                    TimeSpan? startTime = null;
                    bool resetPan = false;
                    this.CurrentZoomAnimationHandler = delegate(object s, EventArgs e)
                    {
                        RenderingEventArgs args = (RenderingEventArgs)e;
                        if (!startTime.HasValue)
                        {
                            startTime = new TimeSpan?(args.RenderingTime);
                        }
                        else
                        {
                            double t = args.RenderingTime.TotalMilliseconds - startTime.Value.TotalMilliseconds;
                            double totalMilliseconds = this.ZoomDuration.TotalMilliseconds;
                            double num3 = QuinticEaseOut(t, 0.0, 1.0, totalMilliseconds);//动画
                            this.mapResolution = ((this.targetResolution - startResolution) * num3) + startResolution;
                            Point2D currentOrigin = new Point2D(((targetOrigin.X - startOrigin.X) * num3) + startOrigin.X, ((targetOrigin.Y - startOrigin.Y) * num3) + startOrigin.Y);
                            if (t >= totalMilliseconds)
                            {
                                CompositionTarget.Rendering -= this.CurrentZoomAnimationHandler;
                                this.CurrentZoomAnimationHandler = null;
                                currentOrigin = targetOrigin;
                                this.mapResolution = this.targetResolution;

                                this.Dispatcher.BeginInvoke(delegate
                                {
                                    this.SetOriginAndResolution(this.mapResolution, currentOrigin, true);
                                    Rectangle2D rect = this.GetFullViewBounds();
                                    if (Rectangle2D.IsNullOrEmpty(rect))
                                    {
                                        this.LoadLayersInView(false, targetBounds);
                                    }
                                    else
                                    {
                                        this.LoadLayersInView(targetBounds.IntersectsWith(rect), rect);
                                    }
                                    this.RaiseViewBoundsChanged();
                                });
                            }
                            else
                            {
                                if (!resetPan)
                                {
                                    this.panHelper.ResetTranslate();
                                    resetPan = true;
                                }
                                this.SetOriginAndResolution(this.mapResolution, currentOrigin, false);
                                if (this.ViewBoundsChanging != null)
                                {
                                    this.ViewBoundsChanging(this, new ViewBoundsEventArgs(startBounds, this.ViewBounds));
                                }
                            }
                        }
                    };

                    CompositionTarget.Rendering += this.CurrentZoomAnimationHandler;
                }
                foreach (Layer layer in this.Layers)
                {
                    if ((layer.Container != null) && !(layer is TiledLayer))
                    {
                        layer.Container.MarkOutdated(!skipAnimation);
                    }
                }

                if (this.mapResizeThrottler != null)
                {
                    this.mapResizeThrottler.Cancel();
                }
                if (skipAnimation)
                {
                    this.LoadLayersInView(false, targetBounds);
                    this.RaiseViewBoundsChanged();
                }
            }
        }
        private IList<Point2DCollection> ClipPointCollection(Point2DCollection points, Rectangle2D box)
        {
            List<Point2DCollection> list = new List<Point2DCollection>();
            Rectangle2D rect = points.GetBounds();
            if (((rect.Right < box.Left) || (rect.Top < box.Bottom)) || ((rect.Left > box.Right) || (rect.Bottom > box.Top)))
            {
                return null;
            }//全部在外,不相交
            if (box.Contains(rect))
            {
                list.Add(points);
                return list;
            }//全部在内
            if (points.Count < 2)
            {
                return null;
            }
            Point2DCollection item = null;
            bool flag = box.Contains(points[0]);
            if (flag)
            {
                item = new Point2DCollection();
                list.Add(item);
                item.Add(points[0]);
            }//第一个点在内
            for (int i = 0; i < (points.Count - 1); i++)
            {
                Point2D head = points[i];
                Point2D end = points[i + 1];
                bool flag2 = box.Contains(end);
                if (flag && flag2)
                {
                    item.Add(end);
                }//同时在内。那么else则有三种情况,head内end外,head外edn内,hean外end外
                else
                {
                    if (flag != flag2)
                    {
                        if (flag)
                        {
                            item.Add(this.ClipLineSegment(head, end, box));
                        }//head内end外,添加交点
                        else
                        {
                            item = new Point2DCollection();
                            list.Add(item);
                            item.Add(this.ClipLineSegment(head, end, box));
                            item.Add(end);
                        }//head外edn内,添加交点和end点
                    }
                    else
                    {
                        Rectangle2D segmentBox = new Rectangle2D(Math.Min(head.X, end.X), Math.Min(head.Y, end.Y), Math.Max(head.X, end.X), Math.Max(head.Y, end.Y));
                        if (segmentBox.IntersectsWith(box))
                        {
                            item = new Point2DCollection();
                            list.Add(item);
                            //与四条边框求交点,在中间就添加上去
                            Point2D point3 = EdgeIntersection(head, end, box.Left, false);
                            Point2D point4 = EdgeIntersection(head, end, box.Right, false);
                            Point2D point5 = EdgeIntersection(head, end, box.Bottom, true);
                            Point2D point6 = EdgeIntersection(head, end, box.Top, true);
                            if ((point6.X >= box.Left) && (point6.X <= box.Right))
                            {
                                item.Add(point6);
                            }
                            if ((point5.X >= box.Left) && (point5.X <= box.Right))
                            {
                                item.Add(point5);
                            }
                            if ((point4.Y >= box.Bottom) && (point4.Y <= box.Top))
                            {
                                item.Add(point4);
                            }
                            if ((point3.Y >= box.Bottom) && (point3.Y <= box.Top))
                            {
                                item.Add(point3);
                            }
                            if (item.Count < 2)
                            {
                                list.Remove(item);
                            }

                        }//hean外end外,添加两个交点
                    }
                    flag = flag2;
                }
            }
            for (int j = list.Count - 1; j >= 0; j--)
            {
                Point2DCollection pts = list[j];
                if (pts.Count < 2)
                {
                    list.RemoveAt(j);
                }
            }
            if (list.Count == 0)
            {
                return null;
            }
            return list;
        }
Exemple #5
0
        private void zoomTo(Rectangle2D bounds, bool skipAnimation)
        {
            if ((!Rectangle2D.IsNullOrEmpty(bounds)) && (bounds.Width != 0.0 || bounds.Height != 0.0))
            {
                Rectangle2D other = this.ViewBounds;
                if (Rectangle2D.IsNullOrEmpty(other))
                {
                    this.mapResolution = this.targetResolution = MathUtil.MinMaxCheck(Math.Max(bounds.Width / currentSize.Width, bounds.Height / currentSize.Height), MinResolution, MaxResolution);
                    Point2D center = bounds.Center;
                    this.origin = new Point2D(center.X - ((currentSize.Width * 0.5) * this.mapResolution), center.Y + ((currentSize.Height * 0.5) * this.mapResolution));
                    this.LoadLayersInView(false, this.GetFullViewBounds());
                }
                else if (double.IsNaN(this.mapResolution))
                {
                    this.cacheViewBounds = bounds;
                }//终于判断了
                else
                {
                    if (!bounds.IntersectsWith(other))
                    {
                        skipAnimation = true;
                    }//有相交的跳过动画

                    Point2D point2 = bounds.Center;
                    double nearestLevelResolution = MathUtil.GetNearest(MathUtil.MinMaxCheck(Math.Max(bounds.Width / currentSize.Width, bounds.Height / currentSize.Height), MinResolution, MaxResolution), this.Resolutions, MinResolution, MaxResolution);
                    bounds = new Rectangle2D(point2.X - ((currentSize.Width * nearestLevelResolution) * 0.5),
                        point2.Y - ((currentSize.Height * nearestLevelResolution) * 0.5),
                        point2.X + ((currentSize.Width * nearestLevelResolution) * 0.5),
                        point2.Y + ((currentSize.Height * nearestLevelResolution) * 0.5));


                    bounds = getAdjustedViewBounds(bounds, currentSize);

                    bool pan = DoubleUtil.AreClose(1.0, bounds.Width / other.Width);
                    if (!pan && (bounds.Width != 0.0 || bounds.Height != 0.0))
                    {
                        beginZoomToTargetBounds(bounds, skipAnimation);
                    }
                    else
                    {
                        //PanTo(bounds.Center, skipAnimation);//pan到这个点的bounds其实
                        panTo(bounds, skipAnimation);//10/3/12
                    }
                }
            }
        }