Example #1
0
        // public enum CoordinateColisionOption { AllowCollisions, AssignToEmptyNeighbor }
        public static Mask ConvertToMask(MaskF mask)
        {
            if (mask == null)
                throw new ArgumentNullException(nameof(mask));

            var original = mask.UnderlayingArray;
            var usedPoints = new HashSet<Point>();

            for (int i = 0; i < original.Length; i++)
            {
                var convertedPoint = original[i].ToPoint();
                if (!usedPoints.Add(convertedPoint))
                {
                    // Testing the 8 closest coordinates
                    int x = convertedPoint.X;
                    int y = convertedPoint.Y;

                    if (usedPoints.Add(new Point(x - 1, y - 1)) ||
                        usedPoints.Add(new Point(x - 1, y)) ||
                        usedPoints.Add(new Point(x - 1, y + 1)) ||

                        usedPoints.Add(new Point(x, y - 1)) ||
                        usedPoints.Add(new Point(x, y + 1)) ||

                        usedPoints.Add(new Point(x + 1, y - 1)) ||
                        usedPoints.Add(new Point(x + 1, y)) ||
                        usedPoints.Add(new Point(x + 1, y + 1))
                        )
                        continue;
                }
            }

            var convertedMask = new Mask(usedPoints);
            return convertedMask;
        }
Example #2
0
        public static Mask Translate(Mask mask, int xOffset, int yOffset)
        {
            if (mask == null)
                throw new ArgumentNullException(nameof(mask));

            var original = mask.UnderlayingArray;
            var transformedPoints = new Point[original.Length];

            for (int i = 0; i < original.Length; i++)
            {
                var pt = original[i];
                transformedPoints[i] = new Point(pt.X + xOffset, pt.Y + yOffset);
            }

            var translatedMask = new Mask();
            translatedMask.points = transformedPoints;
            translatedMask.Center = new Point(mask.Center.X + xOffset, mask.Center.Y + yOffset);
            translatedMask.Left = mask.Left + xOffset;
            translatedMask.Right = mask.Right + xOffset;
            translatedMask.Top = mask.Top + yOffset;
            translatedMask.Bottom = mask.Bottom + yOffset;

            return translatedMask;
        }
Example #3
0
 public void MaskNulLArgumentConstructor()
 {
     Reference = new Mask(null);
 }
Example #4
0
 public void MaskEquals()
 {
     var other = new Mask(Reference);
     Assert.AreEqual(Reference, other);
 }
Example #5
0
 public void MaskEmptyCollectionConstructor()
 {
     Reference = new Mask(Array.Empty<Point>());
 }
Example #6
0
 public void TestInitialize()
 {
     var numbers = Enumerable.Range(-1, 3);
     var points = new List<Point>(9);
     foreach (var x in numbers)
         foreach (var y in numbers)
             points.Add(new Point(x, y));
     Reference = new Mask(points);
 }