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


C# Range.Intersects方法代码示例

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


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

示例1: IntersectsShouldBeValid

		public void IntersectsShouldBeValid(int s1, int e1, int s2, int e2, bool intersects)
		{
			var r1 = new Range<int>(s1, e1);
			var r2 = new Range<int>(s2, e2);
			Assert.AreEqual(intersects, r1.Intersects(r2));
			Assert.AreEqual(intersects, r2.Intersects(r1));
		}
开发者ID:picoe,项目名称:Eto,代码行数:7,代码来源:RangeTests.cs

示例2: GetRound

        Round GetRound(int n)
        {
            if (roundCache.ContainsKey(n)) return roundCache[n];

            var round = new Round();

            if (n == 0)
            {
                round.KeepRanges.Add (new Range(0, 1));
            }
            else
            {
                var prev = GetRound(n - 1);

                foreach (var r in prev.KeepRanges)
                {
                    var r1 = new Range(r.Min, r.Min + r.Width / 3);
                    var r2 = new Range(r.Min + r.Width / 3, r.Max - r.Width / 3);
                    var r3 = new Range(r.Max - r.Width / 3, r.Max);

                    round.KeepRanges.Add(r1);
                    round.EliminateRanges.Add(r2);
                    round.KeepRanges.Add(r3);

                    Debug.Assert(r.Contains(r1));
                    Debug.Assert(r.Contains(r2));
                    Debug.Assert(r.Contains(r3));
                    Debug.Assert(!r1.Intersects(r2));
                    Debug.Assert(!r2.Intersects(r3));
                    Debug.Assert(!r1.Intersects(r3));
                }

              //  Debug.Assert(!prev.KeepRanges.Any(r=>round.EliminateRanges.Any(x=>r.Intersects(x))));
            }

            Debug.Assert(round.KeepRanges.Count == 1 << n);
            Debug.Assert(round.EliminateRanges.Count == (n>0 ? 1 << (n-1) : 0));

            roundCache.Add (n ,round) ;

            return round;
        }
开发者ID:UIILabsDev,项目名称:CodeJam,代码行数:42,代码来源:TestCase.cs

示例3: IntersectionShouldSuccessIfItHasIntersection

        public void IntersectionShouldSuccessIfItHasIntersection()
        {
            var a = new Range<int>(1, 3);
            var b = new Range<int>(2, 4);
            Assert.True(a.Intersects(b));
            Assert.True(b.Intersects(a));

            a = new Range<int>(2, 3);
            b = new Range<int>(1, 4);
            Assert.True(a.Intersects(b));
            Assert.True(b.Intersects(a));

            a = new Range<int>(1, 3);
            b = new Range<int>(3, 4);
            Assert.True(a.Intersects(b));
            Assert.True(b.Intersects(a));

            a = new Range<int>(2, 3);
            b = new Range<int>(1, 2);
            Assert.True(a.Intersects(b));
            Assert.True(b.Intersects(a));

            a = new Range<int>(2, 3);
            b = new Range<int>(2, 3);
            Assert.True(a.Intersects(b));
            Assert.True(b.Intersects(a));

            a = new Range<int>(2, 2);
            b = new Range<int>(2, 2);
            Assert.True(a.Intersects(b));
            Assert.True(b.Intersects(a));

            a = new Range<int>(1);
            b = new Range<int>(2, 4);
            Assert.True(a.Intersects(b));
            Assert.True(b.Intersects(a));

            a = new Range<int>(null, 3);
            b = new Range<int>(2, 4);
            Assert.True(a.Intersects(b));
            Assert.True(b.Intersects(a));

            a = new Range<int>(null, 3);
            b = new Range<int>(null, 4);
            Assert.True(a.Intersects(b));
            Assert.True(b.Intersects(a));

            a = new Range<int>(1);
            b = new Range<int>(2);
            Assert.True(a.Intersects(b));
            Assert.True(b.Intersects(a));

            a = new Range<int>(1);
            b = new Range<int>(null, 4);
            Assert.True(a.Intersects(b));
            Assert.True(b.Intersects(a));

            a = new Range<int>(null, 3);
            b = new Range<int>(2);
            Assert.True(a.Intersects(b));
            Assert.True(b.Intersects(a));

            a = new Range<int>(null);
            b = new Range<int>(1, 6);
            Assert.True(a.Intersects(b));
            Assert.True(b.Intersects(a));
        }
开发者ID:jonathascosta,项目名称:SystemExtensions,代码行数:67,代码来源:RangeFixture.cs

示例4: IntersectionShouldFailIfItHasNoIntersection

        public void IntersectionShouldFailIfItHasNoIntersection()
        {
            var a = new Range<int>(1, 3);
            var b = new Range<int>(4, 6);
            Assert.False(a.Intersects(b));
            Assert.False(b.Intersects(a));

            a = new Range<int>(3);
            b = new Range<int>(1, 2);
            Assert.False(a.Intersects(b));
            Assert.False(b.Intersects(a));

            a = new Range<int>(null, 2);
            b = new Range<int>(3, 4);
            Assert.False(a.Intersects(b));
            Assert.False(b.Intersects(a));

            a = new Range<int>(4);
            b = new Range<int>(null, 3);
            Assert.False(a.Intersects(b));
            Assert.False(b.Intersects(a));
        }
开发者ID:jonathascosta,项目名称:SystemExtensions,代码行数:22,代码来源:RangeFixture.cs

示例5: DrawXAxisLabels

    /// <summary>
    /// Draws the X Axis labels, returns the height required to fit all the labels.
    /// </summary>
    /// <param name="dc"></param>
    /// <param name="scaleY"></param>
    /// <param name="labels"></param>
    /// <param name="offset"></param>
    /// <returns></returns>
    private double DrawXAxisLabels(DrawingContext dc, double scaleX, IEnumerable<GridLabel> labels, double offset) {

      // A list of areas on the label area on which we've already rendered text.
      // If we go to render text on a area that's already used, then go to the next
      // area and move out one width
      List<List<Range<double>>> usedDrawingAreas = new List<List<Range<double>>>();
      usedDrawingAreas.Add(new List<Range<double>>());

      List<double> maxHeights = new List<double>();
      maxHeights.Add(0);

      // First of all work out all of the render positions on the y axis

      List<LabelAndPos> labelAndPos = new List<LabelAndPos>();

      foreach(var gridLabel in labels) {
        double xValue = gridLabel.IsFloating ? (MinPoint.X + MaxPoint.X) * 0.5 : gridLabel.Location;
        if(!RangeX.Contains(xValue)) {
          continue;
        }
        double xPos = (-xValue + MinPoint.X) * scaleX + this.ActualWidth;
        int labelIndex = 0;
        FormattedText formattedText = GetText(gridLabel.Text, gridLabel.Brush);

        UnrestrictedSize labelArea;
        if(gridLabel.Orientation == Orientation.Vertical) {
          labelArea = new UnrestrictedSize(formattedText.Height, formattedText.Width);
        } else {
          labelArea = new UnrestrictedSize(formattedText.Width, formattedText.Height);
        }

        Point textPoint = new Point(xPos - labelArea.Width * 0.5 - 1 , offset);
        textPoint.X = Math.Min(textPoint.X, this.ActualWidth - Math.Max(0, labelArea.Width * 0.5));
        // Uncomment this line to stop any labels going below the bottom chart line
        //textPoint.X = Math.Max(textPoint.X, 0);
        Range<double> range = new Range<double>(textPoint.X, textPoint.X + labelArea.Width);

        bool intersects;
        do {
          intersects = false;
          foreach(var usedRange in usedDrawingAreas[labelIndex]) {
            if(range.Intersects(usedRange)) {
              intersects = true;
              labelIndex++;
              if(usedDrawingAreas.Count <= labelIndex) {
                usedDrawingAreas.Add(new List<Range<double>>());
                maxHeights.Add(0);
              }
              break;
            }
          }
        } while(intersects);

        usedDrawingAreas[labelIndex].Add(range);
        maxHeights[labelIndex] = Math.Max(maxHeights[labelIndex], labelArea.Height);
        labelAndPos.Add(new LabelAndPos(formattedText, textPoint, labelIndex, gridLabel.Orientation));
      }

      List<double> labelOffsets = new List<double>();
      labelOffsets.Add(0);
      double labelOffset = -2;
      foreach(double height in maxHeights) {
        labelOffset += 2 + height;
        labelOffsets.Add(labelOffset);
      }

      foreach(var gridLabel in labelAndPos) {
        FormattedText formattedText = gridLabel.Text;
        Point textPoint = gridLabel.Location;
        textPoint.X -= labelOffsets[gridLabel.Layer];
        if(gridLabel.Orientation == Orientation.Vertical) {
          RotateTransform rotateTransform = new RotateTransform(-90);
          dc.PushTransform(rotateTransform);
          textPoint = rotateTransform.Inverse.Transform(textPoint);
          dc.DrawText(formattedText, textPoint);
          dc.Pop();
        } else {
          dc.DrawText(formattedText, textPoint);
        }
      }

      double totalMaxHeight = -2;
      foreach(var maxHeight in maxHeights) {
        totalMaxHeight += maxHeight + 2;
      }
      return totalMaxHeight;
    }
开发者ID:jrc60752,项目名称:iRacingAdminSync,代码行数:95,代码来源:GridLineCanvas.cs

示例6: intersects_range

        public void intersects_range() {
            var a = new Range(0, 0);
            var b = new Range(1, 1);
            var c = new Range(-1, 3);
            var d = new Range(4, 2);

            Assert.False(a.Intersects(b));
            Assert.True(a.Intersects(a));
            Assert.True(b.Intersects(b));
            Assert.True(c.Intersects(d));
            Assert.True(c.Intersects(a));
            Assert.True(b.Intersects(c));
            Assert.False(b.Intersects(d));
        }
开发者ID:aarondandy,项目名称:vertesaur,代码行数:14,代码来源:RangeFacts.cs

示例7: intersects_value

        public void intersects_value() {
            var a = new Range(0, 0);
            var b = new Range(1, 1);
            var c = new Range(3, 1);

            Assert.True(a.Intersects(0));
            Assert.False(a.Intersects(1));
            Assert.False(b.Intersects(0));
            Assert.True(b.Intersects(1));
            Assert.False(c.Intersects(-1));
            Assert.False(c.Intersects(0));
            Assert.True(c.Intersects(1));
            Assert.True(c.Intersects(2));
            Assert.True(c.Intersects(3));
            Assert.False(c.Intersects(4));
            Assert.False(c.Intersects(-3));
        }
开发者ID:aarondandy,项目名称:vertesaur,代码行数:17,代码来源:RangeFacts.cs


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