예제 #1
0
        private Polygon GetCollisionBox(PointF center, SizeF offset, SizeF size, float angle)
        {
            var xPlus = Config.Envelope.MinX / SphericalMercator.Resolution(Config.ZoomLevel);
            var yPlus = -Config.Envelope.MaxY / SphericalMercator.Resolution(Config.ZoomLevel);

            var halfWidth  = size.Width * 0.5f;
            var halfHeight = size.Height * 0.5f;

            var rotation = new Matrix();

            rotation.RotateAt(angle, center);

            var points = new[]
            {
                new PointF(center.X + offset.Width + halfWidth, center.Y + offset.Height + halfHeight),
                new PointF(center.X + offset.Width - halfWidth, center.Y + offset.Height + halfHeight),
                new PointF(center.X + offset.Width - halfWidth, center.Y + offset.Height - halfHeight),
                new PointF(center.X + offset.Width + halfWidth, center.Y + offset.Height - halfHeight)
            };

            rotation.TransformPoints(points);

            var poly = new Polygon(new LinearRing(new[]
            {
                new Coordinate(xPlus + points[0].X, yPlus + points[0].Y),
                new Coordinate(xPlus + points[1].X, yPlus + points[1].Y),
                new Coordinate(xPlus + points[2].X, yPlus + points[2].Y),
                new Coordinate(xPlus + points[3].X, yPlus + points[3].Y),
                new Coordinate(xPlus + points[0].X, yPlus + points[0].Y)
            }));

            return(poly);
        }
예제 #2
0
        internal PointF[] Project(Coordinate[] coords)
        {
            //TODO: Could consider simplifying https://github.com/mourner/simplify-js
            //TODO: Clip polygons to map edge?

            var spanX = Config.Envelope.MaxX - Config.Envelope.MinX;
            var spanY = Config.Envelope.MaxY - Config.Envelope.MinY;
            var reso  = SphericalMercator.Resolution(Config.ZoomLevel);

            var res = new PointF[coords.Length];

            for (var i = 0; i < coords.Length; i++)
            {
                var c = coords[i];
                res[i] = new PointF(
                    (float)((c.X - Config.Envelope.MinX) * SphericalMercator.TileSize / spanX),
                    (float)((c.Y - Config.Envelope.MaxY) * SphericalMercator.TileSize / -spanY)
                    );
            }
            return(res);
        }