Пример #1
0
 private void _DrawPoint(Int32Point pos, byte[] color, int colorValue, int thickness = 1)
 {
     foreach (var point in GeometryHelper.CalcPositions(pos.X, pos.Y, Offset, Stride, thickness, _bounds, _flags))
     {
         _DrawPixel(point, color, colorValue);
     }
 }
Пример #2
0
        private void MainWindow_MouseUp(object sender, MouseButtonEventArgs e)
        {
            _down = false;
            InvalidateVisual();

            // find rects selected
            var x1 = (int)Math.Floor(_position1.X / (size.Width / columns));
            var y1 = (int)Math.Floor(_position1.Y / (size.Height / rows));
            var x2 = (int)Math.Ceiling(_position2.X / (size.Width / columns));
            var y2 = (int)Math.Ceiling(_position2.Y / (size.Height / rows));
            var w  = x2 - x1;
            var h  = y2 - y1;

            var builder = new StringBuilder();

            for (var y = 0; y < h; y++)
            {
                for (var x = 0; x < w; x++)
                {
                    var int32Point = new Int32Point(x1 + x, y1 + y);
                    var add        = _set.Add(int32Point);
                    if (add)
                    {
                        // download image !!!
                    }
                    else
                    {
                        // image already downloaded, do something !
                    }
                    builder.AppendLine(string.Format("{0} : {1}", int32Point, (add ? "added" : "ignored")));
                }
            }
            MessageBox.Show(builder.ToString());
        }
Пример #3
0
        public Ellipse(byte[] fillColor, Int32Point center, Int32 radiusX, Int32 radiusY, _DrawingPen pen)
        {
            _fillColor     = fillColor;
            Center         = center;
            RadiusX        = radiusX;
            RadiusY        = radiusY;
            RadiusXSquared = (Int64)RadiusX * RadiusX;
            RadiusYSquared = (Int64)RadiusY * RadiusY;
            SplitX         = (Int32)(RadiusXSquared / Math.Sqrt(RadiusXSquared + RadiusYSquared));
            A_2            = Math.Max(RadiusX, RadiusY) << 1;
            Int32 c;

            if (RadiusX > RadiusY)
            {
                c = (Int32)Math.Sqrt(RadiusXSquared - RadiusYSquared);
            }
            else
            {
                c = (Int32)Math.Sqrt(RadiusYSquared - RadiusXSquared);
            }
            if (radiusX > radiusY)
            {
                FocusP1 = new Int32Point(center.X + c, center.Y);
                FocusP2 = new Int32Point(center.X - c, center.Y);
            }
            else
            {
                FocusP1 = new Int32Point(center.X, center.Y + c);
                FocusP2 = new Int32Point(center.X, center.Y - c);
            }
            var _bounds = GeometryHelper.CalcBounds(center, radiusX, RadiusY, pen.Thickness);

            _property = new PrimitiveProperty(pen, _bounds);
        }
Пример #4
0
    private List <Int32Point> GetCellNeighbours(Int32Point cell)
    {
        List <Int32Point> neighbours = new List <Int32Point> ();

        if (cell != null)
        {
            int x = cell.X;
            int y = cell.Y;

            if (x > 0)
            {
                neighbours.Add(new Int32Point(x - 1, y));
            }

            if (x < Width - 1)
            {
                neighbours.Add(new Int32Point(x + 1, y));
            }

            if (y > 0)
            {
                neighbours.Add(new Int32Point(x, y - 1));
            }

            if (y < Height - 1)
            {
                neighbours.Add(new Int32Point(x, y + 1));
            }
        }

        return(neighbours);
    }
Пример #5
0
    bool HasWallBetween(Int32Point cell1, Int32Point cell2)
    {
        Int32Point diff     = cell1 - cell2;
        WallType   wallType = WallType.None;

        if (diff.X != 0)
        {
            if (diff.X > 0)
            {
                wallType = WallType.Left;
            }
            else
            {
                wallType = WallType.Right;
            }
        }
        else if (diff.Y != 0)
        {
            if (diff.Y < 0)
            {
                wallType = WallType.Top;
            }
            else
            {
                wallType = WallType.Bottom;
            }
        }

        if (wallType != WallType.None)
        {
            return(mazeLayer.LayerArray [cell1.X, cell1.Y].GetComponent <CellBehavior> ().IsWallStanding(wallType));
        }

        return(false);
    }
Пример #6
0
        /// <summary>
        /// Swaps the two given points.
        /// </summary>
        /// <param name="a">Point a.</param>
        /// <param name="b">Point b.</param>
        private static void Swap(ref Int32Point a, ref Int32Point b)
        {
            var tmp = a;

            a = b;
            b = tmp;
        }
Пример #7
0
        public DesignTimeGraphicsPixelHistoryViewModel()
            : base(new DesignTimeSelectionService())
        {
            HasSelectedPixel      = true;
            FinalFrameBufferColor = new ColorViewModel(new Number4(0, 0, 1, 1));

            FrameNumber   = 2;
            PixelLocation = new Int32Point(200, 305);

            PixelEvents.AddRange(new[]
            {
                new PixelHistoryEventViewModel(new TracefileEvent
                {
                    Number        = 1,
                    OperationType = OperationType.DeviceContextClearRenderTargetView,
                    PixelEvents   = new List <PixelEvent>(new[] { new SimpleEvent(new Number4(1, 0, 0, 1)) })
                }),
                new PixelHistoryEventViewModel(new TracefileEvent
                {
                    Number        = 15,
                    OperationType = OperationType.DeviceContextDraw,
                    PixelEvents   = new List <PixelEvent>(new[]
                    {
                        DesignTimeDrawPixelHistoryEventViewModel.CreateDrawEvent(),
                        DesignTimeDrawPixelHistoryEventViewModel.CreateDrawEvent(PixelExclusionReason.FailedDepthTest)
                    })
                }),
            });
        }
Пример #8
0
        public void SetBits(Buffer2DView <T> srcView, Int32Rect srcRect, Int32Point?dstPoint = null)
        {
            if (srcRect.X < 0 || srcRect.Width < 0 || (srcRect.X + srcRect.Width) > srcView._buffer._bounds.Width ||
                srcRect.Y < 0 || srcRect.Height < 0 || (srcRect.Y + srcRect.Height) > srcView._buffer._bounds.Height)
            {
                throw new ArgumentOutOfRangeException("srcRect", "The source rect must specify coordinates within the bounds of the source buffer.");
            }

            Int32Point theDstPoint = dstPoint ?? new Int32Point(srcRect.X, srcRect.Y);

            if (theDstPoint.X < 0 || (theDstPoint.X + srcRect.Width) > _bounds.Width ||
                theDstPoint.Y < 0 || (theDstPoint.Y + srcRect.Height) > _bounds.Height)
            {
                throw new ArgumentOutOfRangeException("dstPoint", "The destination point must specify coordinates within the bounds of the buffer.");
            }

            unsafe
            {
                int   sizeOfT = Marshal.SizeOf(typeof(T));
                byte *pRead   = ((byte *)srcView._buffer._pBits.ToPointer()) + (srcRect.Y + srcView._buffer._bounds.Y) * srcView._buffer._rowWidth * sizeOfT + (srcRect.X + srcView._buffer._bounds.X) * sizeOfT;
                byte *pWrite  = ((byte *)_pBits.ToPointer()) + (theDstPoint.Y + _bounds.Y) * _rowWidth * sizeOfT + (theDstPoint.X + _bounds.X) * sizeOfT;

                for (int row = 0; row < srcRect.Height; row++)
                {
                    for (int col = 0; col < srcRect.Width * sizeOfT; col++)
                    {
                        *(pWrite + col) = *(pRead + col);
                    }

                    pRead  += srcView._buffer._rowWidth * sizeOfT;
                    pWrite += _rowWidth * sizeOfT;
                }
            }
        }
Пример #9
0
        private void DrawTriangleCore(Color c, Int32Point p1, Int32Point p2, Int32Point p3, bool mr, bool ml)
        {
            int  currentLine, bottom;
            bool flatTop = (mr && p1.Y == p2.Y) || (ml && p2.Y == p3.Y) || (p1.Y == p3.Y),
                 flatBottom = p1.Y == p3.Y && p2.Y < p1.Y;
            BresenhamEnumerator leftSide, rightSide;

            if (flatTop && mr)
            {
                currentLine = p1.Y;
                leftSide    = new BresenhamEnumerator(p1, p3);
                rightSide   = new BresenhamEnumerator(p2, p3);
                bottom      = p3.Y;
            }
            else if (flatTop && ml)
            {
                return;
            }
            else
            {
                currentLine = p2.Y;
                bottom      = Math.Min(p1.Y, p3.Y);
                leftSide    = new BresenhamEnumerator(p2, p1);
                rightSide   = new BresenhamEnumerator(p2, p3);
            }

            int leftX  = leftSide.Current.X,
                rightX = rightSide.Current.X;

            while (currentLine < bottom)
            {
                // Draw current scan line
                context.FillRect(c, new Int32Rect(leftX, currentLine, rightX - leftX + 1, 1));

                // Advance to next scan line
                //
                leftSide.MoveNextY();
                rightSide.MoveNextY();
                currentLine++;

                leftX  = leftSide.Current.X;
                rightX = rightSide.Current.X;
            }

            if (flatTop || flatBottom)
            {
                // Draw last line
                context.FillRect(c, new Int32Rect(leftX, currentLine, rightX - leftX + 1, 1));
            }
            else if (mr)
            {
                // Draw bottom triangle
                DrawTriangleCore(c, p1, new Int32Point(rightX, currentLine), p3, mr, ml);
            }
            else if (ml)
            {
                // Draw bottom triangle
                // DrawTriangleCore(new Int32Point(leftX, currentLine), p3, mr, ml);
            }
        }
Пример #10
0
        /// <summary>
        /// Swaps two points.
        /// </summary>
        /// <param name="a">Point a.</param>
        /// <param name="b">Point b.</param>
        private static void SwapPoints(ref Int32Point a, ref Int32Point b)
        {
            Int32Point tmp = a;

            a = b;
            b = tmp;
        }
Пример #11
0
    public MazeGraph GenerateGraphPathFromMaze(Int32Point point)
    {
        MazeGraph pathGraph = new MazeGraph();

        Stack <Int32Point> cells          = new Stack <Int32Point> ();
        List <Int32Point>  processedCells = new List <Int32Point> ();

        cells.Push(point);

        while (cells.Count > 0)
        {
            Int32Point cell = cells.Pop();

            if (processedCells.Contains(cell))
            {
                continue;
            }

            processedCells.Add(cell);
            List <Int32Point> neighbours = GetCellNeighbours(cell);

            foreach (Int32Point neighbour in neighbours)
            {
                if (!HasWallBetween(cell, neighbour))
                {
                    pathGraph.AddEdge(cell, neighbour);
                    cells.Push(neighbour);
                }
            }
        }

        //Debug.Log (pathGraph);
        return(pathGraph);
    }
Пример #12
0
    private void GenerateMaze()
    {
        GenerateEmptyMaze();

        Stack <Int32Point> cellLocations = new Stack <Int32Point> ();
        Int32Point         currentCell   = new Int32Point(Random.Range(0, Width), Random.Range(0, Height));

        int visitedCells = 1;

        while (visitedCells != TotalCells)
        {
            List <Int32Point> intactNeighbors = GetIntactNeighbors(currentCell);

            if (intactNeighbors.Count > 0)
            {
                Int32Point randomNeighbor = intactNeighbors [Random.Range(0, intactNeighbors.Count)];

                KnockWallBetween(currentCell, randomNeighbor);
                cellLocations.Push(currentCell);
                currentCell = randomNeighbor;

                visitedCells++;
            }
            else
            {
                currentCell = cellLocations.Pop();
            }
        }
    }
        private static Int32Point?GetNeighbour4(Int32Point u, int neighbourIndex, LiveWireGraph graph, out double distance)
        {
            int width  = graph.Width;
            int height = graph.Height;
            int x      = u.X;
            int y      = u.Y;

            distance = 0.0;

            switch (neighbourIndex)
            {
            case 0:
                if (x >= width - 1)
                {
                    return(null);
                }
                else
                {
                    distance = graph.EdgeData[y * width + x, 0];
                    return(new Int32Point(x + 1, y));
                }

            case 1:
                if (y >= height - 1)
                {
                    return(null);
                }
                else
                {
                    distance = graph.EdgeData[y * width + x, 2];
                    return(new Int32Point(x, y + 1));
                }

            case 2:
                if (x == 0)
                {
                    return(null);
                }
                else
                {
                    distance = graph.EdgeData[y * width + x - 1, 0];
                    return(new Int32Point(x - 1, y));
                }

            case 3:
                if (y == 0)
                {
                    return(null);
                }
                else
                {
                    distance = graph.EdgeData[y * width + x - width, 2];
                    return(new Int32Point(x, y - 1));
                }

            default:
                return(null);
            }
        }
Пример #14
0
 public bool HitTest(Int32Point p)
 {
     if (GeometryHelper.IsPossibleArcContains(Center, Start, End, p))
     {
         return(Math.Abs((p - Center).Length - Radius) <= _property.Pen.Thickness + VisualHelper.HitTestThickness);
     }
     return(false);
 }
Пример #15
0
            public PointToProcess(Int32Point point)
            {
                X = point.X;
                Y = point.Y;

                K        = 0;
                Distance = 0;
            }
Пример #16
0
        internal Cicle(byte[] fillColor, Int32Point center, Int32 radius, _DrawingPen pen)
        {
            _fillColor = fillColor;
            Center     = center;
            Radius     = radius;
            var _bounds = GeometryHelper.CalcBounds(center, radius, pen.Thickness);

            _property = new PrimitiveProperty(pen, _bounds);
        }
Пример #17
0
        internal void DrawLine(Color color, Int32Point start, Int32Point end)
        {
            // Implementation of the Bresenham line algorithm derived from the ideas given in
            // https://de.wikipedia.org/wiki/Bresenham-Algorithmus
            // https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm

            int x1 = start.X;
            int y1 = start.Y;
            int x2 = end.X;
            int y2 = end.Y;

            int dy   = y2 - y1;
            int dx   = x2 - x1;
            int xinc = Math.Sign(dx);
            int yinc = Math.Sign(dy);

            dx *= xinc;  // make dx always positive
            dy *= yinc;  // make dy always positive

            if (dy == 0) // horizontal line
            {
                FillRect(color, new Int32Rect((x2 < x1 ? x2 : x1), y1, Math.Abs(x2 - x1), 1));
            }
            else if (dx == 0) // vertical line
            {
                FillRect(color, new Int32Rect(x1, (y2 < y1 ? y2 : y1), 1, Math.Abs(y2 - y1)));
            }

            else if (dy <= dx) // between pi/4 and -pi/4 (including)
            {
                int error = -dx / 2;
                for (; x1 != x2; x1 += xinc)
                {
                    DrawPixel(color, x1, y1);
                    error += dy;
                    if (error >= 0)
                    {
                        y1    += yinc;
                        error -= dx;
                    }
                }
            }
            else
            {
                int error = -dy / 2; // between pi/2 and pi/4 or between -pi/4 and -pi/2 (excluding)
                for (; y1 != y2; y1 += yinc)
                {
                    DrawPixel(color, x1, y1);
                    error += dx;
                    if (error >= 0)
                    {
                        x1    += xinc;
                        error -= dy;
                    }
                }
            }
        }
 /// <summary>
 /// Convert the given integer Cartesian coordinate to a polar coordinate.
 /// </summary>
 /// <param name="p">The integer Cartesian coordinate to convert.</param>
 /// <param name="radiusSqr">Returns the square of the radius, as an integer. I.e. the distance from the pole, squared.</param>
 /// <param name="azimuth">Returns the azimuth; the anticlockwise angle from the polar axis.</param>
 /// <remarks>
 /// The radius coordinate is returned as the *square* of the radius. This is because normally we want to compare the radius
 /// with some threshold, and it's faster to avoid a square root operation to calculate the radius, and instead to compare
 /// squared radii.
 ///
 /// By convention the polar axis is horizontal and to the right, and a positive azimuth represents an anticlockwise
 /// rotation. Therefore an azimuth of zero degrees represents due east (note. this same angle is never represented by
 /// +360 degrees), and an angle of +90 degrees represents due north.
 /// </remarks>
 private static void CartesianToPolar(Int32Point p, out int radiusSqr, out float azimuth)
 {
     radiusSqr = (p.X * p.X) + (p.Y * p.Y);
     azimuth   = __atan2Lookup[p.Y + __atan2LookupOffset, p.X + __atan2LookupOffset];
     if (azimuth < 0f)
     {
         azimuth += 2f * MathF.PI;
     }
 }
Пример #19
0
        internal Arc(Int32Point start, Int32Point end, Int32Point center, _DrawingPen pen)
        {
            Start  = start;
            End    = end;
            Center = center;
            Radius = (Start - Center).Length;
            var _bounds = GeometryHelper.CalcBounds(center, start, end, Radius, pen.Thickness);

            _property = new PrimitiveProperty(pen, _bounds);
        }
Пример #20
0
 public bool HitTest(Int32Point p)
 {
     foreach (var innerLine in _innerLines)
     {
         if (innerLine.HitTest(p))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #21
0
 internal bool HitTest(Int32Point p)
 {
     foreach (var primitive in _context.Primitives)
     {
         if (primitive.HitTest(p))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #22
0
        internal Line(Int32Point start, Int32Point end, _DrawingPen pen)
        {
            Start = start;
            End   = end;
            Len   = (Start - End).Length;
            GeometryHelper.CalcLineABC(Start, End, out A, out B, out C);
            Arg = (long)Math.Sqrt((long)A * A + (long)B * B);
            var _bounds = GeometryHelper.CalcBounds(pen.Thickness, start, end);

            _property = new PrimitiveProperty(pen, _bounds);
        }
Пример #23
0
    public override bool Equals(object obj)
    {
        if (obj is Int32Point)
        {
            Int32Point otherPoint = (Int32Point)obj;

            return(this.X == otherPoint.X && this.Y == otherPoint.Y);
        }

        return(false);
    }
Пример #24
0
    public bool ContainsTile(GameObject tileGameObject)
    {
        if (tileGameObject != null)
        {
            Int32Point tilePosition = GetTilePosition(tileGameObject);

            return(tilePosition.X != -1 && tilePosition.Y != -1);
        }

        return(false);
    }
Пример #25
0
    public void MoveAgent()
    {
        var world = new PreyCaptureWorld(4, 1f, 4f, 100);
        var agent = new MockPreyCaptureAgent();

        // Agent moving north test.
        {
            world.InitPositions();
            Int32Point posBefore = world.AgentPosition;
            var        outputs   = agent.Outputs.Span;
            outputs.Clear();
            outputs[0] = 1.0;
            world.MoveAgent(agent);
            Int32Point posDelta = world.AgentPosition - posBefore;
            Assert.Equal(new Int32Point(0, 1), posDelta);
        }

        // Agent moving east test.
        {
            world.InitPositions();
            Int32Point posBefore = world.AgentPosition;
            var        outputs   = agent.Outputs.Span;
            outputs.Clear();
            outputs[1] = 1.0;
            world.MoveAgent(agent);
            Int32Point posDelta = world.AgentPosition - posBefore;
            Assert.Equal(new Int32Point(1, 0), posDelta);
        }

        // Agent moving south test.
        {
            world.InitPositions();
            Int32Point posBefore = world.AgentPosition;
            var        outputs   = agent.Outputs.Span;
            outputs.Clear();
            outputs[2] = 1.0;
            world.MoveAgent(agent);
            Int32Point posDelta = world.AgentPosition - posBefore;
            Assert.Equal(new Int32Point(0, -1), posDelta);
        }

        // Agent moving west test.
        {
            world.InitPositions();
            Int32Point posBefore = world.AgentPosition;
            var        outputs   = agent.Outputs.Span;
            outputs.Clear();
            outputs[3] = 1.0;
            world.MoveAgent(agent);
            Int32Point posDelta = world.AgentPosition - posBefore;
            Assert.Equal(new Int32Point(-1, 0), posDelta);
        }
    }
Пример #26
0
            public bool Equals(Int32Point obj)
            {
                if (!obj.X.Equals(this.X))
                {
                    return(false);
                }
                if (!obj.Y.Equals(this.Y))
                {
                    return(false);
                }

                return(true);
            }
Пример #27
0
 public override bool Equals(object o)
 {
     // Check for null and compare run-time types.
     if ((o == null) || !o.GetType().Equals(o.GetType()))
     {
         return(false);
     }
     else
     {
         Int32Point p = (Int32Point)o;
         return((X == p.X) && (Y == p.Y));
     }
 }
Пример #28
0
        public bool HitTest(Int32Point p)
        {
            var len = (p - Center).Length;

            if (_fillColor == null)
            {
                return(Math.Abs(len - Radius) <= _property.Pen.Thickness + VisualHelper.HitTestThickness);
            }
            else
            {
                return(len < Radius + _property.Pen.Thickness + VisualHelper.HitTestThickness);
            }
        }
Пример #29
0
        public bool HitTest(Int32Point p)
        {
            var len1 = (p - FocusP1).Length;
            var len2 = (p - FocusP2).Length;

            if (_fillColor == null)
            {
                return(Math.Abs(len1 + len2 - A_2) <= _property.Pen.Thickness + VisualHelper.HitTestThickness);
            }
            else
            {
                return(len1 + len2 <= A_2 + _property.Pen.Thickness + VisualHelper.HitTestThickness);
            }
        }
Пример #30
0
 public bool RemoveTile(GameObject tileGameObject)
 {
     if (tileGameObject != null && layerArray != null)
     {
         if (ContainsTile(tileGameObject))
         {
             Int32Point tilePosition = GetTilePosition(tileGameObject);
             layerArray [tilePosition.X, tilePosition.Y] = null;
             MonoBehaviour.Destroy(tileGameObject);
             return(true);
         }
     }
     return(false);
 }