public WsSphere()
 {
     this.header = new Header();
     this.point  = new Point32();
     this.ri     = 0.0f;
     this.poses  = new Pose[0];
 }
 public WsSphere(Header header, Point32 point, float ri, Pose[] poses)
 {
     this.header = header;
     this.point  = point;
     this.ri     = ri;
     this.poses  = poses;
 }
Example #3
0
        public override byte[] Serialize(bool partofsomethingelse)
        {
            int  currentIndex = 0, length = 0;
            bool hasmetacomponents = false;

            byte[]        thischunk, scratch1, scratch2;
            List <byte[]> pieces = new List <byte[]>();
            GCHandle      h;

            //header
            if (header == null)
            {
                header = new Header();
            }
            pieces.Add(header.Serialize(true));
            //points
            hasmetacomponents |= true;
            if (points == null)
            {
                points = new Point32[0];
            }
            pieces.Add(BitConverter.GetBytes(points.Length));
            for (int i = 0; i < points.Length; i++)
            {
                //points[i]
                if (points[i] == null)
                {
                    points[i] = new Point32();
                }
                pieces.Add(points[i].Serialize(true));
            }
            //channels
            hasmetacomponents |= true;
            if (channels == null)
            {
                channels = new Messages.sensor_msgs.ChannelFloat32[0];
            }
            pieces.Add(BitConverter.GetBytes(channels.Length));
            for (int i = 0; i < channels.Length; i++)
            {
                //channels[i]
                if (channels[i] == null)
                {
                    channels[i] = new Messages.sensor_msgs.ChannelFloat32();
                }
                pieces.Add(channels[i].Serialize(true));
            }
            //combine every array in pieces into one array and return it
            int __a_b__f = pieces.Sum((__a_b__c) => __a_b__c.Length);
            int __a_b__e = 0;

            byte[] __a_b__d = new byte[__a_b__f];
            foreach (var __p__ in pieces)
            {
                Array.Copy(__p__, 0, __a_b__d, __a_b__e, __p__.Length);
                __a_b__e += __p__.Length;
            }
            return(__a_b__d);
        }
Example #4
0
        public static bool Contains(this Circle32 c, Point32 point)
        {
            var delta           = point - c.Center;
            var radiusSquared   = c.Radius * c.Radius;
            var distanceSquared = delta.LengthSquared();

            return(distanceSquared <= radiusSquared);
        }
Example #5
0
        public Quadrilateral <Vector2> GetCoordinates(Point32 sheetSize)
        {
            var width  = (float)sheetSize.X;
            var height = (float)sheetSize.Y;

            return(Quadrilateral.Create(
                       new Vector2(x0 / width, y0 / height),
                       new Vector2(x1 / width, y1 / height)));
        }
Example #6
0
 // IRosClassInterface Implementation
 public void FromJSON(JSONNode msg)
 {
     points = new List<Point32>();
     foreach (var t in msg["points"].Children)
     {
         Point32 temp = new Point32();
         temp.FromJSON(t);
         points.Add(temp);
     }
 }
Example #7
0
            public Polygon(JSONNode msg)
            {
                JSONArray      points = (JSONArray)msg["points"];
                Point32        element;
                List <Point32> list = new List <Point32> ();

                for (int i = 0; i < points.Count; i++)
                {
                    element = new Point32(points[i]);
                    list.Add(element);
                }
                _points = list;
            }
Example #8
0
        public override void Deserialize(byte[] SERIALIZEDSTUFF, ref int currentIndex)
        {
            int    arraylength       = -1;
            bool   hasmetacomponents = false;
            object __thing;
            int    piecesize = 0;

            byte[] thischunk, scratch1, scratch2;
            IntPtr h;

            //header
            header = new Header(SERIALIZEDSTUFF, ref currentIndex);
            //points
            hasmetacomponents |= true;
            arraylength        = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex      += Marshal.SizeOf(typeof(System.Int32));
            if (points == null)
            {
                points = new Point32[arraylength];
            }
            else
            {
                Array.Resize(ref points, arraylength);
            }
            for (int i = 0; i < points.Length; i++)
            {
                //points[i]
                points[i] = new Point32(SERIALIZEDSTUFF, ref currentIndex);
            }
            //channels
            hasmetacomponents |= true;
            arraylength        = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex      += Marshal.SizeOf(typeof(System.Int32));
            if (channels == null)
            {
                channels = new Messages.sensor_msgs.ChannelFloat32[arraylength];
            }
            else
            {
                Array.Resize(ref channels, arraylength);
            }
            for (int i = 0; i < channels.Length; i++)
            {
                //channels[i]
                channels[i] = new Messages.sensor_msgs.ChannelFloat32(SERIALIZEDSTUFF, ref currentIndex);
            }
        }
Example #9
0
        public override void Randomize()
        {
            int    arraylength = -1;
            Random rand        = new Random();
            int    strlength;

            byte[] strbuf, myByte;

            //header
            header = new Header();
            header.Randomize();
            //points
            arraylength = rand.Next(10);
            if (points == null)
            {
                points = new Point32[arraylength];
            }
            else
            {
                Array.Resize(ref points, arraylength);
            }
            for (int i = 0; i < points.Length; i++)
            {
                //points[i]
                points[i] = new Point32();
                points[i].Randomize();
            }
            //channels
            arraylength = rand.Next(10);
            if (channels == null)
            {
                channels = new Messages.sensor_msgs.ChannelFloat32[arraylength];
            }
            else
            {
                Array.Resize(ref channels, arraylength);
            }
            for (int i = 0; i < channels.Length; i++)
            {
                //channels[i]
                channels[i] = new Messages.sensor_msgs.ChannelFloat32();
                channels[i].Randomize();
            }
        }
 public OrientedBoundingBox(Pose pose, Point32 extents)
 {
     this.pose    = pose;
     this.extents = extents;
 }
 public OrientedBoundingBox()
 {
     this.pose    = new Pose();
     this.extents = new Point32();
 }
Example #12
0
        static void RandomizeMaze(Maze maze, Random random)
        {
            maze.SetAllWalls(true);
            var visited = new BitArray(maze.Width * maze.Height);

            int VisitedIndex(int x, int y) => y * maze.Width + x;
            bool WasVisited(int x, int y) => visited[VisitedIndex(x, y)];
            void Visit(int x, int y) => visited[VisitedIndex(x, y)] = true;

            var trail   = new Stack <(int x, int y)>();
            var lastX   = maze.Width - 1;
            var lastY   = maze.Height - 1;
            var randomX = random.Next(maze.Width);
            var randomY = random.Next(maze.Height);

            trail.Push((randomX, randomY));
            Visit(randomX, randomY);

            while (trail.TryPop(out var position))
            {
                var  nextPosition = position;
                var  direction    = random.Next(4);
                bool proceed      = false;

                for (int i = 0; !proceed && i < 4; ++i)
                {
                    direction = (direction + i) & 3;
                    switch (direction)
                    {
                    case 0:
                        if (0 < position.x && !WasVisited(position.x - 1, position.y))
                        {
                            --nextPosition.x;
                            maze.SetWallLeft(position.x, position.y, false);
                            proceed = true;
                        }
                        break;

                    case 1:
                        if (position.x < lastX && !WasVisited(position.x + 1, position.y))
                        {
                            ++nextPosition.x;
                            maze.SetWallRight(position.x, position.y, false);
                            proceed = true;
                        }
                        break;

                    case 2:
                        if (0 < position.y && !WasVisited(position.x, position.y - 1))
                        {
                            --nextPosition.y;
                            maze.SetWallUp(position.x, position.y, false);
                            proceed = true;
                        }
                        break;

                    case 3:
                        if (position.y < lastY && !WasVisited(position.x, position.y + 1))
                        {
                            ++nextPosition.y;
                            maze.SetWallDown(position.x, position.y, false);
                            proceed = true;
                        }
                        break;
                    }
                }

                if (proceed)
                {
                    trail.Push(position);
                    trail.Push(nextPosition);
                    Visit(nextPosition.x, nextPosition.y);
                }
            }

            for (int i = 0; i < 256; ++i)
            {
                var p = new Point32(
                    random.Next(1, maze.Width - 1),
                    random.Next(1, maze.Height - 1));
                var d = (MazeDirection)random.Next(4);
                maze.SetWall(p, d, false);
            }
        }
Example #13
0
        static void CreateSheetsFromFolder(
            ILogger logger,
            ISdl2 sdl,
            IStb stb,
            Point32 sheetSize,
            string inputFolder,
            string outputFolder)
        {
            var surfaces      = new List <IntPtr>();
            var nameBySurface = new Dictionary <IntPtr, string>();
            var folders       = new Stack <string>();

            folders.Push(inputFolder);

            while (folders.TryPop(out var folder))
            {
                logger.LogDebug("Processing folder {0}", folder);

                foreach (var innerFolder in Directory.EnumerateDirectories(folder))
                {
                    folders.Push(innerFolder);
                }

                foreach (var pngFile in Directory.EnumerateFiles(folder, "*.png"))
                {
                    logger.LogDebug("Loading {0}", pngFile);
                    var pngBytes   = File.ReadAllBytes(pngFile);
                    var pixelBytes = stb.StbiLoadFromMemory(
                        pngBytes[0],
                        pngBytes.Length,
                        out var width,
                        out var height,
                        out var comp,
                        4);

                    if (pixelBytes.IsInvalid())
                    {
                        throw new Exception("Unable to load PNG.");
                    }

                    var surface = sdl.CreateRGBSurfaceFrom(
                        pixelBytes,
                        width,
                        height,
                        32,
                        4 * width,
                        Platform.Rmask,
                        Platform.Gmask,
                        Platform.Bmask,
                        Platform.Amask);

                    if (surface.IsInvalid())
                    {
                        stb.StbiImageFree(pixelBytes);
                        throw new SdlException("Unable to create surface: " + sdl.GetError());
                    }

                    surfaces.Add(surface);
                    nameBySurface.Add(surface, Path.GetFileNameWithoutExtension(pngFile));
                }
            }

            surfaces.Sort(
                (a, b) =>
            {
                var viewA = new SurfaceView(a);
                var viewB = new SurfaceView(b);
                var areaA = viewA.Width * viewA.Height;
                var areaB = viewB.Width * viewB.Height;
                return(-areaA.CompareTo(areaB));    // Sort descending!
            });

            var infoPath = Path.Combine(outputFolder, "info.json");
            var options  = new JsonWriterOptions
            {
                Indented       = true,
                SkipValidation = true
            };

            using (var builder = new SheetImageBuilder(stb, sdl, sheetSize))
                using (var fileStream = File.Create(infoPath))
                    using (var writer = new Utf8JsonWriter(fileStream, options))
                    {
                        writer.WriteStartObject();
                        writer.WriteNumber("width", sheetSize.X);
                        writer.WriteNumber("height", sheetSize.Y);
                        writer.WritePropertyName("sprites");
                        writer.WriteStartArray();
                        foreach (var surface in surfaces)
                        {
                            var position = builder.Add(surface);
                            writer.WriteStartObject();
                            writer.WriteString("name", nameBySurface[surface]);
                            writer.WriteNumber("sheetIndex", position.SheetIndex);
                            writer.WriteNumber("x", position.Rectangle.Position.X);
                            writer.WriteNumber("y", position.Rectangle.Position.Y);
                            writer.WriteNumber("width", position.Rectangle.Size.X);
                            writer.WriteNumber("height", position.Rectangle.Size.Y);
                            writer.WriteEndObject();
                            writer.Flush();
                        }
                        writer.WriteEndArray();
                        writer.WriteEndObject();
                        builder.SaveImages(outputFolder);
                    }

            foreach (var surface in surfaces)
            {
                var view = new SurfaceView(surface);
                stb.StbiImageFree(view.Pixels);
                sdl.FreeSurface(surface);
            }
        }
Example #14
0
 public MazeEdge(Point32 destination, int distance)
 {
     Destination = destination;
     Distance    = distance;
 }
        private void WorldCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            var here = e.GetPosition(worldCanvas);

            if (_panStart.HasValue)
            {
                var diff        = here - _panStart.Value;
                var destination = diff / _mapScaleFactor + _mapPosition;
                _mapTranslation.X = destination.X;
                _mapTranslation.Y = destination.Y;
            }
            else if (_world != null)
            {
                var mapCoordinates  = (Vector)here / _mapScaleFactor - (Vector)_mapPosition;
                var tileCoordinates = new Point32((int)mapCoordinates.X, (int)mapCoordinates.Y);

                if (0 <= tileCoordinates.X &&
                    tileCoordinates.X < _world.WorldWidthInTiles &&
                    0 <= tileCoordinates.Y &&
                    tileCoordinates.Y < _world.WorldHeightInTiles)
                {
                    var tileText = "no tile";
                    var tile     = _world.GetTile(tileCoordinates.X, tileCoordinates.Y);

                    if (tile.IsActive || tile.HasActuator)
                    {
                        var tileInfo = _worldInfo.FindTileInfo(tile.TileType, tile.TextureU, tile.TextureV);

                        if (tileInfo != null)
                        {
                            tileText = tileInfo.Name;
                        }
                    }

                    var liquidText = "no liquid";
                    if (tile.HasLiquid)
                    {
                        if (tile.HasLava)
                        {
                            liquidText = "Lava";
                        }
                        else if (tile.HasHoney)
                        {
                            liquidText = "Honey";
                        }
                        else
                        {
                            liquidText = "Water";
                        }
                    }

                    var wallText = "no wall";
                    if (tile.HasWall && _worldInfo.WallInfoById.TryGetValue(tile.WallType, out var wallInfo))
                    {
                        wallText = wallInfo.Name;
                    }

                    var gps   = _world.GetGpsPosition(tileCoordinates);
                    var xText = gps.X < 0 ? $"{-gps.X} feet west" : $"{gps.X} feet east";
                    var yText = gps.Y < 0 ? $"{-gps.Y} feet above" : $"{gps.Y} feet below";
                    statusBarText.Text = $"{tileCoordinates} ({xText} {yText}) {tileText} - {liquidText} - {wallText}";
                }
            }
        }