示例#1
0
        /// <summary>
        /// Generate random points on a board for testing purposes
        /// </summary>
        /// <param name="topLeft"></param>
        /// <param name="bottomRight"></param>
        /// <param name="pointCount"></param>
        /// <param name="seed">The random seed to use, or a negative number to randomize the seed</param>
        /// <returns></returns>
        public static Core.Point[] GenerateRandomPoints(Core.Point topLeft, Core.Point bottomRight, int pointCount, int seed = -1)
        {
            int width  = bottomRight.X - topLeft.X + 1;
            int height = bottomRight.Y - topLeft.Y + 1;

            Random rnd;

            if (seed < 0)
            {
                rnd = new Random();
            }
            else
            {
                rnd = new Random(seed);
            }
            Core.Point[] randomPoints = new Core.Point[pointCount];
            for (int i = 0; i < randomPoints.Length; i++)
            {
                int        randomX     = topLeft.X + rnd.Next(width);
                int        randomY     = topLeft.Y + rnd.Next(height);
                Core.Point randomPoint = new Core.Point((short)randomX, (short)randomY);
                randomPoints[i] = randomPoint;
            }
            return(randomPoints);
        }
示例#2
0
 public void SelectPoint(Core.Point point)
 {
     if (point.Z > 0)
     {
         this.handData.MarkCenterOfPalm(point);
     }
 }
示例#3
0
        public static Contour AlignInUnitRectangle(Contour c)
        {
            const float indention             = 0.05f;
            const float side                  = 1.0f;
            const float sideWithoutIndentions = side - 2 * indention;

            float minX = c.Points.Select(p => p.X).Min();
            float minY = c.Points.Select(p => p.Y).Min();

            float maxX = c.Points.Select(p => p.X).Max();
            float maxY = c.Points.Select(p => p.Y).Max();

            float realW = maxX - minX;
            float realH = maxY - minY;

            float maxSide = (float)Math.Max(realW, realH);

            float mult = sideWithoutIndentions / maxSide;

            var points = new List <ContourAnalysis.Core.Point>();

            foreach (var p in c.Points)
            {
                float newX = indention + (p.X - minX) * mult + (sideWithoutIndentions - realW * mult) / 2.0f;
                float newY = indention + (p.Y - minY) * mult + (sideWithoutIndentions - realH * mult) / 2.0f;

                Core.Point np = new Core.Point(newX, newY);

                points.Add(np);
            }

            return(new Contour(points.ToArray()));
        }
示例#4
0
 public Cuboid(bool on, int xi, int xa, int yi, int ya, int zi, int za)
 {
     On = on;
     X  = new Core.Point(xi, xa);
     Y  = new Core.Point(yi, ya);
     Z  = new Core.Point(zi, za);
 }
示例#5
0
 public Cuboid(bool on)
 {
     On = on;
     X  = new Core.Point(0, 0);
     Y  = new Core.Point(0, 0);
     Z  = new Core.Point(0, 0);
 }
        private static Rectangle GetCellSizeRectangle(Core.Point point, Direction?direction, int pathToNextPosLength, int cellSize)
        {
            int dx = 0;
            int dy = 0;

            switch (direction)
            {
            case Direction.Left:
                dx = -pathToNextPosLength;
                break;

            case Direction.Up:
                dy = -pathToNextPosLength;
                break;

            case Direction.Right:
                dx = pathToNextPosLength;
                break;

            case Direction.Down:
                dy = pathToNextPosLength;
                break;

            case null:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(direction), direction, null);
            }

            return(new Rectangle(point.X * cellSize + dx, point.Y * cellSize + dy, cellSize - 1, cellSize - 1));
        }
示例#7
0
 private void AdjustVelocity(ref Core.Point position, ref Core.Point velocity)
 {
     position += velocity;
     if (velocity.X != 0)
     {
         velocity.X -= velocity.X > 0 ? 1 : -1;
     }
     velocity.Y -= 1;
 }
示例#8
0
        private string SharedSolution(List <string> inputs, Dictionary <string, string> variables, bool enlargen)
        {
            Node[,] nodes = GetNodes(inputs, enlargen, out int maxX, out int maxY);
            Core.Point end = new Core.Point(maxX - 1, maxY - 1);

            PriorityQueue <Core.Point, long> gridWalker = new PriorityQueue <Core.Point, long>();

            gridWalker.Enqueue(new Core.Point(0, 0), 0);
            while (gridWalker.Count > 0)
            {
                Core.Point curPos = gridWalker.Dequeue();

                Node curNode = nodes[curPos.X, curPos.Y];
                if (curNode.Done)
                {
                    continue;
                }
                curNode.Done = true;

                Node prevNode = nodes[curNode.Prev.X, curNode.Prev.Y];
                curNode.Path = prevNode.Path + curNode.Weight;

                if (curPos.Equals(end))
                {
                    break;
                }

                foreach (Core.Point gridMove in GridMoves)
                {
                    Core.Point nextMove = curPos + gridMove;
                    if (nextMove.X >= 0 && nextMove.X < maxX && nextMove.Y >= 0 && nextMove.Y < maxY)
                    {
                        Node nextNode = nodes[nextMove.X, nextMove.Y];
                        if (!nextNode.Done)
                        {
                            if (nextNode.Prev != null)
                            {
                                Node existing = nodes[nextNode.Prev.X, nextNode.Prev.Y];
                                if (curNode.Path < existing.Path)
                                {
                                    nextNode.Prev = curPos;
                                }
                            }
                            else
                            {
                                nextNode.Prev = curPos;
                            }
                            gridWalker.Enqueue(nextMove, curNode.Path + nextNode.Weight);
                        }
                    }
                }
            }

            return(nodes[maxX - 1, maxY - 1].Path.ToString());
        }
示例#9
0
        private int Step(ref int[,] grid, int maxX, int maxY)
        {
            HashSet <Core.Point> history = new HashSet <Core.Point>();
            Queue <Core.Point>   flash   = new Queue <Core.Point>();

            for (int x = 0; x < maxX; ++x)
            {
                for (int y = 0; y < maxY; ++y)
                {
                    ++grid[x, y];
                    if (grid[x, y] > 9)
                    {
                        flash.Enqueue(new Core.Point(x, y));
                    }
                }
            }

            while (flash.Count > 0)
            {
                Core.Point cur = flash.Dequeue();
                if (cur.X < 0 || cur.X >= maxX || cur.Y < 0 || cur.Y >= maxY)
                {
                    continue;
                }
                if (history.Contains(cur))
                {
                    continue;
                }
                if (++grid[cur.X, cur.Y] > 9)
                {
                    history.Add(cur);
                    foreach (Core.Point next in Surrounding)
                    {
                        flash.Enqueue(cur + next);
                    }
                }
            }

            int flashCount = 0;

            foreach (Core.Point cur in history)
            {
                if (grid[cur.X, cur.Y] > 9)
                {
                    grid[cur.X, cur.Y] = 0;
                    ++flashCount;
                }
            }
            return(flashCount);
        }
示例#10
0
        public void SelectPoint(Core.Point point)
        {
            if (point.Z > 0)
            {
                var existingPoint = this.handData.FingerPoints.Where(p => Point.Distance(p.Point, point) < 15).FirstOrDefault();

                if (existingPoint == null)
                {
                    this.handData.MarkFinger(new FingerPointViewModel(point));
                }
                else
                {
                    existingPoint.Point = point;
                }
            }
        }
        public static void CalculateSegmentStatesUsingOnTheFlyBoolBoolBasedCalculator(
            Tuple <Core.Point, OnTheFlyBoolMatrixBasedSegmentStateCalculator> tuple)
        {
            Core.Point bottomRight = tuple.Item1;
            OnTheFlyBoolMatrixBasedSegmentStateCalculator calculator = tuple.Item2;

            foreach (Axis axis in BoardHelper.AllRealAxes)
            {
                for (int x = 0; x < bottomRight.X; x++)
                {
                    for (int y = 0; y < bottomRight.Y; y++)
                    {
                        SegmentState segState = calculator.GetSegmentState(axis, x, y);
                    }
                }
            }
        }
示例#12
0
 private void GetStartX(int minX, int maxX, out int startX)
 {
     for (int x = 1; ; ++x)
     {
         Core.Point probe    = new Core.Point(0, 0);
         Core.Point velocity = new Core.Point(x, 0);
         while (velocity.X > 0 && probe.X <= maxX)
         {
             AdjustVelocity(ref probe, ref velocity);
             if (probe.X >= minX)
             {
                 startX = x;
                 return;
             }
         }
     }
 }
示例#13
0
        private char EnhancePixel(List <string> pixels, string algorithm, int x, int y, char defaultPixel)
        {
            StringBuilder sb = new StringBuilder();

            Core.Point curPixel = new Core.Point(x, y);
            foreach (Core.Point gridPixel in PixelCheck.Select(p => curPixel + p))
            {
                if (gridPixel.Y < 0 || gridPixel.Y >= pixels.Count || gridPixel.X < 0 || gridPixel.X >= pixels[y].Length)
                {
                    sb.Append(defaultPixel);
                }
                else
                {
                    sb.Append(pixels[gridPixel.Y][gridPixel.X]);
                }
            }

            string binary = sb.Replace(DarkPixel, '0').Replace(LightPixel, '1').ToString();
            int    key    = Convert.ToInt32(binary, 2);

            return(algorithm[key]);
        }
示例#14
0
        private int SolveAll(int startX, List <int> possibleYs, int minX, int maxX, int minY, int maxY)
        {
            possibleYs.AddRange(Enumerable.Range(1, minY * -1).Select(e => e * -1));
            HashSet <Core.Point> knownLocations = new HashSet <Core.Point>();

            foreach (int y in possibleYs)
            {
                for (int x = startX; x <= maxX; ++x)
                {
                    Core.Point pos = new Core.Point(0, 0);
                    Core.Point vel = new Core.Point(x, y);
                    while (pos.X < maxX && pos.Y > minY)
                    {
                        AdjustVelocity(ref pos, ref vel);
                        if (minX <= pos.X && pos.X <= maxX && minY <= pos.Y && pos.Y <= maxY)
                        {
                            knownLocations.Add(new Core.Point(x, y));
                            break;
                        }
                    }
                }
            }
            return(knownLocations.Count);
        }
示例#15
0
 public static void Draw(this Console console, Point point, ColoredGlyph glyph)
 {
     console.Cursor.Position = point.ToSadPoint();
     Draw(console, glyph.Foreground, glyph.Glyph);
 }
 private static Rectangle GetCellSizeRectangle(Core.Point point, int cellSize)
 {
     return(new Rectangle(point.X * cellSize, point.Y * cellSize, cellSize - 1, cellSize - 1));
 }
 public FingerPointViewModel(Core.Point point)
 {
     this.point = point;
 }
 private static Core.Point TranslateCoordinates(Core.Point point, Core.Size mapSize)
 {
     return(new Core.Point(point.X, mapSize.Height - point.Y - 1));
 }
示例#19
0
 private void Populate(ref Node[,] nodes, Core.Point start, Core.Point end)
 {
 }
 public Point ConvertPoint(Core.Point point)
 {
     return(new Point(point.X * this.xMultiplicator + 5, point.Y * this.yMultiplicator + 10));
 }
示例#21
0
 public SKPoint PointToDisplaySkiaPoint(Core.Point p)
 {
     return(new SKPoint((float)((p.X - shift_x) * zoom), (float)((p.Y - shift_y) * zoom)));
 }
示例#22
0
 public CellClickedEventArgs(CellView view, Core.Point position)
 {
     View     = view;
     Position = position;
 }
 public FingerPointViewModel(Core.Point point)
 {
     this.point = point;
 }