当前位置: 首页>>代码示例>>C#>>正文


C# Rect.Union方法代码示例

本文整理汇总了C#中System.Windows.Rect.Union方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.Union方法的具体用法?C# Rect.Union怎么用?C# Rect.Union使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Rect的用法示例。


在下文中一共展示了Rect.Union方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AdjustPosition

 /// <summary>
 /// Sets the item's position according to its tikzitem's value
 /// </summary>
 public override bool AdjustPosition(double Resolution)
 {
     Rect r = new Rect(0, 0, 0, 0);
     bool hasone = false;
     foreach (OverlayShape o in children)
     {
         o.AdjustPosition(Resolution);
         Rect rr = o.View.GetBB();
         if (hasone)
             r.Union(rr);
         else
         {
             r = rr;
             hasone = true;
         }
     }
     if (hasone)
     {
         r.Inflate(20, 20);
         //r = new Rect(10, 10, 100, 100);
         View.SetSize( r.Width, r.Height);
         View.SetPosition(r.X, r.Y);
         return true;
     }
     else return false;
 }
开发者ID:JoeyEremondi,项目名称:tikzedt,代码行数:29,代码来源:OverlayShape.cs

示例2: GetBoundsFromChildren

 protected Rect GetBoundsFromChildren()
 {
     Rect bounds = new Rect(new Size(10, 10)); // default if there are no children.
     Plot2DItem child;
     for (int i = 0; i < plotItems.Count; ++i)
     {
         child = plotItems[i];
         if (i == 0) bounds = child.PaddedBounds;
         else bounds.Union(child.PaddedBounds);
     }
     return bounds;
 }
开发者ID:goutkannan,项目名称:ironlab,代码行数:12,代码来源:PlotPanelChilden.cs

示例3: TransformBounds

		public override Rect TransformBounds (Rect rect)
		{
			Point p1 = new Point (rect.Left, rect.Top);
			Point p2 = new Point (rect.Right, rect.Top);
			Point p3 = new Point (rect.Left, rect.Bottom);
			Point p4 = new Point (rect.Right, rect.Bottom);
			
			Rect r1 = new Rect (Transform (p1), Transform (p2));
			Rect r2 = new Rect (Transform (p3), Transform (p4));

			r1.Union (r2);

			return r1;
		}
开发者ID:dfr0,项目名称:moon,代码行数:14,代码来源:InternalTransform.cs

示例4: MeasureOverride

        protected override Size MeasureOverride(Size availableSize)
        {
            var bounds = new Rect();
            var midPoint = new Point(0, 0);
            var arc = new Arc(midPoint, this.MinAngle, this.MaxAngle, this.ReservedSpace, this.IsDirectionReversed);
            for (int i = 0; i < this.AllTicks.Count; i++)
            {
                var tick = this.AllTicks[i];
                var text = this.AllTexts[i];
                var angle = TickHelper.ToAngle(tick, this.Minimum, this.Maximum, arc);
                var point = arc.GetPoint(angle);
                var textPosition = new TextPosition(text, new TextPositionOptions(this.TextOrientation, angle), point, angle);
                bounds.Union(textPosition.TransformedBounds);
            }
            var points = new[] { bounds.TopLeft, bounds.TopRight, bounds.BottomRight, bounds.BottomLeft };

            this.TextSpace = 2 * points.Max(p => (p - midPoint).Length);
            return bounds.Size;
        }
开发者ID:JackWangCUMT,项目名称:Gu.Gauges,代码行数:19,代码来源:AngularTextBar.cs

示例5: setupSelectionAdorner

 private void setupSelectionAdorner()
 {
     var selectedBound = new Rect();
     bool firstShape = true;
     foreach (Stroke stroke in referencedStrokes)
     {
         addStylingToStroke(stroke);
         var bounds = stroke.GetBounds();
         if (firstShape)
         {
             selectedBound.X = bounds.Left - 5;
             selectedBound.Y = bounds.Top - 5;
             firstShape = false;
         }
         var points = new Point[] { new Point(bounds.Left, bounds.Top), new Point(bounds.Right, bounds.Bottom) };
         foreach (Point point in points)
             selectedBound.Union(point);
     }
     this.Width = selectedBound.Width + 10;
     this.Height = selectedBound.Height + 10;
     Canvas.SetLeft(this, selectedBound.X);
     Canvas.SetTop(this, selectedBound.Y);
 }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:23,代码来源:SelectionAdorner.xaml.cs

示例6: AddToRegion

        private Rect AddToRegion(KeyValuePair<DrawingVisual, uint> entry, Rect region)
        {
            Rect compRect = entry.Key.ContentBounds;

            if (compRect == Rect.Empty)
                return region;

            TranslateTransform transform = entry.Key.Transform as TranslateTransform;
            if (transform != null)
            {
                double x = transform.X;
                double y = transform.Y;
                compRect.Offset(new Vector(x, y));
            }

            if (region.Width == 0)
                return compRect;
            else
            {
                region.Union(compRect);
                return region;
            }
        }
开发者ID:samuto,项目名称:designscript,代码行数:23,代码来源:GraphVisualHost.cs

示例7: Union

		public void Union()
		{
			Rect r;
			
			// fully contained
			r = new Rect(0, 0, 50, 50);
			r.Union(new Rect(10, 10, 10, 10));
			Assert.AreEqual(new Rect(0, 0, 50, 50), r);

			// crosses top side
			r = new Rect(0, 0, 50, 50);
			r.Union(new Rect(5, -5, 10, 10));
			Assert.AreEqual(new Rect(0, -5, 50, 55), r);

			// crosses right side
			r = new Rect(0, 0, 50, 50);
			r.Union(new Rect(5, 5, 50, 10));
			Assert.AreEqual(new Rect(0, 0, 55, 50), r);

			// crosses bottom side
			r = new Rect(0, 0, 50, 50);
			r.Union(new Rect(5, 5, 10, 50));
			Assert.AreEqual(new Rect(0, 0, 50, 55), r);

			// crosses left side
			r = new Rect(0, 0, 50, 50);
			r.Union(new Rect(-5, 5, 10, 10));
			Assert.AreEqual(new Rect(-5, 0, 55, 50), r);

			// completely outside (top)
			r = new Rect(0, 0, 50, 50);
			r.Union(new Rect(5, -5, 1, 1));
			Assert.AreEqual(new Rect(0, -5, 50, 55), r);

			// completely outside (right)
			r = new Rect(0, 0, 50, 50);
			r.Union(new Rect(75, 5, 1, 1));
			Assert.AreEqual(new Rect(0, 0, 76, 50), r);

			// completely outside (bottom)
			r = new Rect(0, 0, 50, 50);
			r.Union(new Rect(5, 75, 1, 1));
			Assert.AreEqual(new Rect(0,0, 50, 76), r);

			// completely outside (left)
			r = new Rect(0, 0, 50, 50);
			r.Union(new Rect(-25, 5, 1, 1));
			Assert.AreEqual(new Rect(-25, 0, 75, 50), r);
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:49,代码来源:RectTest.cs

示例8: ArrangeOverride

        /// <summary>
        /// Arranges the content of a <see cref="StiZoomableCanvas"/> element.
        /// </summary>
        /// <param name="finalSize">The size that this <see cref="StiZoomableCanvas"/> element should use to arrange its child elements.</param>
        /// <returns>A <see cref="Size"/> that represents the arranged size of this <see cref="StiZoomableCanvas"/> element and its descendants.</returns>
        protected override Size ArrangeOverride(Size finalSize)
        {
            bool applyTransform = ApplyTransform;
            Point offset = applyTransform ? new Point() : Offset;
            double scale = applyTransform ? 1.0 : Scale;

            ChildrenExtent = Rect.Empty;

            foreach (UIElement child in InternalChildren)
            {
                if (child != null)
                {
                    // Get bounds information from the element.
                    Rect bounds = new Rect(Canvas.GetLeft(child).GetValueOrDefault(), Canvas.GetTop(child).GetValueOrDefault(), child.DesiredSize.Width / scale, child.DesiredSize.Height / scale);

                    // If we are maintaining our own spatial wrapper then update its bounds.
                    if (PrivateIndex != null)
                    {
                        int index = IndexFromContainer(child); //TODO
                        Rect oldBounds = PrivateIndex[index];
                        const double tolerance = .0001; // The exact values during arrange can vary slightly.
                        if (Math.Abs(oldBounds.Top - bounds.Top) > tolerance ||
                            Math.Abs(oldBounds.Left - bounds.Left) > tolerance ||
                            Math.Abs(oldBounds.Width - bounds.Width) > tolerance ||
                            Math.Abs(oldBounds.Height - bounds.Height) > tolerance)
                        {
                            PrivateIndex[index] = bounds;
                        }
                    }

                    // Update the children extent for scrolling.
                    ChildrenExtent.Union(bounds);

                    // So far everything has been in canvas coordinates.  Here we adjust the result for the final call to Arrange.
                    bounds.X *= scale;
                    bounds.X -= offset.X;
                    bounds.Y *= scale;
                    bounds.Y -= offset.Y;
                    bounds.Width  = Math.Ceiling(bounds.Width*scale);
                    bounds.Height = Math.Ceiling(bounds.Height*scale);

                    // WPF Arrange will crash if the values are too large.
                    bounds.X = bounds.X.AtLeast(Single.MinValue / 2);
                    bounds.Y = bounds.Y.AtLeast(Single.MinValue / 2);
                    bounds.Width = bounds.Width.AtMost(Single.MaxValue);
                    bounds.Height = bounds.Height.AtMost(Single.MaxValue);

                    child.Arrange(bounds);
                }
            }

            InvalidateExtent();

            return finalSize;
        }
开发者ID:inqwi84,项目名称:StiZoomableCanvas,代码行数:60,代码来源:StiZoomableCanvas.cs

示例9: MeasureOverride

 protected override Size MeasureOverride(Size availableSize)
 {
     var rect = new Rect();
     var arc = new Arc(new Point(0, 0), this.MinAngle, this.MaxAngle, this.ReservedSpace / 2 + this.TickLength, this.IsDirectionReversed);
     rect.Union(arc.GetPoint(arc.Start));
     var a = TickHelper.ToAngle(this.Value, this.Minimum, this.Maximum, arc);
     rect.Union(arc.GetPoint(a));
     foreach (var p in arc.GetQuadrants(arc.Start, a))
     {
         rect.Union(p);
     }
     return rect.Size;
 }
开发者ID:JackWangCUMT,项目名称:Gu.Gauges,代码行数:13,代码来源:AngularBlockBar.cs

示例10: MeasureOverride


//.........这里部分代码省略.........
        if( dateEnd > DateTime.MinValue && dateEnd > date )
        {
          if( Orientation == Orientation.Horizontal )
          {
            if( UnitTimeSpan != TimeSpan.Zero && UnitSize > 0 )
            {
              double size = ( double )( dateEnd.Ticks - date.Ticks ) / ( double )UnitTimeSpan.Ticks;

              childSize.Width = size * UnitSize;
            }
            else if( !double.IsPositiveInfinity( availableSize.Width ) )
            {
              // width is DateEnd - Date
              childSize.Width = CalculateTimelineOffset( dateEnd, availableSize.Width ) - CalculateTimelineOffset( date, availableSize.Width );
            }
          }
          else
          {
            if( UnitTimeSpan != TimeSpan.Zero && UnitSize > 0 )
            {
              double size = ( double )( dateEnd.Ticks - date.Ticks ) / ( double )UnitTimeSpan.Ticks;

              childSize.Height = size * UnitSize;
            }
            else if( !double.IsPositiveInfinity( availableSize.Height ) )
            {
              // height is DateEnd - Date
              childSize.Height = CalculateTimelineOffset( dateEnd, availableSize.Height ) - CalculateTimelineOffset( date, availableSize.Height );
            }
          }
        }

        child.Measure( childSize );
      }

      Size newAvailableSize = new Size( availableSize.Width, availableSize.Height );

      if( UnitTimeSpan != TimeSpan.Zero && UnitSize > 0 )
      {
        double size = ( double )( EndDate.Ticks - BeginDate.Ticks ) / ( double )UnitTimeSpan.Ticks;

        if( Orientation == Orientation.Horizontal )
        {
          newAvailableSize.Width = size * UnitSize;
        }
        else
        {
          newAvailableSize.Height = size * UnitSize;
        }
      }

      Size desiredSize = new Size();

      if( ( Orientation == Orientation.Vertical && double.IsPositiveInfinity( newAvailableSize.Height ) ) ||
          ( Orientation == Orientation.Horizontal && double.IsPositiveInfinity( newAvailableSize.Width ) ) )
      {
        // Our panel cannot layout items when we have positive infinity in the layout direction
        // so defer to arrange pass.
        _visibleElements = null;
      }
      else
      {
        LayoutItems( InternalChildren, newAvailableSize );

        Rect desiredRect = new Rect();

        foreach( DateElement child in _visibleElements )
        {
          desiredRect.Union( child.PlacementRectangle );
        }

        if( Orientation == Orientation.Horizontal )
        {
          desiredSize.Width = newAvailableSize.Width;
          desiredSize.Height = desiredRect.Size.Height;
        }
        else
        {
          desiredSize.Width = desiredRect.Size.Width;
          desiredSize.Height = newAvailableSize.Height;
        }
      }

      if( IsScrolling )
      {
        Size viewport = new Size( availableSize.Width, availableSize.Height );
        Size extent = new Size( desiredSize.Width, desiredSize.Height );
        Vector offset = new Vector( Math.Max( 0, Math.Min( _offset.X, extent.Width - viewport.Width ) ),
                                    Math.Max( 0, Math.Min( _offset.Y, extent.Height - viewport.Height ) ) );

        SetScrollingData( viewport, extent, offset );

        desiredSize.Width = Math.Min( desiredSize.Width, availableSize.Width );
        desiredSize.Height = Math.Min( desiredSize.Height, availableSize.Height );

        _physicalViewport = availableSize;
      }

      return desiredSize;
    }
开发者ID:Guiedo,项目名称:BehaviorIsManaged,代码行数:101,代码来源:TimelinePanel.cs

示例11: SaveWorkspaceAsImage

        internal void SaveWorkspaceAsImage(string path)
        {
            var initialized = false;
            var bounds = new Rect();

            double minX = 0.0, minY = 0.0;
            var dragCanvas = WpfUtilities.ChildOfType<DragCanvas>(this);
            var childrenCount = VisualTreeHelper.GetChildrenCount(dragCanvas);
            for (int index = 0; index < childrenCount; ++index)
            {
                var child = VisualTreeHelper.GetChild(dragCanvas, index);
                var firstChild = VisualTreeHelper.GetChild(child, 0);

                switch (firstChild.GetType().Name)
                {
                    case "NodeView":
                    case "NoteView":
                    case "AnnotationView":
                        break;

                    // Until we completely removed InfoBubbleView (or fixed its broken 
                    // size calculation), we will not be including it in our size 
                    // calculation here. This means that the info bubble, if any, will 
                    // still go beyond the boundaries of the final PNG file. I would 
                    // prefer not to add this hack here as it introduces multiple issues 
                    // (including NaN for Grid inside the view and the fix would be too 
                    // ugly to type in). Suffice to say that InfoBubbleView is not 
                    // included in the size calculation for screen capture (work-around 
                    // should be obvious).
                    // 
                    // case "InfoBubbleView":
                    //     child = WpfUtilities.ChildOfType<Grid>(child);
                    //     break;

                    // We do not take anything other than those above 
                    // into consideration when the canvas size is measured.
                    default:
                        continue;
                }

                // Determine the smallest corner of all given visual elements on the 
                // graph. This smallest top-left corner value will be useful in making 
                // the offset later on.
                // 
                var childBounds = VisualTreeHelper.GetDescendantBounds(child as Visual);
                minX = childBounds.X < minX ? childBounds.X : minX;
                minY = childBounds.Y < minY ? childBounds.Y : minY;
                childBounds.X = (double)(child as Visual).GetValue(Canvas.LeftProperty);
                childBounds.Y = (double)(child as Visual).GetValue(Canvas.TopProperty);

                if (initialized)
                {
                    bounds.Union(childBounds);
                }
                else
                {
                    initialized = true;
                    bounds = childBounds;
                }
            }

            // Nothing found in the canvas, bail out.
            if (!initialized) return;

            // Add padding to the edge and make them multiples of two (pad 10px on each side).
            bounds.Width = 20 + ((((int)Math.Ceiling(bounds.Width)) + 1) & ~0x01);
            bounds.Height = 20 + ((((int)Math.Ceiling(bounds.Height)) + 1) & ~0x01);

            var currentTransformGroup = WorkspaceElements.RenderTransform as TransformGroup;
            WorkspaceElements.RenderTransform = new TranslateTransform(10.0 - bounds.X - minX, 10.0 - bounds.Y - minY);
            WorkspaceElements.UpdateLayout();

            var rtb = new RenderTargetBitmap(((int)bounds.Width),
                ((int)bounds.Height), 96, 96, PixelFormats.Default);

            rtb.Render(WorkspaceElements);
            WorkspaceElements.RenderTransform = currentTransformGroup;

            try
            {
                using (var stm = System.IO.File.Create(path))
                {
                    // Encode as PNG format
                    var pngEncoder = new PngBitmapEncoder();
                    pngEncoder.Frames.Add(BitmapFrame.Create(rtb));
                    pngEncoder.Save(stm);
                }
            }
            catch (Exception)
            {
            }
        }
开发者ID:Conceptual-Design,项目名称:Dynamo,代码行数:92,代码来源:WorkspaceView.xaml.cs

示例12: ExpandContent

        /// <summary>
        /// Expand the content area to fit the diagram-elements.
        /// </summary>
        private void ExpandContent()
        {
            double smallestX = 0;
            double smallestY = 0;
            var contentRect = new Rect(0, 0, 0, 0);
            foreach (DiagramElement diagramElement in Controller.DiagramElements)
            {
                if (diagramElement.TopLeft.X < smallestX)
                {
                    smallestX = diagramElement.TopLeft.X;
                }

                if (diagramElement.TopLeft.Y < smallestY)
                {
                    smallestY = diagramElement.TopLeft.Y;
                }

                contentRect.Union(new Rect(diagramElement.TopLeft.X, diagramElement.TopLeft.Y, diagramElement.Width, diagramElement.Height));
            }

            // Translate all diagram-elements so they are in positive space.
            smallestX = Math.Abs(smallestX);
            smallestY = Math.Abs(smallestY);

            if (smallestX > 0.01 || smallestY > 0.01)
            {
                Controller.DiagramElements.ToList().ForEach(element => element.AdjustCoordinatesAfterCanvasExpansion(smallestX, smallestY));
            }

            Diagram.ContentWidth = contentRect.Width;
            Diagram.ContentHeight = contentRect.Height;
        }
开发者ID:Benrnz,项目名称:TypeVisualiser,代码行数:35,代码来源:ShellTabControl.xaml.cs

示例13: IsValid

        private ValidSetOfPointsCollection IsValid(List<TouchPoint2> points)
        {
            bool result = true;

            ValidSetOfPointsCollection sets = new ValidSetOfPointsCollection();

            if (points.Count > 0)
            {
                //double minX = int.MinValue, minY = int.MinValue, maxX = int.MaxValue, maxY = int.MaxValue;

                Rect area = new Rect(points[0].Position, new Size(0, 0));

                // Calculate the bounding box that covers all points
                foreach (var point in points)
                {
                    if (_data.HistoryLevel > 0)
                    {
                        Rect location = RuleValidationHelper.GetBoundingBox(point);
                        List<TouchPoint2> selectedPoints = new List<TouchPoint2>();
                        result = RuleValidationHelper.HasPreviousTouchPoints(location, point, _data.HistoryLevel, point.StartTime.AddSeconds(-_data.HistoryTimeLine), selectedPoints);

                        if (result) // Has required number of previous touch points in selected location
                        {
                            foreach (var p in selectedPoints)
                            {
                                area.Union(p.Position);
                            }
                        }
                        else
                        {
                            break;
                        }
                    }

                    area.Union(point.Position);
                }

                // TODO: We need to implement circular area too

                if (result && area.Height <= _data.Height && area.Width <= _data.Width)
                {
                    sets.Add(new ValidSetOfTouchPoints(points));
                }

            }
            return sets;
        }
开发者ID:tuliosouza,项目名称:ASG,代码行数:47,代码来源:TouchAreaValidator.cs

示例14: Bars

 public Bars(Plot2D plot2D, ILArray<double> barStart, ILArray<double> barEnd, ILArray<double> barPosition, ILArray<double> barThickness, BarType barType)
 {
     this.plot2D = plot2D;
     int n = barStart.Length;
     rectangles = new List<Path>();
     Geometry geometry;
     Path rectangle;
     Rect bounds = new Rect();
     Rect rectangleBounds = new Rect();
     for (int i = 0; i < n; ++i)
     {
         rectangle = new Path();
         rectangles.Add(rectangle);
         if (barType == BarType.Horizontal)
         {
             rectangleBounds = new Rect(new Point(barStart.GetValue(i), barPosition.GetValue(i) + barThickness.GetValue(i) / 2),
                 new Point(barEnd.GetValue(i), barPosition.GetValue(i) - barThickness.GetValue(i) / 2));
         }
         else
         {
             rectangleBounds = new Rect(new Point(barPosition.GetValue(i) + barThickness.GetValue(i) / 2, barStart.GetValue(i)),
                 new Point(barPosition.GetValue(i) - barThickness.GetValue(i) / 2, barEnd.GetValue(i)));
         }
         geometry = new RectangleGeometry(rectangleBounds);
         rectangle.Data = geometry;
         geometry.Transform = plot2D.GraphToCanvas;
         rectangle.Fill = (Brush)(this.GetValue(FillProperty));
         rectangle.StrokeThickness = (double)(this.GetValue(StrokeThicknessProperty));
         rectangle.Stroke = (Brush)(this.GetValue(StrokeProperty));
         if (i == 0) bounds = rectangleBounds;
         else
         {
             bounds.Union(rectangleBounds);
         }
     }
     Bounds = bounds;
     SetBindings();
 }
开发者ID:goutkannan,项目名称:ironlab,代码行数:38,代码来源:Plot2DBar.cs

示例15: _CreateVisualChildren

        /// <summary>
        /// Create Gant TimeLine ranges.
        /// </summary>
        protected override Size _CreateVisualChildren(Size dimension, double rangeWidth, int rangeStepInHour)
        {
            Rect boundingRect = new Rect();

            // Calculate range boundbox.
            Size itemSize = new Size(rangeWidth, dimension.Height);
            Rect itemRect = new Rect(new Point(0, 0), itemSize);

            DateTime currentHour;

            // Define start hour: "0" if _startDate in MaxValue
            if (_startHour.Date == DateTime.MaxValue.Date)
                currentHour = DateTime.MinValue;
            else
                currentHour = _startHour;

            int current = 0;
            while (current < (int)_duration)
            {
                // Create TimeLine range.
                DrawingVisual visualItem = _CreateVisualItem(currentHour, rangeStepInHour, itemRect);
                _children.Add(visualItem);

                boundingRect.Union(visualItem.ContentBounds);

                // Relocate for next element.
                itemRect.Offset(rangeWidth, 0);

                currentHour = currentHour.AddHours(rangeStepInHour);
                current += rangeStepInHour;
            }

            return boundingRect.Size;
        }
开发者ID:erindm,项目名称:route-planner-csharp,代码行数:37,代码来源:GanttTimeLinePanel.cs


注:本文中的System.Windows.Rect.Union方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。