From 7cf3c89b671b6d9ced53ea462a25dab0f9746257 Mon Sep 17 00:00:00 2001 From: brnkhy Date: Wed, 29 Mar 2017 21:04:42 +0300 Subject: [PATCH 1/9] implement Vector2d, Vector3d, Mathd and RectD classes switch to double based structs for lat/lng/meter values --- .../Editor/GeocodeAttributeSearchWindow.cs | 2 +- .../Unity/MeshGeneration/Data/MeshData.cs | 3 +- .../Unity/MeshGeneration/Data/UnityTile.cs | 3 +- .../Factories/DirectionsFactory.cs | 4 +- .../Factories/TerrainFactory.cs | 34 +- .../LayerVisualizers/PoiVisualizer.cs | 10 +- .../LayerVisualizers/VectorLayerVisualizer.cs | 4 +- .../Unity/MeshGeneration/MapController.cs | 15 +- .../Modifiers/MeshModifiers/UvModifier.cs | 4 +- .../Core/Unity/Utilities/Conversions.cs | 78 ++-- .../Mapbox/Core/Unity/Utilities/Vector2d.meta | 9 + .../Core/Unity/Utilities/Vector2d/Mathd.cs | 378 ++++++++++++++++++ .../Unity/Utilities/Vector2d/Mathd.cs.meta | 12 + .../Core/Unity/Utilities/Vector2d/RectD.cs | 27 ++ .../Unity/Utilities/Vector2d/RectD.cs.meta | 12 + .../Core/Unity/Utilities/Vector2d/Vector2d.cs | 303 ++++++++++++++ .../Unity/Utilities/Vector2d/Vector2d.cs.meta | 12 + .../Core/Unity/Utilities/Vector2d/Vector3d.cs | Bin 0 -> 28704 bytes .../Unity/Utilities/Vector2d/Vector3d.cs.meta | 12 + .../Core/Unity/Utilities/VectorExtensions.cs | 24 +- .../Drive/Direction/DirectionsHelper.cs | 4 +- .../Factories/MeshFactory.asset | 1 + .../Playground/Scripts/DirectionsExample.cs | 4 +- .../Playground/Scripts/RasterTileExample.cs | 6 +- .../Examples/Voxels/Scripts/VoxelTile.cs | 12 +- .../Scripts/ForwardGeocodeUserInput.cs | 4 +- .../Scripts/ReverseGeocodeUserInput.cs | 6 +- .../Examples/_resources/Scripts/Slippy.cs | 4 +- sdkproject/Assets/StreamingAssets.meta | 4 +- .../ProjectSettings/GraphicsSettings.asset | 24 +- 30 files changed, 902 insertions(+), 113 deletions(-) create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d.meta create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Mathd.cs create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Mathd.cs.meta create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/RectD.cs create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/RectD.cs.meta create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector2d.cs create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector2d.cs.meta create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector3d.cs create mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector3d.cs.meta diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Editor/GeocodeAttributeSearchWindow.cs b/sdkproject/Assets/Mapbox/Core/Unity/Editor/GeocodeAttributeSearchWindow.cs index 4a898476d..b0cbbdcc6 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Editor/GeocodeAttributeSearchWindow.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/Editor/GeocodeAttributeSearchWindow.cs @@ -81,7 +81,7 @@ void OnGUI() for (int i = 0; i < _features.Count; i++) { Feature feature = _features[i]; - string coordinates = feature.Center.Latitude + ", " + feature.Center.Longitude; + string coordinates = feature.Center.x + ", " + feature.Center.y; string buttonContent = feature.Address + " (" + coordinates + ")"; if (GUILayout.Button(buttonContent)) diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Data/MeshData.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Data/MeshData.cs index 9e8b631f2..e274c7517 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Data/MeshData.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Data/MeshData.cs @@ -2,11 +2,12 @@ namespace Mapbox.Unity.MeshGeneration.Data { using System.Collections.Generic; using UnityEngine; + using Utils; public class MeshData { public Vector2 MercatorCenter { get; set; } - public Rect TileRect { get; set; } + public RectD TileRect { get; set; } public List Vertices { get; set; } public List> Triangles { get; set; } public List> UV { get; set; } diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Data/UnityTile.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Data/UnityTile.cs index 1a69ec23f..56b085688 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Data/UnityTile.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Data/UnityTile.cs @@ -5,6 +5,7 @@ namespace Mapbox.Unity.MeshGeneration.Data using UnityEngine; using Mapbox.Unity.MeshGeneration.Enums; using Mapbox.Unity.Utilities; + using Utils; [RequireComponent(typeof(MeshRenderer), typeof(MeshFilter))] public class UnityTile : MonoBehaviour, INotifyPropertyChanged @@ -52,7 +53,7 @@ public string VectorData public Vector2 TileCoordinate { get; set; } public int Zoom { get; set; } - public Rect Rect { get; set; } + public RectD Rect { get; set; } public float RelativeScale { get; set; } public float QueryHeightData(float x, float y) diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/DirectionsFactory.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/DirectionsFactory.cs index 16cc05f69..facc549f5 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/DirectionsFactory.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/DirectionsFactory.cs @@ -24,7 +24,7 @@ public override void Initialize(MonoBehaviour mb, IFileSource fileSource) _directions = new Directions(fileSource); } - public void Query(List waypoints) + public void Query(List waypoints) { var _directionResource = new DirectionResource(waypoints.ToArray(), RoutingProfile.Driving); _directionResource.Steps = true; @@ -39,7 +39,7 @@ void HandleDirectionsResponse(DirectionsResponse response) { foreach (var step in leg.Steps) { - meshData.Vertices.Add(Conversions.GeoToWorldPosition(step.Maneuver.Location.Latitude, step.Maneuver.Location.Longitude, MapController.ReferenceTileRect.center, MapController.WorldScaleFactor).ToVector3xz()); + meshData.Vertices.Add(Conversions.GeoToWorldPosition(step.Maneuver.Location.x, step.Maneuver.Location.y, MapController.ReferenceTileRect.Center, MapController.WorldScaleFactor).ToVector3xz()); } } diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/TerrainFactory.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/TerrainFactory.cs index f7c6b9e88..fcb26c321 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/TerrainFactory.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/TerrainFactory.cs @@ -7,6 +7,7 @@ namespace Mapbox.Unity.MeshGeneration.Factories using Mapbox.Unity.MeshGeneration.Data; using Mapbox.Platform; using Mapbox.Unity.Utilities; + using Utils; [CreateAssetMenu(menuName = "Mapbox/Factories/Terrain Factory")] public class TerrainFactory : Factory @@ -83,22 +84,22 @@ private void CreateTerrain(UnityTile tile, Texture2D texture) { var go = tile.gameObject; var mesh = new Mesh(); - var verts = new List(); + var verts = new List(sampleCount* sampleCount); for (float x = 0; x < sampleCount; x++) { for (float y = 0; y < sampleCount; y++) { - var xx = Mathf.Lerp(tile.Rect.xMin, (tile.Rect.xMin + tile.Rect.size.x), + var xx = Mathd.Lerp(tile.Rect.Min.x, tile.Rect.Max.x, x / (sampleCount - 1)); - var yy = Mathf.Lerp(tile.Rect.yMin, (tile.Rect.yMin + tile.Rect.size.y), + var yy = Mathd.Lerp(tile.Rect.Min.y, tile.Rect.Max.y, y / (sampleCount - 1)); verts.Add(new Vector3( - (xx - tile.Rect.center.x), + (float)(xx - tile.Rect.Center.x), Conversions.GetRelativeHeightFromColor(texture.GetPixel((int)Mathf.Clamp((x / (sampleCount - 1) * 256), 0, 255), (int)Mathf.Clamp((256 - (y / (sampleCount - 1) * 256)), 0, 255)), tile.RelativeScale), - (yy - tile.Rect.center.y))); + (float)(yy - tile.Rect.Center.y))); } } @@ -106,7 +107,7 @@ private void CreateTerrain(UnityTile tile, Texture2D texture) //we can read these from a hardcoded dictionary as well //no need to calculate this every single time unless we need a really high range for sampleCount - var trilist = new List(); + var trilist = new List(sampleCount * sampleCount * 3); for (int y = 0; y < sampleCount - 1; y++) { for (int x = 0; x < sampleCount - 1; x++) @@ -122,7 +123,7 @@ private void CreateTerrain(UnityTile tile, Texture2D texture) } mesh.SetTriangles(trilist, 0); - var uvlist = new List(); + var uvlist = new List(sampleCount * sampleCount); var step = 1f / (sampleCount - 1); for (int i = 0; i < sampleCount; i++) { @@ -134,7 +135,8 @@ private void CreateTerrain(UnityTile tile, Texture2D texture) mesh.SetUVs(0, uvlist); mesh.RecalculateNormals(); go.GetComponent().sharedMesh = mesh; - go.AddComponent(); + + //go.AddComponent(); //go.layer = LayerMask.NameToLayer("terrain"); } @@ -204,10 +206,18 @@ private void CreateTileBase(UnityTile tile) var mesh = new Mesh(); var verts = new List(); - verts.Add((tile.Rect.min - tile.Rect.center).ToVector3xz()); - verts.Add(new Vector3(tile.Rect.xMax - tile.Rect.center.x, 0, tile.Rect.yMin - tile.Rect.center.y)); - verts.Add(new Vector3(tile.Rect.xMin - tile.Rect.center.x, 0, tile.Rect.yMax - tile.Rect.center.y)); - verts.Add((tile.Rect.max - tile.Rect.center).ToVector3xz()); + verts.Add((tile.Rect.Min - tile.Rect.Center).ToVector3xz()); + verts.Add( + new Vector3( + (float)(tile.Rect.Max.x - tile.Rect.Center.x), + 0, + (float)(tile.Rect.Min.y - tile.Rect.Center.y))); + verts.Add( + new Vector3( + (float)(tile.Rect.Min.x - tile.Rect.Center.x), + 0, + (float)(tile.Rect.Max.y - tile.Rect.Center.y))); + verts.Add((tile.Rect.Max - tile.Rect.Center).ToVector3xz()); mesh.SetVertices(verts); var trilist = new List() { 0, 1, 2, 1, 3, 2 }; diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/PoiVisualizer.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/PoiVisualizer.cs index 0e1e27c44..eb311104a 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/PoiVisualizer.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/PoiVisualizer.cs @@ -41,8 +41,8 @@ private void Build(VectorFeatureUnity feature, UnityTile tile, GameObject parent return; int selpos = feature.Points[0].Count / 2; - var met = Conversions.GeoToWorldPosition(feature.Points[0][selpos].Lat, feature.Points[0][selpos].Lng, tile.Rect.center).ToVector3xz(); - if (Math.Abs(met.x) > Math.Abs(tile.Rect.size.x) / 2 || Math.Abs(met.y) > Math.Abs(tile.Rect.size.y) / 2) + var met = Conversions.GeoToWorldPosition(feature.Points[0][selpos].Lat, feature.Points[0][selpos].Lng, tile.Rect.Center).ToVector3xz(); + if (Math.Abs(met.x) > Math.Abs(tile.Rect.Size.x) / 2 || Math.Abs(met.y) > Math.Abs(tile.Rect.Size.y) / 2) return; if (!feature.Properties.ContainsKey("name")) return; @@ -50,9 +50,9 @@ private void Build(VectorFeatureUnity feature, UnityTile tile, GameObject parent var go = Instantiate(PoiPrefab); go.name = _key + " " + feature.Data.Id.ToString(); - var rx = (met.x - tile.Rect.min.x) / tile.Rect.width; - var ry = 1 - (met.z - tile.Rect.min.y) / tile.Rect.height; - var h = tile.QueryHeightData(rx, ry); + var rx = (met.x - tile.Rect.Min.x) / tile.Rect.Size.x; + var ry = 1 - (met.z - tile.Rect.Min.y) / tile.Rect.Size.y; + var h = tile.QueryHeightData((float)rx, (float)ry); met.y += h; go.transform.position = met; go.transform.SetParent(parent.transform, false); diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/VectorLayerVisualizer.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/VectorLayerVisualizer.cs index 7444acae7..ea731c5dc 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/VectorLayerVisualizer.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/VectorLayerVisualizer.cs @@ -110,7 +110,7 @@ private void Build(VectorFeatureUnity feature, UnityTile tile, GameObject parent } //we'll run all visualizers on MeshData here - var list = geometry.Select(x => Conversions.GeoToWorldPosition(x.Lat, x.Lng, tile.Rect.center).ToVector3xz()).ToList(); + var list = geometry.Select(x => Conversions.GeoToWorldPosition(x.Lat, x.Lng, tile.Rect.Center).ToVector3xz()).ToList(); //long straight edges looks bad on bumpy terrain if (_subdivideLongEdges) @@ -143,7 +143,7 @@ private void Build(VectorFeatureUnity feature, UnityTile tile, GameObject parent //we may move this into height modifier in the future meshData.Vertices = list.Select(vertex => { - var h = tile.QueryHeightData((vertex.x + tile.Rect.size.x / 2) / tile.Rect.size.x, (tile.Rect.size.y - (vertex.z + tile.Rect.size.y / 2)) / tile.Rect.size.y); + var h = tile.QueryHeightData((float)((vertex.x + tile.Rect.Size.x / 2) / tile.Rect.Size.x), (float)((vertex.z + tile.Rect.Size.y / 2) / tile.Rect.Size.y)); vertex += new Vector3(0, h, 0); if (feature.Properties.ContainsKey("min_height")) diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/MapController.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/MapController.cs index 7403d8d6c..9a53ec215 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/MapController.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/MapController.cs @@ -6,11 +6,12 @@ namespace Mapbox.Unity.MeshGeneration using Mapbox.Unity; using Mapbox.Platform; using Mapbox.Unity.Utilities; + using Utils; public class MapController : MonoBehaviour { private IFileSource _fileSource; - public static Rect ReferenceTileRect { get; set; } + public static RectD ReferenceTileRect { get; set; } public static float WorldScaleFactor { get; set; } public MapVisualization MapVisualization; @@ -72,10 +73,10 @@ public void Execute(double lat, double lng, int zoom, Vector4 frame) _root = new GameObject("worldRoot"); - var v2 = Conversions.GeoToWorldPosition(lat, lng, new Vector2(0, 0)); + var v2 = Conversions.GeoToWorldPosition(lat, lng, new Vector2d(0, 0)); var tms = Conversions.MetersToTile(v2, zoom); ReferenceTileRect = Conversions.TileBounds(tms, zoom); - WorldScaleFactor = TileSize / ReferenceTileRect.width; + WorldScaleFactor = (float)(TileSize / ReferenceTileRect.Size.x); _root.transform.localScale = Vector3.one * WorldScaleFactor; for (int i = (int)(tms.x - frame.x); i <= (tms.x + frame.z); i++) @@ -88,7 +89,7 @@ public void Execute(double lat, double lng, int zoom, Vector4 frame) tile.RelativeScale = Conversions.GetTileScaleInMeters(0, Zoom) / Conversions.GetTileScaleInMeters((float)lat, Zoom); tile.TileCoordinate = new Vector2(i, j); tile.Rect = Conversions.TileBounds(tile.TileCoordinate, zoom); - tile.transform.position = new Vector3(tile.Rect.center.x - ReferenceTileRect.center.x, 0, tile.Rect.center.y - ReferenceTileRect.center.y); + tile.transform.position = new Vector3((float)(tile.Rect.Center.x - ReferenceTileRect.Center.x), 0, (float)(tile.Rect.Center.y - ReferenceTileRect.Center.y)); tile.transform.SetParent(_root.transform, false); MapVisualization.ShowTile(tile); } @@ -116,10 +117,10 @@ public void Request(Vector2 pos, int zoom) tile.TileCoordinate = new Vector2(pos.x, pos.y); tile.Rect = Conversions.TileBounds(tile.TileCoordinate, zoom); tile.RelativeScale = Conversions.GetTileScaleInMeters(0, Zoom) / - Conversions.GetTileScaleInMeters((float)Conversions.MetersToLatLon(tile.Rect.center).Latitude, Zoom); - tile.transform.localPosition = new Vector3(tile.Rect.center.x - ReferenceTileRect.center.x, + Conversions.GetTileScaleInMeters((float)Conversions.MetersToLatLon(tile.Rect.Center).x, Zoom); + tile.transform.localPosition = new Vector3((float)(tile.Rect.Center.x - ReferenceTileRect.Center.x), 0, - tile.Rect.center.y - ReferenceTileRect.center.y); + (float)(tile.Rect.Center.y - ReferenceTileRect.Center.y)); MapVisualization.ShowTile(tile); } } diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Modifiers/MeshModifiers/UvModifier.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Modifiers/MeshModifiers/UvModifier.cs index 6c0d381d7..e7a734f07 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Modifiers/MeshModifiers/UvModifier.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Modifiers/MeshModifiers/UvModifier.cs @@ -17,8 +17,8 @@ public override void Run(VectorFeatureUnity feature, MeshData md) { if (UseSatelliteRoof) { - var fromBottomLeft = new Vector2((c.x + md.TileRect.width / 2) / md.TileRect.width, - ((c.z + md.TileRect.width / 2) / md.TileRect.width)); + var fromBottomLeft = new Vector2((float)((c.x + md.TileRect.Size.x / 2) / md.TileRect.Size.x), + (float)((c.z + md.TileRect.Size.x / 2) / md.TileRect.Size.x)); uv.Add(fromBottomLeft); } else diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Conversions.cs b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Conversions.cs index 8bdc879af..7f24816d1 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Conversions.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Conversions.cs @@ -21,14 +21,14 @@ public static class Conversions private const double OriginShift = 2 * Math.PI * EarthRadius / 2; /// - /// Converts struct, WGS84 + /// Converts struct, WGS84 /// lat/lon to Spherical Mercator EPSG:900913 xy meters. /// - /// The . - /// A of coordinates in meters. - private static Vector2 LatLonToMeters(GeoCoordinate v) + /// The . + /// A of coordinates in meters. + private static Vector2d LatLonToMeters(Vector2d v) { - return LatLonToMeters(v.Latitude, v.Longitude); + return LatLonToMeters(v.x, v.y); } /// @@ -37,46 +37,46 @@ private static Vector2 LatLonToMeters(GeoCoordinate v) /// /// The latitude. /// The longitude. - /// A of xy meters. - private static Vector2 LatLonToMeters(double lat, double lon) + /// A of xy meters. + private static Vector2d LatLonToMeters(double lat, double lon) { var posx = lon * OriginShift / 180; var posy = Math.Log(Math.Tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180); posy = posy * OriginShift / 180; //losing precision by converting to float here if lat/lng is too high/low. //prefer using GeoToWorldPosition - return new Vector2((float)posx, (float)posy); + return new Vector2d((float)posx, (float)posy); } - public static Vector2 GeoToWorldPosition(double lat, double lon, Vector2 refPoint, float scale = 1) + public static Vector2d GeoToWorldPosition(double lat, double lon, Vector2d refPoint, float scale = 1) { var posx = lon * OriginShift / 180; var posy = Math.Log(Math.Tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180); posy = posy * OriginShift / 180; - return new Vector2((float)((posx - refPoint.x) * scale), (float)((posy - refPoint.y) * scale)); + return new Vector2d((posx - refPoint.x) * scale, (posy - refPoint.y) * scale); } /// /// Converts Spherical Mercator EPSG:900913 in xy meters to WGS84 lat/lon. /// Inverse of LatLonToMeters. /// - /// A of coordinates in meters. - /// The in lat/lon. - public static GeoCoordinate MetersToLatLon(Vector2 m) + /// A of coordinates in meters. + /// The in lat/lon. + public static Vector2d MetersToLatLon(Vector2d m) { var vx = (m.x / OriginShift) * 180; var vy = (m.y / OriginShift) * 180; vy = 180 / Math.PI * (2 * Math.Atan(Math.Exp(vy * Math.PI / 180)) - Math.PI / 2); - return new GeoCoordinate(vy, vx); + return new Vector2d(vy, vx); } /// /// Gets the xy tile ID from Spherical Mercator EPSG:900913 xy coords. /// - /// XY coords in meters. + /// XY coords in meters. /// Zoom level. - /// A xy tile ID. - public static Vector2 MetersToTile(Vector2 m, int zoom) + /// A xy tile ID. + public static Vector2 MetersToTile(Vector2d m, int zoom) { var p = MetersToPixels(m, zoom); return PixelsToTile(p); @@ -85,14 +85,14 @@ public static Vector2 MetersToTile(Vector2 m, int zoom) /// /// Gets the tile bounds in Spherical Mercator EPSG:900913 meters from an xy tile ID. /// - /// XY tile ID. + /// XY tile ID. /// Zoom level. /// A in meters. - public static Rect TileBounds(Vector2 t, int zoom) + public static RectD TileBounds(Vector2 tileCoordinate, int zoom) { - var min = PixelsToMeters(new Vector2(t.x * TileSize, t.y * TileSize), zoom); - var max = PixelsToMeters(new Vector2((t.x + 1) * TileSize, (t.y + 1) * TileSize), zoom); - return new Rect(min, max - min); + var min = PixelsToMeters(new Vector2d(tileCoordinate.x * TileSize, tileCoordinate.y * TileSize), zoom); + var max = PixelsToMeters(new Vector2d((tileCoordinate.x + 1) * TileSize, (tileCoordinate.y + 1) * TileSize), zoom); + return new RectD(min, max - min); } /// @@ -102,14 +102,14 @@ public static Rect TileBounds(Vector2 t, int zoom) /// The latitude. /// The longitude. /// Zoom level. - /// A xy tile ID. - public static Vector2 LatitudeLongitudeToTileId(float latitude, float longitude, int zoom) + /// A xy tile ID. + public static Vector2d LatitudeLongitudeToTileId(float latitude, float longitude, int zoom) { var x = (int)Math.Floor((longitude + 180.0) / 360.0 * Math.Pow(2.0, zoom)); var y = (int)Math.Floor((1.0 - Math.Log(Math.Tan(latitude * Math.PI / 180.0) + 1.0 / Math.Cos(latitude * Math.PI / 180.0)) / Math.PI) / 2.0 * Math.Pow(2.0, zoom)); - return new Vector2(x, y); + return new Vector2d(x, y); } /// @@ -142,17 +142,17 @@ public static double TileYToNWLatitude(int y, int zoom) } /// - /// Gets the of a tile. + /// Gets the of a tile. /// /// Tile X position. /// Tile Y position. /// Zoom level. - /// The of the tile. - public static GeoCoordinateBounds TileIdToBounds(int x, int y, int zoom) + /// The of the tile. + public static Vector2dBounds TileIdToBounds(int x, int y, int zoom) { - var sw = new GeoCoordinate(TileYToNWLatitude(y, zoom), TileXToNWLongitude(x + 1, zoom)); - var ne = new GeoCoordinate(TileYToNWLatitude(y + 1, zoom), TileXToNWLongitude(x, zoom)); - return new GeoCoordinateBounds(sw, ne); + var sw = new Vector2d(TileYToNWLatitude(y, zoom), TileXToNWLongitude(x + 1, zoom)); + var ne = new Vector2d(TileYToNWLatitude(y + 1, zoom), TileXToNWLongitude(x, zoom)); + return new Vector2dBounds(sw, ne); } /// @@ -161,12 +161,12 @@ public static GeoCoordinateBounds TileIdToBounds(int x, int y, int zoom) /// Tile X position. /// Tile Y position. /// Zoom level. - /// A of lat/lon coordinates. - public static Vector2 TileIdToCenterLatitudeLongitude(int x, int y, int zoom) + /// A of lat/lon coordinates. + public static Vector2d TileIdToCenterLatitudeLongitude(int x, int y, int zoom) { var bb = TileIdToBounds(x, y, zoom); var center = bb.Center; - return new Vector2((float)center.Latitude, (float)center.Longitude); + return new Vector2d((float)center.x, (float)center.y); } /// @@ -208,23 +208,23 @@ private static double Resolution(int zoom) return InitialResolution / Math.Pow(2, zoom); } - private static Vector2 PixelsToMeters(Vector2 p, int zoom) + private static Vector2d PixelsToMeters(Vector2d p, int zoom) { var res = Resolution(zoom); - var met = new Vector2(); + var met = new Vector2d(); met.x = (float)(p.x * res - OriginShift); met.y = (float)-(p.y * res - OriginShift); return met; } - private static Vector2 MetersToPixels(Vector2 m, int zoom) + private static Vector2d MetersToPixels(Vector2d m, int zoom) { var res = Resolution(zoom); - var pix = new Vector2((float)((m.x + OriginShift) / res), (float)((-m.y + OriginShift) / res)); + var pix = new Vector2d((float)((m.x + OriginShift) / res), (float)((-m.y + OriginShift) / res)); return pix; } - private static Vector2 PixelsToTile(Vector2 p) + private static Vector2 PixelsToTile(Vector2d p) { var t = new Vector2((int)Math.Ceiling(p.x / (double)TileSize) - 1, (int)Math.Ceiling(p.y / (double)TileSize) - 1); return t; diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d.meta b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d.meta new file mode 100644 index 000000000..895fd0154 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 5193dade1c52a2a4584edd672d0f199f +folderAsset: yes +timeCreated: 1490810641 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Mathd.cs b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Mathd.cs new file mode 100644 index 000000000..b5efc0988 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Mathd.cs @@ -0,0 +1,378 @@ +// Type: UnityEngine.Mathd +// Assembly: UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// Assembly location: C:\Program Files (x86)\Unity\Editor\Data\Managed\UnityEngine.dll +using System; +using System.Runtime.CompilerServices; +using UnityEngine; + +namespace Mapbox.Utils +{ + public struct Mathd { + public const double PI = 3.141593d; + public const double Infinity = double.PositiveInfinity; + public const double NegativeInfinity = double.NegativeInfinity; + public const double Deg2Rad = 0.01745329d; + public const double Rad2Deg = 57.29578d; + public const double Epsilon = 1.401298E-45d; + + public static double Sin(double d) { + return Math.Sin(d); + } + + public static double Cos(double d) { + return Math.Cos(d); + } + + public static double Tan(double d) { + return Math.Tan(d); + } + + public static double Asin(double d) { + return Math.Asin(d); + } + + public static double Acos(double d) { + return Math.Acos(d); + } + + public static double Atan(double d) { + return Math.Atan(d); + } + + public static double Atan2(double y, double x) { + return Math.Atan2(y, x); + } + + public static double Sqrt(double d) { + return Math.Sqrt(d); + } + + public static double Abs(double d) { + return Math.Abs(d); + } + + public static int Abs(int value) { + return Math.Abs(value); + } + + public static double Min(double a, double b) { + if (a < b) + return a; + else + return b; + } + + public static double Min(params double[] values) { + int length = values.Length; + if (length == 0) + return 0.0d; + double num = values[0]; + for (int index = 1; index < length; ++index) { + if (values[index] < num) + num = values[index]; + } + return num; + } + + public static int Min(int a, int b) { + if (a < b) + return a; + else + return b; + } + + public static int Min(params int[] values) { + int length = values.Length; + if (length == 0) + return 0; + int num = values[0]; + for (int index = 1; index < length; ++index) { + if (values[index] < num) + num = values[index]; + } + return num; + } + + public static double Max(double a, double b) { + if (a > b) + return a; + else + return b; + } + + public static double Max(params double[] values) { + int length = values.Length; + if (length == 0) + return 0d; + double num = values[0]; + for (int index = 1; index < length; ++index) { + if ((double)values[index] > (double)num) + num = values[index]; + } + return num; + } + + public static int Max(int a, int b) { + if (a > b) + return a; + else + return b; + } + + public static int Max(params int[] values) { + int length = values.Length; + if (length == 0) + return 0; + int num = values[0]; + for (int index = 1; index < length; ++index) { + if (values[index] > num) + num = values[index]; + } + return num; + } + + public static double Pow(double d, double p) { + return Math.Pow(d, p); + } + + public static double Exp(double power) { + return Math.Exp(power); + } + + public static double Log(double d, double p) { + return Math.Log(d, p); + } + + public static double Log(double d) { + return Math.Log(d); + } + + public static double Log10(double d) { + return Math.Log10(d); + } + + public static double Ceil(double d) { + return Math.Ceiling(d); + } + + public static double Floor(double d) { + return Math.Floor(d); + } + + public static double Round(double d) { + return Math.Round(d); + } + + public static int CeilToInt(double d) { + return (int)Math.Ceiling(d); + } + + public static int FloorToInt(double d) { + return (int)Math.Floor(d); + } + + public static int RoundToInt(double d) { + return (int)Math.Round(d); + } + + public static double Sign(double d) { + return d >= 0.0 ? 1d : -1d; + } + + public static double Clamp(double value, double min, double max) { + if (value < min) + value = min; + else if (value > max) + value = max; + return value; + } + + public static int Clamp(int value, int min, int max) { + if (value < min) + value = min; + else if (value > max) + value = max; + return value; + } + + public static double Clamp01(double value) { + if (value < 0.0) + return 0.0d; + if (value > 1.0) + return 1d; + else + return value; + } + + public static double Lerp(double from, double to, double t) { + return from + (to - from) * Mathd.Clamp01(t); + } + + public static double LerpAngle(double a, double b, double t) { + double num = Mathd.Repeat(b - a, 360d); + if (num > 180.0d) + num -= 360d; + return a + num * Mathd.Clamp01(t); + } + + public static double MoveTowards(double current, double target, double maxDelta) { + if (Mathd.Abs(target - current) <= maxDelta) + return target; + else + return current + Mathd.Sign(target - current) * maxDelta; + } + + public static double MoveTowardsAngle(double current, double target, double maxDelta) { + target = current + Mathd.DeltaAngle(current, target); + return Mathd.MoveTowards(current, target, maxDelta); + } + + public static double SmoothStep(double from, double to, double t) { + t = Mathd.Clamp01(t); + t = (-2.0 * t * t * t + 3.0 * t * t); + return to * t + from * (1.0 - t); + } + + public static double Gamma(double value, double absmax, double gamma) { + bool flag = false; + if (value < 0.0) + flag = true; + double num1 = Mathd.Abs(value); + if (num1 > absmax) { + if (flag) + return -num1; + else + return num1; + } else { + double num2 = Mathd.Pow(num1 / absmax, gamma) * absmax; + if (flag) + return -num2; + else + return num2; + } + } + + public static bool Approximately(double a, double b) { + return Mathd.Abs(b - a) < Mathd.Max(1E-06d * Mathd.Max(Mathd.Abs(a), Mathd.Abs(b)), 1.121039E-44d); + } + + public static double SmoothDamp(double current, double target, ref double currentVelocity, double smoothTime, double maxSpeed) { + double deltaTime = (double)Time.deltaTime; + return Mathd.SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime); + } + + public static double SmoothDamp(double current, double target, ref double currentVelocity, double smoothTime) { + double deltaTime = Time.deltaTime; + double maxSpeed = double.PositiveInfinity; + return Mathd.SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime); + } + + public static double SmoothDamp(double current, double target, ref double currentVelocity, double smoothTime, double maxSpeed, double deltaTime) { + smoothTime = Mathd.Max(0.0001d, smoothTime); + double num1 = 2d / smoothTime; + double num2 = num1 * deltaTime; + double num3 = (1.0d / (1.0d + num2 + 0.479999989271164d * num2 * num2 + 0.234999999403954d * num2 * num2 * num2)); + double num4 = current - target; + double num5 = target; + double max = maxSpeed * smoothTime; + double num6 = Mathd.Clamp(num4, -max, max); + target = current - num6; + double num7 = (currentVelocity + num1 * num6) * deltaTime; + currentVelocity = (currentVelocity - num1 * num7) * num3; + double num8 = target + (num6 + num7) * num3; + if (num5 - current > 0.0 == num8 > num5) { + num8 = num5; + currentVelocity = (num8 - num5) / deltaTime; + } + return num8; + } + + public static double SmoothDampAngle(double current, double target, ref double currentVelocity, double smoothTime, double maxSpeed) { + double deltaTime = (double)Time.deltaTime; + return Mathd.SmoothDampAngle(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime); + } + + public static double SmoothDampAngle(double current, double target, ref double currentVelocity, double smoothTime) { + double deltaTime = (double)Time.deltaTime; + double maxSpeed = double.PositiveInfinity; + return Mathd.SmoothDampAngle(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime); + } + + public static double SmoothDampAngle(double current, double target, ref double currentVelocity, double smoothTime, double maxSpeed, double deltaTime) { + target = current + Mathd.DeltaAngle(current, target); + return Mathd.SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime); + } + + public static double Repeat(double t, double length) { + return t - Mathd.Floor(t / length) * length; + } + + public static double PingPong(double t, double length) { + t = Mathd.Repeat(t, length * 2d); + return length - Mathd.Abs(t - length); + } + + public static double InverseLerp(double from, double to, double value) { + if (from < to) { + if (value < from) + return 0d; + if (value > to) + return 1d; + value -= from; + value /= to - from; + return value; + } else { + if (from <= to) + return 0d; + if (value < to) + return 1d; + if (value > from) + return 0d; + else + return (1.0d - (value - to) / (from - to)); + } + } + + public static double DeltaAngle(double current, double target) { + double num = Mathd.Repeat(target - current, 360d); + if (num > 180.0d) + num -= 360d; + return num; + } + + internal static bool LineIntersection(Vector2d p1, Vector2d p2, Vector2d p3, Vector2d p4, ref Vector2d result) { + double num1 = p2.x - p1.x; + double num2 = p2.y - p1.y; + double num3 = p4.x - p3.x; + double num4 = p4.y - p3.y; + double num5 = num1 * num4 - num2 * num3; + if (num5 == 0.0d) + return false; + double num6 = p3.x - p1.x; + double num7 = p3.y - p1.y; + double num8 = (num6 * num4 - num7 * num3) / num5; + result = new Vector2d(p1.x + num8 * num1, p1.y + num8 * num2); + return true; + } + + internal static bool LineSegmentIntersection(Vector2d p1, Vector2d p2, Vector2d p3, Vector2d p4, ref Vector2d result) { + double num1 = p2.x - p1.x; + double num2 = p2.y - p1.y; + double num3 = p4.x - p3.x; + double num4 = p4.y - p3.y; + double num5 = (num1 * num4 - num2 * num3); + if (num5 == 0.0d) + return false; + double num6 = p3.x - p1.x; + double num7 = p3.y - p1.y; + double num8 = (num6 * num4 - num7 * num3) / num5; + if (num8 < 0.0d || num8 > 1.0d) + return false; + double num9 = (num6 * num2 - num7 * num1) / num5; + if (num9 < 0.0d || num9 > 1.0d) + return false; + result = new Vector2d(p1.x + num8 * num1, p1.y + num8 * num2); + return true; + } + } +} diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Mathd.cs.meta b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Mathd.cs.meta new file mode 100644 index 000000000..d08216fde --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Mathd.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f126d867620a586468dcf8d3921a5b8e +timeCreated: 1490802250 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/RectD.cs b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/RectD.cs new file mode 100644 index 000000000..a58efcaf7 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/RectD.cs @@ -0,0 +1,27 @@ +using UnityEngine; + +namespace Mapbox.Utils +{ + public class RectD + { + public Vector2d Min { get; private set; } + public Vector2d Max { get; private set; } + //size is absolute width&height so Min+size != max + public Vector2d Size { get; private set; } + public Vector2d Center { get; private set; } + + public RectD(Vector2d min, Vector2d size) + { + Min = min; + Max = min + size; + Center = new Vector2d(Min.x + size.x / 2, Min.y + size.y / 2); + Size = new Vector2d(Mathd.Abs(size.x), Mathd.Abs(size.y)); + } + + public bool Contains(Vector2d point) + { + bool flag = Size.x < 0.0 && point.x <= Min.x && point.x > (Min.x + Size.x) || Size.x >= 0.0 && point.x >= Min.x && point.x < (Min.x + Size.x); + return flag && (Size.y < 0.0 && point.y <= Min.y && point.y > (Min.y + Size.y) || Size.y >= 0.0 && point.y >= Min.y && point.y < (Min.y + Size.y)); + } + } +} \ No newline at end of file diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/RectD.cs.meta b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/RectD.cs.meta new file mode 100644 index 000000000..031b24ab9 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/RectD.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 465114a58e967a04ba6bbd09745a4b96 +timeCreated: 1490802250 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector2d.cs b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector2d.cs new file mode 100644 index 000000000..5d7f5ede4 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector2d.cs @@ -0,0 +1,303 @@ +// Type: UnityEngine.Vector2 +// Assembly: UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null +// Assembly location: C:\Program Files (x86)\Unity\Editor\Data\Managed\UnityEngine.dll +using System; +using System.Runtime.CompilerServices; + +namespace Mapbox.Utils +{ + public struct Vector2d + { + public const double kEpsilon = 1E-05d; + public double x; + public double y; + + public double this[int index] + { + get + { + switch (index) + { + case 0: + return this.x; + case 1: + return this.y; + default: + throw new IndexOutOfRangeException("Invalid Vector2d index!"); + } + } + set + { + switch (index) + { + case 0: + this.x = value; + break; + case 1: + this.y = value; + break; + default: + throw new IndexOutOfRangeException("Invalid Vector2d index!"); + } + } + } + + public Vector2d normalized + { + get + { + Vector2d vector2d = new Vector2d(this.x, this.y); + vector2d.Normalize(); + return vector2d; + } + } + + public double magnitude + { + get + { + return Mathd.Sqrt(this.x * this.x + this.y * this.y); + } + } + + public double sqrMagnitude + { + get + { + return this.x * this.x + this.y * this.y; + } + } + + public static Vector2d zero + { + get + { + return new Vector2d(0.0d, 0.0d); + } + } + + public static Vector2d one + { + get + { + return new Vector2d(1d, 1d); + } + } + + public static Vector2d up + { + get + { + return new Vector2d(0.0d, 1d); + } + } + + public static Vector2d right + { + get + { + return new Vector2d(1d, 0.0d); + } + } + + public Vector2d(double x, double y) + { + this.x = x; + this.y = y; + } + + public static implicit operator Vector2d(Vector3d v) + { + return new Vector2d(v.x, v.y); + } + + public static implicit operator Vector3d(Vector2d v) + { + return new Vector3d(v.x, v.y, 0.0d); + } + + public static Vector2d operator +(Vector2d a, Vector2d b) + { + return new Vector2d(a.x + b.x, a.y + b.y); + } + + public static Vector2d operator -(Vector2d a, Vector2d b) + { + return new Vector2d(a.x - b.x, a.y - b.y); + } + + public static Vector2d operator -(Vector2d a) + { + return new Vector2d(-a.x, -a.y); + } + + public static Vector2d operator *(Vector2d a, double d) + { + return new Vector2d(a.x * d, a.y * d); + } + + public static Vector2d operator *(float d, Vector2d a) + { + return new Vector2d(a.x * d, a.y * d); + } + + public static Vector2d operator /(Vector2d a, double d) + { + return new Vector2d(a.x / d, a.y / d); + } + + public static bool operator ==(Vector2d lhs, Vector2d rhs) + { + return Vector2d.SqrMagnitude(lhs - rhs) < 0.0 / 1.0; + } + + public static bool operator !=(Vector2d lhs, Vector2d rhs) + { + return (double)Vector2d.SqrMagnitude(lhs - rhs) >= 0.0 / 1.0; + } + + public void Set(double new_x, double new_y) + { + this.x = new_x; + this.y = new_y; + } + + public static Vector2d Lerp(Vector2d from, Vector2d to, double t) + { + t = Mathd.Clamp01(t); + return new Vector2d(from.x + (to.x - from.x) * t, from.y + (to.y - from.y) * t); + } + + public static Vector2d MoveTowards(Vector2d current, Vector2d target, double maxDistanceDelta) + { + Vector2d vector2 = target - current; + double magnitude = vector2.magnitude; + if (magnitude <= maxDistanceDelta || magnitude == 0.0d) + return target; + else + return current + vector2 / magnitude * maxDistanceDelta; + } + + public static Vector2d Scale(Vector2d a, Vector2d b) + { + return new Vector2d(a.x * b.x, a.y * b.y); + } + + public void Scale(Vector2d scale) + { + this.x *= scale.x; + this.y *= scale.y; + } + + public void Normalize() + { + double magnitude = this.magnitude; + if (magnitude > 9.99999974737875E-06) + this = this / magnitude; + else + this = Vector2d.zero; + } + + public override string ToString() + { + return this.x + " - " + this.y; + //string fmt = "({0:D1}, {1:D1})"; + //object[] objArray = new object[2]; + //int index1 = 0; + //// ISSUE: variable of a boxed type + //__Boxed local1 = (ValueType)this.x; + //objArray[index1] = (object)local1; + //int index2 = 1; + //// ISSUE: variable of a boxed type + //__Boxed local2 = (ValueType)this.y; + //objArray[index2] = (object)local2; + + return "not implemented"; + } + + public string ToString(string format) + { + /* TODO: + string fmt = "({0}, {1})"; + object[] objArray = new object[2]; + int index1 = 0; + string str1 = this.x.ToString(format); + objArray[index1] = (object) str1; + int index2 = 1; + string str2 = this.y.ToString(format); + objArray[index2] = (object) str2; + */ + return "not implemented"; + } + + public override int GetHashCode() + { + return this.x.GetHashCode() ^ this.y.GetHashCode() << 2; + } + + public override bool Equals(object other) + { + if (!(other is Vector2d)) + return false; + Vector2d vector2d = (Vector2d)other; + if (this.x.Equals(vector2d.x)) + return this.y.Equals(vector2d.y); + else + return false; + } + + public static double Dot(Vector2d lhs, Vector2d rhs) + { + return lhs.x * rhs.x + lhs.y * rhs.y; + } + + public static double Angle(Vector2d from, Vector2d to) + { + return Mathd.Acos(Mathd.Clamp(Vector2d.Dot(from.normalized, to.normalized), -1d, 1d)) * 57.29578d; + } + + public static double Distance(Vector2d a, Vector2d b) + { + return (a - b).magnitude; + } + + public static Vector2d ClampMagnitude(Vector2d vector, double maxLength) + { + if (vector.sqrMagnitude > maxLength * maxLength) + return vector.normalized * maxLength; + else + return vector; + } + + public static double SqrMagnitude(Vector2d a) + { + return (a.x * a.x + a.y * a.y); + } + + public double SqrMagnitude() + { + return (this.x * this.x + this.y * this.y); + } + + public static Vector2d Min(Vector2d lhs, Vector2d rhs) + { + return new Vector2d(Mathd.Min(lhs.x, rhs.x), Mathd.Min(lhs.y, rhs.y)); + } + + public static Vector2d Max(Vector2d lhs, Vector2d rhs) + { + return new Vector2d(Mathd.Max(lhs.x, rhs.x), Mathd.Max(lhs.y, rhs.y)); + } + + public double[] ToArray() + { + double[] array = + { + this.x, + this.y + }; + + return array; + } + } +} diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector2d.cs.meta b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector2d.cs.meta new file mode 100644 index 000000000..ec26f3278 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector2d.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 9278c6e46ad98444180368e71a39a0a7 +timeCreated: 1490802250 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector3d.cs b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector3d.cs new file mode 100644 index 0000000000000000000000000000000000000000..b0dc8ec0c420a2604f2b8342d53370fdf825fe58 GIT binary patch literal 28704 zcmeHQZF3XJ5uVSf%6|}iNJ%6J{K5suK^5UHFO_hlFyYHVuKdb57|W4tW1Hl!CwZP} zwP$)}c2`&vo2uckYhdu6vBne|Lv&-yNgnTYP$t z&xg3vcW>}_8|?!(bZc(M{nGscV>$Yn8{ucyeRNyy0OP8m{06-VXNdm$fOP1dxch(| ze%a%>I{}h6z7O3d+S%i8xW~Enfze;k=Nu~-xDWV5h=+dsK@El-j2&R? zCZGx)#Q8Zee+$?{+7jGN3$UUMCUJp$BC52fSRcLYuhK$ku!LTVnM2m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s.meta new file mode 100644 index 000000000..fb271ad66 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector3d.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 406431b7fcfb6df46aae964fa2200941 +timeCreated: 1490802250 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/VectorExtensions.cs b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/VectorExtensions.cs index 74c547201..5e77131e9 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/VectorExtensions.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/VectorExtensions.cs @@ -16,30 +16,40 @@ public static Vector3 ToVector3xz(this Vector2 v) return new Vector3(v.x, 0, v.y); } + public static Vector3 ToVector3xz(this Vector2d v) + { + return new Vector3((float)v.x, 0, (float)v.y); + } + public static Vector2 ToVector2xz(this Vector3 v) { return new Vector3(v.x, v.z); } - public static void MoveToGeocoordinate(this Transform t, double lat, double lng, Vector2 refPoint, float scale = 1) + public static Vector2d ToVector2d(this Vector3 v) + { + return new Vector2d(v.x, v.z); + } + + public static void MoveToGeocoordinate(this Transform t, double lat, double lng, Vector2d refPoint, float scale = 1) { t.position = Conversions.GeoToWorldPosition(lat, lng, refPoint, scale).ToVector3xz(); } - public static void MoveToGeocoordinate(this Transform t, Vector2 latLon, Vector2 refPoint, float scale = 1) + public static void MoveToGeocoordinate(this Transform t, Vector2d latLon, Vector2d refPoint, float scale = 1) { t.MoveToGeocoordinate(latLon.x, latLon.y, refPoint, scale); } - public static Vector3 AsUnityPosition(this Vector2 latLon, Vector2 refPoint, float scale = 1) + public static Vector3 AsUnityPosition(this Vector2 latLon, Vector2d refPoint, float scale = 1) { - return Conversions.GeoToWorldPosition(latLon.x, latLon.y, refPoint, scale); + return Conversions.GeoToWorldPosition(latLon.x, latLon.y, refPoint, scale).ToVector3xz(); } - public static GeoCoordinate GetGeoPosition(this Transform t, Vector2 refPoint, float scale = 1) + public static Vector2d GetGeoPosition(this Transform t, Vector2d refPoint, float scale = 1) { - var pos = refPoint.ToVector3xz() + (t.position / scale); - return Conversions.MetersToLatLon(pos.ToVector2xz()); + var pos = refPoint + (t.position / scale).ToVector2d(); + return Conversions.MetersToLatLon(pos); } // TODO: add ability to get geo position from a vector2 or vector 3, as well (not just transform). diff --git a/sdkproject/Assets/Mapbox/Examples/Drive/Direction/DirectionsHelper.cs b/sdkproject/Assets/Mapbox/Examples/Drive/Direction/DirectionsHelper.cs index 143214920..317a58bfc 100644 --- a/sdkproject/Assets/Mapbox/Examples/Drive/Direction/DirectionsHelper.cs +++ b/sdkproject/Assets/Mapbox/Examples/Drive/Direction/DirectionsHelper.cs @@ -21,10 +21,10 @@ void Start() public void Query() { - var waypoints = new List(); + var waypoints = new List(); foreach (var wp in Waypoints) { - waypoints.Add(wp.transform.GetGeoPosition(MapController.ReferenceTileRect.center, MapController.WorldScaleFactor)); + waypoints.Add(wp.transform.GetGeoPosition(MapController.ReferenceTileRect.Center, MapController.WorldScaleFactor)); } Directions.Query(waypoints); diff --git a/sdkproject/Assets/Mapbox/Examples/MeshGenerationBasics/MapVisualization/Factories/MeshFactory.asset b/sdkproject/Assets/Mapbox/Examples/MeshGenerationBasics/MapVisualization/Factories/MeshFactory.asset index e1d43e53b..45a9743ed 100644 --- a/sdkproject/Assets/Mapbox/Examples/MeshGenerationBasics/MapVisualization/Factories/MeshFactory.asset +++ b/sdkproject/Assets/Mapbox/Examples/MeshGenerationBasics/MapVisualization/Factories/MeshFactory.asset @@ -11,6 +11,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 63d97cb1cfb3f1b499c24763afa54873, type: 3} m_Name: MeshFactory m_EditorClassIdentifier: + _mapId: mapbox.mapbox-streets-v7 Visualizers: - {fileID: 11400000, guid: 49b5b5cab8982084a986f2d148acff42, type: 2} - {fileID: 11400000, guid: e71aac5125636534886a86af764815c9, type: 2} diff --git a/sdkproject/Assets/Mapbox/Examples/Playground/Scripts/DirectionsExample.cs b/sdkproject/Assets/Mapbox/Examples/Playground/Scripts/DirectionsExample.cs index 0244f403a..9a6411762 100644 --- a/sdkproject/Assets/Mapbox/Examples/Playground/Scripts/DirectionsExample.cs +++ b/sdkproject/Assets/Mapbox/Examples/Playground/Scripts/DirectionsExample.cs @@ -32,7 +32,7 @@ public class DirectionsExample : MonoBehaviour Directions _directions; - GeoCoordinate[] _coordinates; + Vector2d[] _coordinates; DirectionResource _directionResource; @@ -42,7 +42,7 @@ void Start() _startLocationGeocoder.OnGeocoderResponse += StartLocationGeocoder_OnGeocoderResponse; _endLocationGeocoder.OnGeocoderResponse += EndLocationGeocoder_OnGeocoderResponse; - _coordinates = new GeoCoordinate[2]; + _coordinates = new Vector2d[2]; // Can we make routing profiles an enum? _directionResource = new DirectionResource(_coordinates, RoutingProfile.Driving); diff --git a/sdkproject/Assets/Mapbox/Examples/Playground/Scripts/RasterTileExample.cs b/sdkproject/Assets/Mapbox/Examples/Playground/Scripts/RasterTileExample.cs index 5b212f8f9..5c7c5a9c7 100644 --- a/sdkproject/Assets/Mapbox/Examples/Playground/Scripts/RasterTileExample.cs +++ b/sdkproject/Assets/Mapbox/Examples/Playground/Scripts/RasterTileExample.cs @@ -45,7 +45,7 @@ public class RasterTileExample : MonoBehaviour, Mapbox.Utils.IObserver Date: Thu, 30 Mar 2017 01:43:13 +0300 Subject: [PATCH 2/9] move Vector2 classes to sdk-cs --- .../Mapbox/Core/Unity/Utilities/Vector2d.meta | 9 - .../Core/Unity/Utilities/Vector2d/Mathd.cs | 378 ------------------ .../Unity/Utilities/Vector2d/Mathd.cs.meta | 12 - .../Core/Unity/Utilities/Vector2d/RectD.cs | 27 -- .../Unity/Utilities/Vector2d/RectD.cs.meta | 12 - .../Core/Unity/Utilities/Vector2d/Vector2d.cs | 303 -------------- .../Unity/Utilities/Vector2d/Vector2d.cs.meta | 12 - .../Core/Unity/Utilities/Vector2d/Vector3d.cs | Bin 28704 -> 0 bytes .../Unity/Utilities/Vector2d/Vector3d.cs.meta | 12 - 9 files changed, 765 deletions(-) delete mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d.meta delete mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Mathd.cs delete mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Mathd.cs.meta delete mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/RectD.cs delete mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/RectD.cs.meta delete mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector2d.cs delete mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector2d.cs.meta delete mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector3d.cs delete mode 100644 sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector3d.cs.meta diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d.meta b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d.meta deleted file mode 100644 index 895fd0154..000000000 --- a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: 5193dade1c52a2a4584edd672d0f199f -folderAsset: yes -timeCreated: 1490810641 -licenseType: Pro -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Mathd.cs b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Mathd.cs deleted file mode 100644 index b5efc0988..000000000 --- a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Mathd.cs +++ /dev/null @@ -1,378 +0,0 @@ -// Type: UnityEngine.Mathd -// Assembly: UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null -// Assembly location: C:\Program Files (x86)\Unity\Editor\Data\Managed\UnityEngine.dll -using System; -using System.Runtime.CompilerServices; -using UnityEngine; - -namespace Mapbox.Utils -{ - public struct Mathd { - public const double PI = 3.141593d; - public const double Infinity = double.PositiveInfinity; - public const double NegativeInfinity = double.NegativeInfinity; - public const double Deg2Rad = 0.01745329d; - public const double Rad2Deg = 57.29578d; - public const double Epsilon = 1.401298E-45d; - - public static double Sin(double d) { - return Math.Sin(d); - } - - public static double Cos(double d) { - return Math.Cos(d); - } - - public static double Tan(double d) { - return Math.Tan(d); - } - - public static double Asin(double d) { - return Math.Asin(d); - } - - public static double Acos(double d) { - return Math.Acos(d); - } - - public static double Atan(double d) { - return Math.Atan(d); - } - - public static double Atan2(double y, double x) { - return Math.Atan2(y, x); - } - - public static double Sqrt(double d) { - return Math.Sqrt(d); - } - - public static double Abs(double d) { - return Math.Abs(d); - } - - public static int Abs(int value) { - return Math.Abs(value); - } - - public static double Min(double a, double b) { - if (a < b) - return a; - else - return b; - } - - public static double Min(params double[] values) { - int length = values.Length; - if (length == 0) - return 0.0d; - double num = values[0]; - for (int index = 1; index < length; ++index) { - if (values[index] < num) - num = values[index]; - } - return num; - } - - public static int Min(int a, int b) { - if (a < b) - return a; - else - return b; - } - - public static int Min(params int[] values) { - int length = values.Length; - if (length == 0) - return 0; - int num = values[0]; - for (int index = 1; index < length; ++index) { - if (values[index] < num) - num = values[index]; - } - return num; - } - - public static double Max(double a, double b) { - if (a > b) - return a; - else - return b; - } - - public static double Max(params double[] values) { - int length = values.Length; - if (length == 0) - return 0d; - double num = values[0]; - for (int index = 1; index < length; ++index) { - if ((double)values[index] > (double)num) - num = values[index]; - } - return num; - } - - public static int Max(int a, int b) { - if (a > b) - return a; - else - return b; - } - - public static int Max(params int[] values) { - int length = values.Length; - if (length == 0) - return 0; - int num = values[0]; - for (int index = 1; index < length; ++index) { - if (values[index] > num) - num = values[index]; - } - return num; - } - - public static double Pow(double d, double p) { - return Math.Pow(d, p); - } - - public static double Exp(double power) { - return Math.Exp(power); - } - - public static double Log(double d, double p) { - return Math.Log(d, p); - } - - public static double Log(double d) { - return Math.Log(d); - } - - public static double Log10(double d) { - return Math.Log10(d); - } - - public static double Ceil(double d) { - return Math.Ceiling(d); - } - - public static double Floor(double d) { - return Math.Floor(d); - } - - public static double Round(double d) { - return Math.Round(d); - } - - public static int CeilToInt(double d) { - return (int)Math.Ceiling(d); - } - - public static int FloorToInt(double d) { - return (int)Math.Floor(d); - } - - public static int RoundToInt(double d) { - return (int)Math.Round(d); - } - - public static double Sign(double d) { - return d >= 0.0 ? 1d : -1d; - } - - public static double Clamp(double value, double min, double max) { - if (value < min) - value = min; - else if (value > max) - value = max; - return value; - } - - public static int Clamp(int value, int min, int max) { - if (value < min) - value = min; - else if (value > max) - value = max; - return value; - } - - public static double Clamp01(double value) { - if (value < 0.0) - return 0.0d; - if (value > 1.0) - return 1d; - else - return value; - } - - public static double Lerp(double from, double to, double t) { - return from + (to - from) * Mathd.Clamp01(t); - } - - public static double LerpAngle(double a, double b, double t) { - double num = Mathd.Repeat(b - a, 360d); - if (num > 180.0d) - num -= 360d; - return a + num * Mathd.Clamp01(t); - } - - public static double MoveTowards(double current, double target, double maxDelta) { - if (Mathd.Abs(target - current) <= maxDelta) - return target; - else - return current + Mathd.Sign(target - current) * maxDelta; - } - - public static double MoveTowardsAngle(double current, double target, double maxDelta) { - target = current + Mathd.DeltaAngle(current, target); - return Mathd.MoveTowards(current, target, maxDelta); - } - - public static double SmoothStep(double from, double to, double t) { - t = Mathd.Clamp01(t); - t = (-2.0 * t * t * t + 3.0 * t * t); - return to * t + from * (1.0 - t); - } - - public static double Gamma(double value, double absmax, double gamma) { - bool flag = false; - if (value < 0.0) - flag = true; - double num1 = Mathd.Abs(value); - if (num1 > absmax) { - if (flag) - return -num1; - else - return num1; - } else { - double num2 = Mathd.Pow(num1 / absmax, gamma) * absmax; - if (flag) - return -num2; - else - return num2; - } - } - - public static bool Approximately(double a, double b) { - return Mathd.Abs(b - a) < Mathd.Max(1E-06d * Mathd.Max(Mathd.Abs(a), Mathd.Abs(b)), 1.121039E-44d); - } - - public static double SmoothDamp(double current, double target, ref double currentVelocity, double smoothTime, double maxSpeed) { - double deltaTime = (double)Time.deltaTime; - return Mathd.SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime); - } - - public static double SmoothDamp(double current, double target, ref double currentVelocity, double smoothTime) { - double deltaTime = Time.deltaTime; - double maxSpeed = double.PositiveInfinity; - return Mathd.SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime); - } - - public static double SmoothDamp(double current, double target, ref double currentVelocity, double smoothTime, double maxSpeed, double deltaTime) { - smoothTime = Mathd.Max(0.0001d, smoothTime); - double num1 = 2d / smoothTime; - double num2 = num1 * deltaTime; - double num3 = (1.0d / (1.0d + num2 + 0.479999989271164d * num2 * num2 + 0.234999999403954d * num2 * num2 * num2)); - double num4 = current - target; - double num5 = target; - double max = maxSpeed * smoothTime; - double num6 = Mathd.Clamp(num4, -max, max); - target = current - num6; - double num7 = (currentVelocity + num1 * num6) * deltaTime; - currentVelocity = (currentVelocity - num1 * num7) * num3; - double num8 = target + (num6 + num7) * num3; - if (num5 - current > 0.0 == num8 > num5) { - num8 = num5; - currentVelocity = (num8 - num5) / deltaTime; - } - return num8; - } - - public static double SmoothDampAngle(double current, double target, ref double currentVelocity, double smoothTime, double maxSpeed) { - double deltaTime = (double)Time.deltaTime; - return Mathd.SmoothDampAngle(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime); - } - - public static double SmoothDampAngle(double current, double target, ref double currentVelocity, double smoothTime) { - double deltaTime = (double)Time.deltaTime; - double maxSpeed = double.PositiveInfinity; - return Mathd.SmoothDampAngle(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime); - } - - public static double SmoothDampAngle(double current, double target, ref double currentVelocity, double smoothTime, double maxSpeed, double deltaTime) { - target = current + Mathd.DeltaAngle(current, target); - return Mathd.SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime); - } - - public static double Repeat(double t, double length) { - return t - Mathd.Floor(t / length) * length; - } - - public static double PingPong(double t, double length) { - t = Mathd.Repeat(t, length * 2d); - return length - Mathd.Abs(t - length); - } - - public static double InverseLerp(double from, double to, double value) { - if (from < to) { - if (value < from) - return 0d; - if (value > to) - return 1d; - value -= from; - value /= to - from; - return value; - } else { - if (from <= to) - return 0d; - if (value < to) - return 1d; - if (value > from) - return 0d; - else - return (1.0d - (value - to) / (from - to)); - } - } - - public static double DeltaAngle(double current, double target) { - double num = Mathd.Repeat(target - current, 360d); - if (num > 180.0d) - num -= 360d; - return num; - } - - internal static bool LineIntersection(Vector2d p1, Vector2d p2, Vector2d p3, Vector2d p4, ref Vector2d result) { - double num1 = p2.x - p1.x; - double num2 = p2.y - p1.y; - double num3 = p4.x - p3.x; - double num4 = p4.y - p3.y; - double num5 = num1 * num4 - num2 * num3; - if (num5 == 0.0d) - return false; - double num6 = p3.x - p1.x; - double num7 = p3.y - p1.y; - double num8 = (num6 * num4 - num7 * num3) / num5; - result = new Vector2d(p1.x + num8 * num1, p1.y + num8 * num2); - return true; - } - - internal static bool LineSegmentIntersection(Vector2d p1, Vector2d p2, Vector2d p3, Vector2d p4, ref Vector2d result) { - double num1 = p2.x - p1.x; - double num2 = p2.y - p1.y; - double num3 = p4.x - p3.x; - double num4 = p4.y - p3.y; - double num5 = (num1 * num4 - num2 * num3); - if (num5 == 0.0d) - return false; - double num6 = p3.x - p1.x; - double num7 = p3.y - p1.y; - double num8 = (num6 * num4 - num7 * num3) / num5; - if (num8 < 0.0d || num8 > 1.0d) - return false; - double num9 = (num6 * num2 - num7 * num1) / num5; - if (num9 < 0.0d || num9 > 1.0d) - return false; - result = new Vector2d(p1.x + num8 * num1, p1.y + num8 * num2); - return true; - } - } -} diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Mathd.cs.meta b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Mathd.cs.meta deleted file mode 100644 index d08216fde..000000000 --- a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Mathd.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: f126d867620a586468dcf8d3921a5b8e -timeCreated: 1490802250 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/RectD.cs b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/RectD.cs deleted file mode 100644 index a58efcaf7..000000000 --- a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/RectD.cs +++ /dev/null @@ -1,27 +0,0 @@ -using UnityEngine; - -namespace Mapbox.Utils -{ - public class RectD - { - public Vector2d Min { get; private set; } - public Vector2d Max { get; private set; } - //size is absolute width&height so Min+size != max - public Vector2d Size { get; private set; } - public Vector2d Center { get; private set; } - - public RectD(Vector2d min, Vector2d size) - { - Min = min; - Max = min + size; - Center = new Vector2d(Min.x + size.x / 2, Min.y + size.y / 2); - Size = new Vector2d(Mathd.Abs(size.x), Mathd.Abs(size.y)); - } - - public bool Contains(Vector2d point) - { - bool flag = Size.x < 0.0 && point.x <= Min.x && point.x > (Min.x + Size.x) || Size.x >= 0.0 && point.x >= Min.x && point.x < (Min.x + Size.x); - return flag && (Size.y < 0.0 && point.y <= Min.y && point.y > (Min.y + Size.y) || Size.y >= 0.0 && point.y >= Min.y && point.y < (Min.y + Size.y)); - } - } -} \ No newline at end of file diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/RectD.cs.meta b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/RectD.cs.meta deleted file mode 100644 index 031b24ab9..000000000 --- a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/RectD.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 465114a58e967a04ba6bbd09745a4b96 -timeCreated: 1490802250 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector2d.cs b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector2d.cs deleted file mode 100644 index 5d7f5ede4..000000000 --- a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector2d.cs +++ /dev/null @@ -1,303 +0,0 @@ -// Type: UnityEngine.Vector2 -// Assembly: UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null -// Assembly location: C:\Program Files (x86)\Unity\Editor\Data\Managed\UnityEngine.dll -using System; -using System.Runtime.CompilerServices; - -namespace Mapbox.Utils -{ - public struct Vector2d - { - public const double kEpsilon = 1E-05d; - public double x; - public double y; - - public double this[int index] - { - get - { - switch (index) - { - case 0: - return this.x; - case 1: - return this.y; - default: - throw new IndexOutOfRangeException("Invalid Vector2d index!"); - } - } - set - { - switch (index) - { - case 0: - this.x = value; - break; - case 1: - this.y = value; - break; - default: - throw new IndexOutOfRangeException("Invalid Vector2d index!"); - } - } - } - - public Vector2d normalized - { - get - { - Vector2d vector2d = new Vector2d(this.x, this.y); - vector2d.Normalize(); - return vector2d; - } - } - - public double magnitude - { - get - { - return Mathd.Sqrt(this.x * this.x + this.y * this.y); - } - } - - public double sqrMagnitude - { - get - { - return this.x * this.x + this.y * this.y; - } - } - - public static Vector2d zero - { - get - { - return new Vector2d(0.0d, 0.0d); - } - } - - public static Vector2d one - { - get - { - return new Vector2d(1d, 1d); - } - } - - public static Vector2d up - { - get - { - return new Vector2d(0.0d, 1d); - } - } - - public static Vector2d right - { - get - { - return new Vector2d(1d, 0.0d); - } - } - - public Vector2d(double x, double y) - { - this.x = x; - this.y = y; - } - - public static implicit operator Vector2d(Vector3d v) - { - return new Vector2d(v.x, v.y); - } - - public static implicit operator Vector3d(Vector2d v) - { - return new Vector3d(v.x, v.y, 0.0d); - } - - public static Vector2d operator +(Vector2d a, Vector2d b) - { - return new Vector2d(a.x + b.x, a.y + b.y); - } - - public static Vector2d operator -(Vector2d a, Vector2d b) - { - return new Vector2d(a.x - b.x, a.y - b.y); - } - - public static Vector2d operator -(Vector2d a) - { - return new Vector2d(-a.x, -a.y); - } - - public static Vector2d operator *(Vector2d a, double d) - { - return new Vector2d(a.x * d, a.y * d); - } - - public static Vector2d operator *(float d, Vector2d a) - { - return new Vector2d(a.x * d, a.y * d); - } - - public static Vector2d operator /(Vector2d a, double d) - { - return new Vector2d(a.x / d, a.y / d); - } - - public static bool operator ==(Vector2d lhs, Vector2d rhs) - { - return Vector2d.SqrMagnitude(lhs - rhs) < 0.0 / 1.0; - } - - public static bool operator !=(Vector2d lhs, Vector2d rhs) - { - return (double)Vector2d.SqrMagnitude(lhs - rhs) >= 0.0 / 1.0; - } - - public void Set(double new_x, double new_y) - { - this.x = new_x; - this.y = new_y; - } - - public static Vector2d Lerp(Vector2d from, Vector2d to, double t) - { - t = Mathd.Clamp01(t); - return new Vector2d(from.x + (to.x - from.x) * t, from.y + (to.y - from.y) * t); - } - - public static Vector2d MoveTowards(Vector2d current, Vector2d target, double maxDistanceDelta) - { - Vector2d vector2 = target - current; - double magnitude = vector2.magnitude; - if (magnitude <= maxDistanceDelta || magnitude == 0.0d) - return target; - else - return current + vector2 / magnitude * maxDistanceDelta; - } - - public static Vector2d Scale(Vector2d a, Vector2d b) - { - return new Vector2d(a.x * b.x, a.y * b.y); - } - - public void Scale(Vector2d scale) - { - this.x *= scale.x; - this.y *= scale.y; - } - - public void Normalize() - { - double magnitude = this.magnitude; - if (magnitude > 9.99999974737875E-06) - this = this / magnitude; - else - this = Vector2d.zero; - } - - public override string ToString() - { - return this.x + " - " + this.y; - //string fmt = "({0:D1}, {1:D1})"; - //object[] objArray = new object[2]; - //int index1 = 0; - //// ISSUE: variable of a boxed type - //__Boxed local1 = (ValueType)this.x; - //objArray[index1] = (object)local1; - //int index2 = 1; - //// ISSUE: variable of a boxed type - //__Boxed local2 = (ValueType)this.y; - //objArray[index2] = (object)local2; - - return "not implemented"; - } - - public string ToString(string format) - { - /* TODO: - string fmt = "({0}, {1})"; - object[] objArray = new object[2]; - int index1 = 0; - string str1 = this.x.ToString(format); - objArray[index1] = (object) str1; - int index2 = 1; - string str2 = this.y.ToString(format); - objArray[index2] = (object) str2; - */ - return "not implemented"; - } - - public override int GetHashCode() - { - return this.x.GetHashCode() ^ this.y.GetHashCode() << 2; - } - - public override bool Equals(object other) - { - if (!(other is Vector2d)) - return false; - Vector2d vector2d = (Vector2d)other; - if (this.x.Equals(vector2d.x)) - return this.y.Equals(vector2d.y); - else - return false; - } - - public static double Dot(Vector2d lhs, Vector2d rhs) - { - return lhs.x * rhs.x + lhs.y * rhs.y; - } - - public static double Angle(Vector2d from, Vector2d to) - { - return Mathd.Acos(Mathd.Clamp(Vector2d.Dot(from.normalized, to.normalized), -1d, 1d)) * 57.29578d; - } - - public static double Distance(Vector2d a, Vector2d b) - { - return (a - b).magnitude; - } - - public static Vector2d ClampMagnitude(Vector2d vector, double maxLength) - { - if (vector.sqrMagnitude > maxLength * maxLength) - return vector.normalized * maxLength; - else - return vector; - } - - public static double SqrMagnitude(Vector2d a) - { - return (a.x * a.x + a.y * a.y); - } - - public double SqrMagnitude() - { - return (this.x * this.x + this.y * this.y); - } - - public static Vector2d Min(Vector2d lhs, Vector2d rhs) - { - return new Vector2d(Mathd.Min(lhs.x, rhs.x), Mathd.Min(lhs.y, rhs.y)); - } - - public static Vector2d Max(Vector2d lhs, Vector2d rhs) - { - return new Vector2d(Mathd.Max(lhs.x, rhs.x), Mathd.Max(lhs.y, rhs.y)); - } - - public double[] ToArray() - { - double[] array = - { - this.x, - this.y - }; - - return array; - } - } -} diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector2d.cs.meta b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector2d.cs.meta deleted file mode 100644 index ec26f3278..000000000 --- a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector2d.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 9278c6e46ad98444180368e71a39a0a7 -timeCreated: 1490802250 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector3d.cs b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector3d.cs deleted file mode 100644 index b0dc8ec0c420a2604f2b8342d53370fdf825fe58..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 28704 zcmeHQZF3XJ5uVSf%6|}iNJ%6J{K5suK^5UHFO_hlFyYHVuKdb57|W4tW1Hl!CwZP} zwP$)}c2`&vo2uckYhdu6vBne|Lv&-yNgnTYP$t z&xg3vcW>}_8|?!(bZc(M{nGscV>$Yn8{ucyeRNyy0OP8m{06-VXNdm$fOP1dxch(| ze%a%>I{}h6z7O3d+S%i8xW~Enfze;k=Nu~-xDWV5h=+dsK@El-j2&R? zCZGx)#Q8Zee+$?{+7jGN3$UUMCUJp$BC52fSRcLYuhK$ku!LTVnM2m62ae>+$Q ze~u!Kb^NM^XrVlbM5L0X<17?ywa~UP|DlK3aeJ750Q?B|1Nd@;cH+by9mqzDJaqhZ2Yfqo z?+iy2TA9Lnmy&y29H%|%$7`>V`vgpm!SNq~Q#Zn@R|{RoPd1D8re@P3b-?Gx6T#P! zdZpzN3q-k5s`e}SujA5dz+`34m{dtsih+I)n5@nj6O~n+sp(2-+yjTi%D3YWIYK-A z3EZK7;`Pt?B$ECTu#eqK%<>BJ(3(9K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BT9MAWP53v6kTILb`-A1Hx z8?ae{QYwWf0eFYecHV=rFUM5(&{O?<@9XUu<6`UWtku&RR?1b)5y~D-pO7kXrCtNA zAJbeQ%_R7p^wIliuAubO`=pl5L}s%*mSQ<==$$ak^Dc5Tu2OgWv- zOYG9NY3&=IljE)rcU)Ewn>>OKTlc#+YxuT~Z>!#)t;4TXoup99pjRs?DG!*t%6kCI zoK`69y;@2Wk+2*OrR(W95@eiLrfIWvp42lo$)~(unz4!Gxhd8i;L0~pYme9CieXt& z^*JT>qD^iisg|25M6r`8mOLN88cWc#bR6+5ucS(X+fmrs%xB)CR8<@m$1*MXY}oAd zV>C*C!(E7H;3Ml$-HIpPa_bZ_1jV(F6@~mn;%(W_CcfpnJul_qy<75*Jk2B?AcpOG zOTbSLfoWM!=fRKkbZ@@mdDnqcNv*05R9EQq-2jXa@(QuG+6u9@HfPvY+f-Wg`R9Dk zigKhrIJRS2aS(5u-%-C@zC#b5-%(#(x-(y`eG^$^u7v+pMV|vL<#T!e7)R=}wF8V$ z&s@BN-bS-EH;m`%L!bE$z7sa>`tWtx62<|w*$OJUAL`yFefS_H_Y2a5bMaqvTlU-n z@q3JCzj(5q|I>*7OHBT&8Q-E7o-9eBFjM7I>C9^QU(q<8dqaEE{V`_F28AcrN+- Ee-eq?cK`qY diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector3d.cs.meta b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector3d.cs.meta deleted file mode 100644 index fb271ad66..000000000 --- a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Vector2d/Vector3d.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 406431b7fcfb6df46aae964fa2200941 -timeCreated: 1490802250 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: From a3144ace902b12b13be3999750afd3026d6c7ca6 Mon Sep 17 00:00:00 2001 From: David Rhodes Date: Wed, 29 Mar 2017 16:47:58 -0600 Subject: [PATCH 3/9] bumping to the proper branch for testing --- dependencies/mapbox-sdk-cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies/mapbox-sdk-cs b/dependencies/mapbox-sdk-cs index 9bd950375..4cb2cece7 160000 --- a/dependencies/mapbox-sdk-cs +++ b/dependencies/mapbox-sdk-cs @@ -1 +1 @@ -Subproject commit 9bd950375dccf6423b93f1afd2ab4286b44dcf66 +Subproject commit 4cb2cece7f9f14cfffdc9067d464ab84a34af9f3 From 0f02e99890d69d431a703e267fd94b3dc6a31c52 Mon Sep 17 00:00:00 2001 From: brnkhy Date: Thu, 30 Mar 2017 19:13:00 +0300 Subject: [PATCH 4/9] removed GeometryAsWsg84 usage and converting vector tile coordinates to unity space in VectorFeatureUnity class --- .../MeshGeneration/Data/VectorFeatureUnity.cs | 53 ++++++++++++------- .../LayerVisualizers/PoiVisualizer.cs | 2 +- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Data/VectorFeatureUnity.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Data/VectorFeatureUnity.cs index c39666af4..d9574b342 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Data/VectorFeatureUnity.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Data/VectorFeatureUnity.cs @@ -1,21 +1,34 @@ -namespace Mapbox.Unity.MeshGeneration.Data -{ - using Mapbox.VectorTile; - using Mapbox.VectorTile.ExtensionMethods; - using System.Collections.Generic; - using Mapbox.VectorTile.Geometry; - +namespace Mapbox.Unity.MeshGeneration.Data +{ + using Mapbox.VectorTile; + using Mapbox.VectorTile.ExtensionMethods; + using System.Collections.Generic; + using Mapbox.VectorTile.Geometry; + using UnityEngine; + public class VectorFeatureUnity - { - public VectorTileFeature Data { get; set; } - public Dictionary Properties { get; set; } - public List> Points; - - public VectorFeatureUnity(VectorTileFeature feature, UnityTile tile) - { - Data = feature; - Properties = Data.GetProperties(); - Points = feature.GeometryAsWgs84((ulong)tile.Zoom, (ulong)tile.TileCoordinate.x, (ulong)tile.TileCoordinate.y); - } - } -} + { + private const float TileMax = 4096f; + public VectorTileFeature Data { get; set; } + public Dictionary Properties { get; set; } + public List> Points; + + public VectorFeatureUnity(VectorTileFeature feature, UnityTile tile) + { + Data = feature; + Properties = Data.GetProperties(); + Points = new List>(); + + for (int i = 0; i < feature.Geometry.Count; i++) + { + var nl = new List(feature.Geometry[i].Count); + for (int j = 0; j < feature.Geometry[i].Count; j++) + { + var point = feature.Geometry[i][j]; + nl.Add(new Vector3((float)(point.X / TileMax * tile.Rect.Size.x - (tile.Rect.Size.x/2)), 0, (float)((TileMax - point.Y) / TileMax * tile.Rect.Size.y - (tile.Rect.Size.y / 2)))); + } + Points.Add(nl); + } + } + } +} diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/PoiVisualizer.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/PoiVisualizer.cs index eb311104a..41219a8f3 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/PoiVisualizer.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/PoiVisualizer.cs @@ -41,7 +41,7 @@ private void Build(VectorFeatureUnity feature, UnityTile tile, GameObject parent return; int selpos = feature.Points[0].Count / 2; - var met = Conversions.GeoToWorldPosition(feature.Points[0][selpos].Lat, feature.Points[0][selpos].Lng, tile.Rect.Center).ToVector3xz(); + var met = feature.Points[0][selpos]; if (Math.Abs(met.x) > Math.Abs(tile.Rect.Size.x) / 2 || Math.Abs(met.y) > Math.Abs(tile.Rect.Size.y) / 2) return; if (!feature.Properties.ContainsKey("name")) From d823d3dfb6bf8d930851a8efbfeceb498e0e79d4 Mon Sep 17 00:00:00 2001 From: brnkhy Date: Thu, 30 Mar 2017 20:45:09 +0300 Subject: [PATCH 5/9] add missing VectorLayerVisualizer from previous commit --- .../MeshGeneration/LayerVisualizers/VectorLayerVisualizer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/VectorLayerVisualizer.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/VectorLayerVisualizer.cs index ea731c5dc..749c24cc2 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/VectorLayerVisualizer.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/VectorLayerVisualizer.cs @@ -110,7 +110,8 @@ private void Build(VectorFeatureUnity feature, UnityTile tile, GameObject parent } //we'll run all visualizers on MeshData here - var list = geometry.Select(x => Conversions.GeoToWorldPosition(x.Lat, x.Lng, tile.Rect.Center).ToVector3xz()).ToList(); + var list = geometry; + //.Select(x => Conversions.GeoToWorldPosition(x.Lat, x.Lng, tile.Rect.Center).ToVector3xz()).ToList(); //long straight edges looks bad on bumpy terrain if (_subdivideLongEdges) From 3baa1174c1e1111a4188fe29e7ec583db7666cf2 Mon Sep 17 00:00:00 2001 From: David Rhodes Date: Thu, 30 Mar 2017 13:54:20 -0600 Subject: [PATCH 6/9] Adding fix for Directions request (proper string formatting for Vector2d). --- dependencies/mapbox-sdk-cs | 2 +- .../Core/Unity/MeshGeneration/Factories/DirectionsFactory.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dependencies/mapbox-sdk-cs b/dependencies/mapbox-sdk-cs index 4cb2cece7..456e641ef 160000 --- a/dependencies/mapbox-sdk-cs +++ b/dependencies/mapbox-sdk-cs @@ -1 +1 @@ -Subproject commit 4cb2cece7f9f14cfffdc9067d464ab84a34af9f3 +Subproject commit 456e641ef8c9cfd46cd14de4822cc09f6e322155 diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/DirectionsFactory.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/DirectionsFactory.cs index facc549f5..7135140e0 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/DirectionsFactory.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/DirectionsFactory.cs @@ -21,7 +21,7 @@ public class DirectionsFactory : Factory public override void Initialize(MonoBehaviour mb, IFileSource fileSource) { base.Initialize(mb, fileSource); - _directions = new Directions(fileSource); + _directions = MapboxAccess.Instance.Directions; } public void Query(List waypoints) From 433c61170bbb14ba6e79465e06b7f2d7e771932b Mon Sep 17 00:00:00 2001 From: brnkhy Date: Fri, 31 Mar 2017 17:06:12 +0300 Subject: [PATCH 7/9] fix the vector tile layer extent problem which wasn't working with traffic data --- .../Core/Unity/MeshGeneration/Data/VectorFeatureUnity.cs | 5 ++--- .../Unity/MeshGeneration/LayerVisualizers/PoiVisualizer.cs | 2 +- .../MeshGeneration/LayerVisualizers/VectorLayerVisualizer.cs | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Data/VectorFeatureUnity.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Data/VectorFeatureUnity.cs index d9574b342..0264537ed 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Data/VectorFeatureUnity.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Data/VectorFeatureUnity.cs @@ -8,12 +8,11 @@ namespace Mapbox.Unity.MeshGeneration.Data public class VectorFeatureUnity { - private const float TileMax = 4096f; public VectorTileFeature Data { get; set; } public Dictionary Properties { get; set; } public List> Points; - public VectorFeatureUnity(VectorTileFeature feature, UnityTile tile) + public VectorFeatureUnity(VectorTileFeature feature, UnityTile tile, float layerExtent) { Data = feature; Properties = Data.GetProperties(); @@ -25,7 +24,7 @@ public VectorFeatureUnity(VectorTileFeature feature, UnityTile tile) for (int j = 0; j < feature.Geometry[i].Count; j++) { var point = feature.Geometry[i][j]; - nl.Add(new Vector3((float)(point.X / TileMax * tile.Rect.Size.x - (tile.Rect.Size.x/2)), 0, (float)((TileMax - point.Y) / TileMax * tile.Rect.Size.y - (tile.Rect.Size.y / 2)))); + nl.Add(new Vector3((float)(point.X / layerExtent * tile.Rect.Size.x - (tile.Rect.Size.x/2)), 0, (float)((layerExtent - point.Y) / layerExtent * tile.Rect.Size.y - (tile.Rect.Size.y / 2)))); } Points.Add(nl); } diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/PoiVisualizer.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/PoiVisualizer.cs index 41219a8f3..f61a388db 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/PoiVisualizer.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/PoiVisualizer.cs @@ -30,7 +30,7 @@ public override void Create(VectorTileLayer layer, UnityTile tile) var fc = layer.FeatureCount(); for (int i = 0; i < fc; i++) { - var feature = new VectorFeatureUnity(layer.GetFeature(i, 0), tile); + var feature = new VectorFeatureUnity(layer.GetFeature(i, 0), tile, layer.Extent); Build(feature, tile, _container); } } diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/VectorLayerVisualizer.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/VectorLayerVisualizer.cs index 749c24cc2..1f61cf1b9 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/VectorLayerVisualizer.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/LayerVisualizers/VectorLayerVisualizer.cs @@ -55,7 +55,7 @@ public override void Create(VectorTileLayer layer, UnityTile tile) for (int i = 0; i < fc; i++) { filterOut = false; - var feature = new VectorFeatureUnity(layer.GetFeature(i, 0), tile); + var feature = new VectorFeatureUnity(layer.GetFeature(i, 0), tile, layer.Extent); foreach (var filter in Filters) { if (!string.IsNullOrEmpty(filter.Key) && !feature.Properties.ContainsKey(filter.Key)) From 1cbcc05c57fd117779bb70cc24aabbafcd49aa8b Mon Sep 17 00:00:00 2001 From: David Rhodes Date: Fri, 31 Mar 2017 09:19:13 -0600 Subject: [PATCH 8/9] Removing monobehaviour injection (no longer needed). (#1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use `Runnable.Run()` for any “asynchronous” operations, rather than coroutines! --- .../Core/Unity/MeshGeneration/Factories/DirectionsFactory.cs | 4 ++-- .../Mapbox/Core/Unity/MeshGeneration/Factories/Factory.cs | 2 +- .../Core/Unity/MeshGeneration/Factories/MapImageFactory.cs | 4 ++-- .../Mapbox/Core/Unity/MeshGeneration/Factories/MeshFactory.cs | 4 ++-- .../Core/Unity/MeshGeneration/Factories/TerrainFactory.cs | 4 ++-- .../Assets/Mapbox/Core/Unity/MeshGeneration/MapController.cs | 4 +--- .../Mapbox/Core/Unity/MeshGeneration/MapVisualization.cs | 4 ++-- 7 files changed, 12 insertions(+), 14 deletions(-) diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/DirectionsFactory.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/DirectionsFactory.cs index 7135140e0..cb80b7035 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/DirectionsFactory.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/DirectionsFactory.cs @@ -18,9 +18,9 @@ public class DirectionsFactory : Factory private Directions _directions; public List MeshModifiers; - public override void Initialize(MonoBehaviour mb, IFileSource fileSource) + public override void Initialize(IFileSource fileSource) { - base.Initialize(mb, fileSource); + base.Initialize(fileSource); _directions = MapboxAccess.Instance.Directions; } diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/Factory.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/Factory.cs index b9bc43e57..f2334709a 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/Factory.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/Factory.cs @@ -8,7 +8,7 @@ public class Factory : ScriptableObject { protected IFileSource FileSource; - public virtual void Initialize(MonoBehaviour mb, IFileSource fileSource) + public virtual void Initialize(IFileSource fileSource) { FileSource = fileSource; } diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/MapImageFactory.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/MapImageFactory.cs index fa608eeb0..c17596a32 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/MapImageFactory.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/MapImageFactory.cs @@ -20,9 +20,9 @@ public class MapImageFactory : Factory private Dictionary _tiles; - public override void Initialize(MonoBehaviour mb, IFileSource fs) + public override void Initialize(IFileSource fs) { - base.Initialize(mb, fs); + base.Initialize(fs); _tiles = new Dictionary(); } diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/MeshFactory.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/MeshFactory.cs index c539695dd..f50a83a62 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/MeshFactory.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/MeshFactory.cs @@ -17,9 +17,9 @@ public class MeshFactory : Factory private Dictionary _tiles; private Dictionary> _layerBuilder; - public override void Initialize(MonoBehaviour mb, IFileSource fs) + public override void Initialize(IFileSource fs) { - base.Initialize(mb, fs); + base.Initialize(fs); _tiles = new Dictionary(); _layerBuilder = new Dictionary>(); foreach (LayerVisualizerBase factory in Visualizers) diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/TerrainFactory.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/TerrainFactory.cs index fcb26c321..8d49919f4 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/TerrainFactory.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/TerrainFactory.cs @@ -25,9 +25,9 @@ public class TerrainFactory : Factory [SerializeField] private int sampleCount = 40; - public override void Initialize(MonoBehaviour mb, IFileSource fs) + public override void Initialize(IFileSource fs) { - base.Initialize(mb, fs); + base.Initialize(fs); _tiles = new Dictionary(); } diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/MapController.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/MapController.cs index 9a53ec215..224ce95d7 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/MapController.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/MapController.cs @@ -10,7 +10,6 @@ namespace Mapbox.Unity.MeshGeneration public class MapController : MonoBehaviour { - private IFileSource _fileSource; public static RectD ReferenceTileRect { get; set; } public static float WorldScaleFactor { get; set; } @@ -30,8 +29,7 @@ public class MapController : MonoBehaviour public void Awake() { - _fileSource = MapboxAccess.Instance; - MapVisualization.Initialize(this, _fileSource); + MapVisualization.Initialize(MapboxAccess.Instance); _tiles = new Dictionary(); } diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/MapVisualization.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/MapVisualization.cs index 24a5794d8..525289c93 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/MapVisualization.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/MapVisualization.cs @@ -12,11 +12,11 @@ public class MapVisualization : ScriptableObject { public List Factories; - public void Initialize(MonoBehaviour runner, IFileSource fs) + public void Initialize(IFileSource fs) { foreach (Factory fac in Factories.Where(x => x != null)) { - fac.Initialize(runner, fs); + fac.Initialize(fs); } } From 6e69e527f74bed1cb5cf42db59c294acc4b36ad4 Mon Sep 17 00:00:00 2001 From: David Rhodes Date: Fri, 31 Mar 2017 12:06:58 -0600 Subject: [PATCH 9/9] Pointing back to master. --- dependencies/mapbox-sdk-cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies/mapbox-sdk-cs b/dependencies/mapbox-sdk-cs index 456e641ef..e7cec0185 160000 --- a/dependencies/mapbox-sdk-cs +++ b/dependencies/mapbox-sdk-cs @@ -1 +1 @@ -Subproject commit 456e641ef8c9cfd46cd14de4822cc09f6e322155 +Subproject commit e7cec018502fe90ecced48dee846e99e2798523f