Example #1
0
        public IEnumerable <Segment1i> Lerp(Segment1i target)
        {
            if (target.a == a && target.b == b)
            {
                yield break;
            }
            int currA = a,
                currB = b,
                lenA  = target.a - a,
                lenB  = target.b - b,
                stepA = Math.Sign(lenA),
                stepB = Math.Sign(lenB);

            for (int i = Math.Max(Math.Abs(lenA), Math.Abs(lenB)); i > 1; i--)
            {
                if (currA != target.a)
                {
                    currA += stepA;
                }
                if (currB != target.b)
                {
                    currB += stepB;
                }
                yield return(new Segment1i(currA, currB));
            }
        }
Example #2
0
        /// <summary>
        /// Determines if any one of the edges of the given rectangle overlaps one of the edges.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool OverlapsEdge(Recti other)
        {
            Segment1i h = new Segment1i(other.left, other.right),
                      v = new Segment1i(other.bottom, other.top);

            return(OverlapsEdge(h, other.bottom, false) ||
                   OverlapsEdge(v, other.left, true) ||
                   OverlapsEdge(h, other.top - 1, false) ||
                   OverlapsEdge(v, other.right - 1, true));
        }
Example #3
0
 /// <summary>
 /// Determines if the given line segment overlaps one of the edges.
 /// </summary>
 public bool OverlapsEdge(Segment1i line, int otherAxis, bool isVertical)
 {
     if (isVertical)
     {
         return((otherAxis == left || otherAxis == right - 1) && line.Overlaps(new Segment1i(yMin, yMax)));
     }
     else
     {
         return((otherAxis == bottom || otherAxis == top - 1) && line.Overlaps(new Segment1i(xMin, xMax)));
     }
 }
Example #4
0
 public Segment1i Union(Segment1i other)
 {
     return(new Segment1i(Math.Min(a, other.a), Math.Max(b, other.b)));
 }
Example #5
0
        //public Segment1i Resize(int amount)
        //{
        //    Assert.IsTrue(length + amount * 2 > 0);
        //    if (!incremental)
        //        amount = -amount;

        //    a -= amount;
        //    b += amount;

        //    return this;
        //}

        public Segment1i Intersect(Segment1i other)
        {
            return(Overlaps(other) ?
                   new Segment1i(Math.Max(a, other.a), Math.Min(b, other.b)) :
                   new Segment1i(0, 0));
        }
Example #6
0
 /// <summary>Returns the distance (non-negative) to another segment.</summary>
 /// <param name="other">The other segment.</param>
 public int Distance(Segment1i other)
 {
     return(Overlaps(other) ? 0 :
            Math.Min(Math.Abs(a - other.b + 1), Math.Abs(other.a - b + 1)));
 }
Example #7
0
 public bool Overlaps(Segment1i other)
 {
     return(a < other.b && b > other.a);
 }