public Distance(string distanceUnit) { distanceUnit.ThrowIfNullOrEmpty(nameof(distanceUnit)); var match = _distanceUnitRegex.Match(distanceUnit); if (!match.Success) throw new ArgumentException("must be a valid distance unit", nameof(distanceUnit)); var precision = double.Parse(match.Groups["precision"].Value, NumberStyles.Any, CultureInfo.InvariantCulture); var unit = match.Groups["unit"].Value; this.Precision = precision; if (string.IsNullOrEmpty(unit)) { this.Unit = DistanceUnit.Meters; return; } var unitMeasure = unit.ToEnum<DistanceUnit>(); if (unitMeasure == null) { throw new InvalidCastException($"cannot parse {typeof(DistanceUnit).Name} from string '{unit}'"); } this.Unit = unitMeasure.Value; }
/// <summary> /// Creates a new <c>PathItem</c> /// </summary> /// <param name="itemType">The type of item involved</param> /// <param name="unit">The distance unit (was default=null)</param> /// <param name="value">The item value (was default=0.0)</param> internal PathItem(PathItemType itemType, DistanceUnit unit, double value) { m_Item = itemType; m_Unit = unit; m_Value = value; m_Leg = 0; }
/// <summary> /// Default constructor creates a null item. /// </summary> internal PathItem() { m_Item = PathItemType.Null; m_Unit = null; m_Value = 0.0; m_Leg = 0; }
public RadialSearchQuery(Field field, Geocode center, decimal radius, DistanceUnit unit = Sdk.DistanceUnit.Miles) { this.Field = field; this.Center = center; this.DistanceUnit = unit; this.Radius = radius; }
/// <summary> /// Initializes a new instance of the <see cref="PathParser"/> class, and /// attempts to parse the supplied string. /// </summary> /// <param name="str">The string to parse</param> /// <param name="entryUnit">The initial default entry units</param> PathParser(string str, DistanceUnit entryUnit) { m_Items = new List<PathItem>(); m_Omit = false; m_Units = entryUnit; ParseString(str); }
/// <summary>Returns the distance using Haversine formula in miles or kilometers of any two latitude and longitude points.</summary> /// <param name="p1">Location 1</param> /// <param name="p2">Location 2</param> /// <param name="unit">Miles or Kilometers</param> /// <returns>Distance in the requested unit.</returns> public static double GetDistance(LatLong p1, LatLong p2, DistanceUnit unit) { double r = (unit == DistanceUnit.Miles) ? 3960 : 6371; var lat = (p2.Latitude - p1.Latitude).ToRadians(); var lng = (p2.Longitude - p1.Longitude).ToRadians(); var h1 = Math.Sin(lat / 2) * Math.Sin(lat / 2) + Math.Cos(p1.Latitude.ToRadians()) * Math.Cos(p2.Latitude.ToRadians()) * Math.Sin(lng / 2) * Math.Sin(lng / 2); var h2 = 2 * Math.Asin(Math.Min(1, Math.Sqrt(h1))); return r * h2; }
internal override void InitializeUnits(DistanceUnit units) { if (units.UnitType == DistanceUnitType.Feet) fRadioButton.Checked = true; else if (units.UnitType == DistanceUnitType.Chains) cRadioButton.Checked = true; else mRadioButton.Checked = true; }
public DistanceSet(DateTime date, double distance, DistanceUnit unit, TimeSpan duration) { Date = date; Distance = distance; Unit = unit; Duration = duration; }
public async Task<double?> GetDistanceAsync(GetGeoCoordinatesRequest startPoint, GetGeoCoordinatesRequest endPoint, DistanceUnit distanceUnit) { if (startPoint != null && endPoint != null) { var url = DistanceUrl + string.Format("?origins={0}&destinations={1}&language=en-gb", Uri.EscapeUriString(startPoint.PostCode), Uri.EscapeUriString(endPoint.PostCode)); return await GetDistanceAsync(url, distanceUnit); } return null; }
public double CalculateDistance(IPosition pos1, IPosition pos2, DistanceUnit unit) { var r = (unit == DistanceUnit.Miles) ? GeoConstants.EarthRadiusInMiles : GeoConstants.EarthRadiusInKilometers; var dLat = _angleConverter.ConvertDegreesToRadians(pos2.X) - _angleConverter.ConvertDegreesToRadians(pos1.X); var dLon = _angleConverter.ConvertDegreesToRadians(pos2.Y) - _angleConverter.ConvertDegreesToRadians(pos1.Y); var a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Cos(_angleConverter.ConvertDegreesToRadians(pos1.X)) * Math.Cos(_angleConverter.ConvertDegreesToRadians(pos2.X)) * Math.Sin(dLon / 2) * Math.Sin(dLon / 2); var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); var distance = c * r; return Math.Round(distance, 2); }
/// <summary> /// Calculate the distance between two positions. /// </summary> public double CalculateDistance(Position position1, Position position2, DistanceUnit distanceUnit) { var R = (distanceUnit == DistanceUnit.Miles) ? GeoConstants.EarthRadiusInMiles : GeoConstants.EarthRadiusInKilometers; var dLat = angleConverter.ConvertDegreesToRadians(position2.Latitude) - angleConverter.ConvertDegreesToRadians(position1.Latitude); var dLon = angleConverter.ConvertDegreesToRadians(position2.Longitude) - angleConverter.ConvertDegreesToRadians(position1.Longitude); var a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Cos(angleConverter.ConvertDegreesToRadians(position1.Latitude)) * Math.Cos(angleConverter.ConvertDegreesToRadians(position2.Latitude)) * Math.Sin(dLon / 2) * Math.Sin(dLon / 2); var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); var distance = c * R; return Math.Round(distance, 2); }
private const double WGS84_b = 6356752.3; // Minor semiaxis [m] public static double HaversineDistance(MapPoint pos1, MapPoint pos2, DistanceUnit unit) { double R = (unit == DistanceUnit.Miles) ? 3960 : 6371; var lat = Deg2rad(pos2.Latitude - pos1.Latitude); var lng = Deg2rad(pos2.Longitude - pos1.Longitude); var h1 = Math.Sin(lat / 2) * Math.Sin(lat / 2) + Math.Cos(Deg2rad(pos1.Latitude)) * Math.Cos(Deg2rad(pos2.Latitude)) * Math.Sin(lng / 2) * Math.Sin(lng / 2); var h2 = 2 * Math.Asin(Math.Min(1, Math.Sqrt(h1))); return R * h2; }
internal DistanceForm() { InitializeComponent(); m_Distance = 0.0; m_Repeat = 1; m_Unit = EditingController.Current.EntryUnit; m_CurUnit = m_Unit; m_NewUnit = false; m_WantLine = true; m_WantPoint = true; }
public static double Distance(Posicao pos1, Posicao pos2, DistanceUnit distanceUnit) { double R = (distanceUnit == DistanceUnit.Milhas) ? 3960 : 6371; double dLat = toRadian(pos2.Latitude - pos1.Latitude); double dLon = toRadian(pos2.Longitude - pos1.Longitude); double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Cos(toRadian(pos1.Latitude)) *Math.Cos(toRadian(pos2.Latitude)) * Math.Sin(dLon / 2) * Math.Sin(dLon / 2); double c = 2 * Math.Asin(Math.Min(1, Math.Sqrt(a))); double d = R * c; return d; }
/// <summary> /// Creates a new CoordinateBoundary object /// </summary> /// <param name="latitude">The origin point latitude in decimal notation</param> /// <param name="longitude">The origin point longitude in decimal notation</param> /// <param name="distance">The distance from the origin point in statute miles</param> /// <param name="distanceUnit">The unit of distance</param> public CoordinateBoundaries(double latitude, double longitude, double distance, DistanceUnit distanceUnit) { if (!CoordinateValidator.Validate(latitude, longitude)) throw new ArgumentException("Invalid coordinates supplied."); _latitude = latitude; _longitude = longitude; _distance = distance; _distanceUnit = distanceUnit; Calculate(); }
public GeoDistanceFilterBuilder Distance(double distance, DistanceUnit unit) { if (unit == DistanceUnit.KILOMETERS) { _distance = distance + "km"; } else { _distance = distance + "mi"; } return this; }
public static double HaversineDistance(LatLng coord1, LatLng coord2, DistanceUnit unit) { double R = (unit == DistanceUnit.Miles) ? 3960 : 6371; var lat = (coord2.Latitude - coord1.Latitude).ToRadian(); var lng = (coord2.Longitude - coord1.Longitude).ToRadian(); var h1 = Math.Sin(lat / 2) * Math.Sin(lat / 2) + Math.Cos(coord1.Latitude.ToRadian()) * Math.Cos(coord2.Latitude.ToRadian()) * Math.Sin(lng / 2) * Math.Sin(lng / 2); var h2 = 2 * Math.Asin(Math.Min(1, Math.Sqrt(h1))); return R * h2; }
public static double GetDistance(GeoCoordinate startPoint, GeoCoordinate endPoint, DistanceUnit distanceUnit) { var distanceType = (distanceUnit == DistanceUnit.Miles) ? 3960 : 6371; var distanceLat = ToRadian(endPoint.Latitude - startPoint.Latitude); var distanceLon = ToRadian(endPoint.Longitude - endPoint.Longitude); var a = (Math.Sin(distanceLat / 2) * Math.Sin(distanceLat / 2)) + (Math.Cos(ToRadian(startPoint.Latitude)) * Math.Cos(ToRadian(endPoint.Latitude)) * Math.Sin(distanceLon / 2) * Math.Sin(distanceLon / 2)); var c = 2 * Math.Asin(Math.Min(1, Math.Sqrt(a))); var d = distanceType * c; return d; }
public static double ConvertDistance(double value, DistanceUnit from, DistanceUnit to) { double multiplier = 1; double conversion = 1; if (DistanceUnit.Imperial.ContainsFlag(from)) { switch (from) { case DistanceUnit.Inches: conversion = 0.0254; break; case DistanceUnit.Feet: conversion = 0.3048; break; case DistanceUnit.Yards: conversion = 0.9143999986; break; case DistanceUnit.Miles: conversion = 1609.3440006146; break; } value *= conversion; from = DistanceUnit.Meters; conversion = 1; } switch (from) { case DistanceUnit.Millimeters: multiplier = 10; break; case DistanceUnit.Centimeters: multiplier = 100; break; case DistanceUnit.Decimeters: multiplier = 1000; break; case DistanceUnit.Decameters: multiplier = 0.1; break; case DistanceUnit.Hectometers: multiplier = 0.01; break; case DistanceUnit.Kilometers: multiplier = 0.001; break; } switch (to) { case DistanceUnit.Millimeters: multiplier = 0.1; break; case DistanceUnit.Centimeters: multiplier = 0.01; break; case DistanceUnit.Decimeters: multiplier = 0.001; break; case DistanceUnit.Decameters: multiplier = 10; break; case DistanceUnit.Hectometers: multiplier = 100; break; case DistanceUnit.Kilometers: multiplier = 1000; break; case DistanceUnit.Inches: conversion = 39.3700787; break; case DistanceUnit.Feet: conversion = 3.280839895; break; case DistanceUnit.Yards: conversion = 1.0936133; break; case DistanceUnit.Miles: conversion = 0.000621371192; break; } return value * multiplier * conversion; }
public static double CalcDistance(double Lat1, double Long1, double Lat2, double Long2, DistanceUnit Unit) { /* The Haversine formula according to Dr. Math. http://mathforum.org/library/drmath/view/51879.html dlon = lon2 - lon1 dlat = lat2 - lat1 a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2 c = 2 * atan2(sqrt(a), sqrt(1-a)) d = R * c Where * dlon is the change in longitude * dlat is the change in latitude * c is the great circle distance in Radians. * R is the radius of a spherical Earth. * The locations of the two points in spherical coordinates (longitude and latitude) are lon1,lat1 and lon2, lat2. */ double dDistance = Double.MinValue; double dLat1InRad = Lat1 * (Math.PI / 180.0); double dLong1InRad = Long1 * (Math.PI / 180.0); double dLat2InRad = Lat2 * (Math.PI / 180.0); double dLong2InRad = Long2 * (Math.PI / 180.0); double dLongitude = dLong2InRad - dLong1InRad; double dLatitude = dLat2InRad - dLat1InRad; // Intermediate result a. double a = Math.Pow(Math.Sin(dLatitude / 2.0), 2.0) + Math.Cos(dLat1InRad) * Math.Cos(dLat2InRad) * Math.Pow(Math.Sin(dLongitude / 2.0), 2.0); // Intermediate result c (great circle distance in Radians). double c = 2.0 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1.0 - a)); // Distance. if (Unit == DistanceUnit.Miles) dDistance = kEarthRadiusMiles * c; if (Unit == DistanceUnit.KM) dDistance = kEarthRadiusKms * c; return dDistance; }
/// <summary> /// Initializes a new instance of the <see cref="PathOperation"/> class /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <param name="entryString"></param> internal PathOperation(PointFeature from, PointFeature to, string entryString, DistanceUnit defaultEntryUnit) : base() { m_From = from; m_To = to; m_EntryString = entryString; m_DefaultEntryUnit = defaultEntryUnit; Leg[] legs = PathParser.CreateLegs(m_EntryString, m_DefaultEntryUnit); uint lastId = PrepareLegs(this.EditSequence, legs); EditingController.Current.Project.SetLastItem(lastId); m_Legs = new List<Leg>(legs); }
public static Distance CalculateDistance(GeoLocation pos1, GeoLocation pos2, DistanceUnit unit) // returns KMs between two Geopoints { double r = unit == DistanceUnit.Kilometres ? RKilometres : RMiles; double lat = (pos2.Latitude - pos1.Latitude).ToRadians(); var lng = (pos2.Longitude - pos1.Longitude).ToRadians(); double h1 = Math.Sin(lat/2)*Math.Sin(lat/2) + Math.Cos(ToRadians(pos1.Latitude))*Math.Cos(ToRadians(pos2.Latitude))* Math.Sin(lng/2)*Math.Sin(lng/2); double h2 = 2*Math.Asin(Math.Min(1, Math.Sqrt(h1))); return new Distance(r*h2, unit); }
public static double CalcDistance(string NS1, double Lat1, double Lat1Min, string EW1, double Long1, double Long1Min, string NS2, double Lat2, double Lat2Min, string EW2, double Long2, double Long2Min, DistanceUnit Unit) { double NS1Sign = NS1.ToUpper() == "N" ? 1.0 : -1.0; double EW1Sign = EW1.ToUpper() == "E" ? 1.0 : -1.0; double NS2Sign = NS2.ToUpper() == "N" ? 1.0 : -1.0; double EW2Sign = EW2.ToUpper() == "E" ? 1.0 : -1.0; return (CalcDistance( (Lat1 + (Lat1Min / 60)) * NS1Sign, (Long1 + (Long1Min / 60)) * EW1Sign, (Lat2 + (Lat2Min / 60)) * NS2Sign, (Long2 + (Long2Min / 60)) * EW2Sign , Unit)); }
/// <summary> /// Calculate the rhumb distance between two positions. /// </summary> public double CalculateRhumbDistance(Position position1, Position position2, DistanceUnit distanceUnit) { var R = (distanceUnit == DistanceUnit.Miles) ? GeoConstants.EarthRadiusInMiles : GeoConstants.EarthRadiusInKilometers; var lat1 = angleConverter.ConvertDegreesToRadians(position1.Latitude); var lat2 = angleConverter.ConvertDegreesToRadians(position2.Latitude); var dLat = angleConverter.ConvertDegreesToRadians(position2.Latitude - position1.Latitude); var dLon = angleConverter.ConvertDegreesToRadians(Math.Abs(position2.Longitude - position1.Longitude)); var dPhi = Math.Log(Math.Tan(lat2 / 2 + Math.PI / 4) / Math.Tan(lat1 / 2 + Math.PI / 4)); var q = Math.Cos(lat1); if (dPhi != 0) q = dLat / dPhi; // E-W line gives dPhi=0 // if dLon over 180° take shorter rhumb across 180° meridian: if (dLon > Math.PI) dLon = 2 * Math.PI - dLon; var dist = Math.Sqrt(dLat * dLat + q * q * dLon * dLon) * R; return dist; }
public static DirectionsResponse Directions(double[] origin, double[] destination, DistanceType type, DistanceUnit unit, bool sensor) { string url = APIUrl + "directions/json"; string[] parameters = { "origin", "destination", "mode", "units", "sensor" }; string[] values = { origin[0].ToString() + "," + origin[1].ToString() , destination[0].ToString() + "," + destination[1].ToString(), type.ToString(), unit.ToString(), ((sensor) ? "true" : "false") }; ArrayList headers = new ArrayList(); string response = Utils.Request.ReadResponse(Utils.Request.Get(url, Encoding.UTF8, parameters, values, headers), Encoding.UTF8); DirectionsResponse dr = jss.Deserialize<DirectionsResponse>(response); return dr; }
public RadiusMearsureTrackInteractiveOverlay(DistanceUnit distanceUnit, GeographyUnit mapUnit) { DistanceUnit = distanceUnit; MapUnit = mapUnit; textBlock = new TextBlock(); textBlock.Visibility = Visibility.Collapsed; OverlayCanvas.Children.Add(textBlock); PolygonTrackMode = PolygonTrackMode.LineWithFill; RenderMode = RenderMode.DrawingVisual; areaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(80, GeoColor.SimpleColors.LightGreen), GeoColor.SimpleColors.White, 2); pointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.SimpleColors.DarkBlue, 8); lineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.SimpleColors.White, 3, true); SetStylesForInMemoryFeatureLayer(TrackShapeLayer); SetStylesForInMemoryFeatureLayer(TrackShapesInProcessLayer); }
public static double CalculateAproxDistance(double[] origin, double[] destination, DistanceUnit unit) { const double km_factor = 1.609344; const double m_factor = 69.09; double distance = Math.Sin(DegToRad(origin[0])) * Math.Sin(DegToRad(destination[0])) + Math.Cos(DegToRad(origin[0])) * Math.Cos(DegToRad(destination[0])) * Math.Cos(DegToRad(origin[1] - destination[1])); double degree = RadToDeg(Math.Acos(distance)); double miles = degree * m_factor; double km = miles * km_factor; if (unit == DistanceUnit.imperial) { return Math.Round(miles, 2); } else { return Math.Round(km, 2); } }
public static void Reload() { RealtimeCSG.CSGSettings.LockAxisX = EditorPrefs.GetBool("LockAxisX", false); RealtimeCSG.CSGSettings.LockAxisY = EditorPrefs.GetBool("LockAxisY", false); RealtimeCSG.CSGSettings.LockAxisZ = EditorPrefs.GetBool("LockAxisZ", false); RealtimeCSG.CSGSettings.UniformGrid = EditorPrefs.GetBool("UniformGrid", true); RealtimeCSG.CSGSettings.EditMode = (ToolEditMode)EditorPrefs.GetInt("EditMode", (int)ToolEditMode.Generate); var moveSnapVector = new Vector3(EditorPrefs.GetFloat("MoveSnapX", 1.0f), EditorPrefs.GetFloat("MoveSnapY", 1.0f), EditorPrefs.GetFloat("MoveSnapZ", 1.0f)); RealtimeCSG.CSGSettings.SnapVector = moveSnapVector; var moveOffsetVector = new Vector3(EditorPrefs.GetFloat("DefaultMoveOffsetX", 0.0f), EditorPrefs.GetFloat("DefaultMoveOffsetY", 0.0f), EditorPrefs.GetFloat("DefaultMoveOffsetZ", 0.0f)); RealtimeCSG.CSGSettings.DefaultMoveOffset = moveOffsetVector; var rotateOffsetVector = new Vector3(EditorPrefs.GetFloat("DefaultRotateOffsetX", 0.0f), EditorPrefs.GetFloat("DefaultRotateOffsetY", 0.0f), EditorPrefs.GetFloat("DefaultRotateOffsetZ", 0.0f)); RealtimeCSG.CSGSettings.DefaultRotateOffset = rotateOffsetVector; RealtimeCSG.CSGSettings.ShapeBuildMode = (ShapeMode)EditorPrefs.GetInt("ShapeBuildMode", (int)ShapeMode.Box); RealtimeCSG.CSGSettings.GridVisible = EditorPrefs.GetBool("ShowGrid", true); RealtimeCSG.CSGSettings.SnapToGrid = EditorPrefs.GetBool("ForceSnapToGrid", true); var helperSurfaces = (HelperSurfaceFlags)EditorPrefs.GetInt("HelperSurfaces", (int)DefaultHelperSurfaceFlags); RealtimeCSG.CSGSettings.VisibleHelperSurfaces = helperSurfaces; RealtimeCSG.CSGSettings.ClipMode = (ClipMode)EditorPrefs.GetInt("ClipMode", 0); RealtimeCSG.CSGSettings.EnableRealtimeCSG = EditorPrefs.GetBool("EnableRealtimeCSG", true); var defaultMaterialGUID = EditorPrefs.GetString("DefaultMaterial", null); if (defaultMaterialGUID != null) { var defaultMaterialAssetPath = AssetDatabase.GUIDToAssetPath(defaultMaterialGUID); var materialFromID = AssetDatabase.LoadAssetAtPath <Material>(defaultMaterialAssetPath); if (materialFromID) { DefaultMaterial = materialFromID; } else { DefaultMaterial = MaterialUtility.WallMaterial; } } else { DefaultMaterial = MaterialUtility.WallMaterial; } RealtimeCSG.CSGSettings.SnapScale = EditorPrefs.GetFloat("ScaleSnap", 0.1f); RealtimeCSG.CSGSettings.SnapRotation = EditorPrefs.GetFloat("RotationSnap", 15.0f); RealtimeCSG.CSGSettings.DefaultShapeHeight = EditorPrefs.GetFloat("DefaultShapeHeight", 1.0f); RealtimeCSG.CSGSettings.CurveSides = (uint)EditorPrefs.GetInt("CurveSides", 10); CircleSides = Mathf.Max(3, EditorPrefs.GetInt("CircleSides", 18)); CircleOffset = EditorPrefs.GetFloat("CircleOffset", 0); CircleSmoothShading = EditorPrefs.GetBool("CircleSmoothShading", true); CircleSingleSurfaceEnds = EditorPrefs.GetBool("CircleSingleSurfaceEnds", true); CircleDistanceToSide = EditorPrefs.GetBool("CircleDistanceToSide", true); CircleRecenter = EditorPrefs.GetBool("CircleRecenter", true); SphereSplits = Mathf.Max(1, EditorPrefs.GetInt("SphereSplits", 1)); SphereOffset = EditorPrefs.GetFloat("SphereOffset", 0); SphereSmoothShading = EditorPrefs.GetBool("SphereSmoothShading", true); SphereDistanceToSide = EditorPrefs.GetBool("SphereDistanceToSide", true); HemiSphereMode = EditorPrefs.GetBool("HemiSphereMode", false); LinearStairsStepLength = EditorPrefs.GetFloat("LinearStairsStepLength", 0.30f); LinearStairsStepHeight = EditorPrefs.GetFloat("LinearStairsStepHeight", 0.20f); LinearStairsStepWidth = EditorPrefs.GetFloat("LinearStairsStepWidth", 1.0f); LinearStairsTotalSteps = EditorPrefs.GetInt("LinearStairsTotalSteps", 4); LinearStairsLength = EditorPrefs.GetFloat("LinearStairsLength", 16.0f); LinearStairsHeight = EditorPrefs.GetFloat("LinearStairsHeight", 16.0f); LinearStairsLengthOffset = EditorPrefs.GetFloat("LinearStairsLengthOffset", 0.0f); LinearStairsHeightOffset = EditorPrefs.GetFloat("LinearStairsHeightOffset", 0.0f); var distanceUnit = (DistanceUnit)EditorPrefs.GetInt("DistanceUnit", (int)DistanceUnit.Meters); RealtimeCSG.CSGSettings.DistanceUnit = distanceUnit; var sceneViews = SortedSceneViews(); EnsureValidSceneviewNames(sceneViews); var arrayString = EditorPrefs.GetString("Wireframe", string.Empty); if (arrayString.Contains(',')) { LegacyLoadWireframeSettings(sceneViews, arrayString); } else { LoadWireframeSettings(sceneViews, arrayString); } UpdateSnapSettings(); }
public Distance(double value, DistanceUnit unit) { Value = value; Unit = unit; }
public Distance(double distance, DistanceUnit unit) { Precision = distance; Unit = unit; }
/// <summary> /// Convert the current value from 'fromUnit' to 'toUnit' /// </summary> public static float Convert(this float value, DistanceUnit fromUnit, DistanceUnit toUnit) { return(FingerGestures.Convert(value, fromUnit, toUnit)); }
public GeoShapePropertyDescriptor <T> Precision(double precision, DistanceUnit unit) => Assign(a => a.Precision = new Distance(precision, unit));
public GeoDistanceQueryDescriptor <T> Distance(double distance, DistanceUnit unit) => Assign(a => a.Distance = new Distance(distance, unit));
static void OnBottomBarGUI(SceneView sceneView, Rect barSize) { //if (Event.current.type == EventType.Layout) // return; var snapMode = RealtimeCSG.CSGSettings.SnapMode; var uniformGrid = RealtimeCSG.CSGSettings.UniformGrid; var moveSnapVector = RealtimeCSG.CSGSettings.SnapVector; var rotationSnap = RealtimeCSG.CSGSettings.SnapRotation; var scaleSnap = RealtimeCSG.CSGSettings.SnapScale; var showGrid = RealtimeCSG.CSGSettings.GridVisible; var lockAxisX = RealtimeCSG.CSGSettings.LockAxisX; var lockAxisY = RealtimeCSG.CSGSettings.LockAxisY; var lockAxisZ = RealtimeCSG.CSGSettings.LockAxisZ; var distanceUnit = RealtimeCSG.CSGSettings.DistanceUnit; var helperSurfaces = RealtimeCSG.CSGSettings.VisibleHelperSurfaces; var showWireframe = RealtimeCSG.CSGSettings.IsWireframeShown(sceneView); var skin = CSG_GUIStyleUtility.Skin; var updateSurfaces = false; bool wireframeModified = false; var viewWidth = sceneView.position.width; float layoutHeight = barSize.height; float layoutX = 6.0f; bool modified = false; GUI.changed = false; { currentRect.width = 27; currentRect.y = 0; currentRect.height = layoutHeight - currentRect.y; currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; #region "Grid" button if (showGrid) { showGrid = GUI.Toggle(currentRect, showGrid, skin.gridIconOn, EditorStyles.toolbarButton); } else { showGrid = GUI.Toggle(currentRect, showGrid, skin.gridIcon, EditorStyles.toolbarButton); } //(x:6.00, y:0.00, width:27.00, height:18.00) TooltipUtility.SetToolTip(showGridTooltip, currentRect); #endregion if (viewWidth >= 800) { layoutX += 6; //(x:33.00, y:0.00, width:6.00, height:6.00) } var prevBackgroundColor = GUI.backgroundColor; var lockedBackgroundColor = skin.lockedBackgroundColor; if (lockAxisX) { GUI.backgroundColor = lockedBackgroundColor; } #region "X" lock button currentRect.width = 17; currentRect.y = 0; currentRect.height = layoutHeight - currentRect.y; currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; lockAxisX = !GUI.Toggle(currentRect, !lockAxisX, xLabel, skin.xToolbarButton); //(x:39.00, y:0.00, width:17.00, height:18.00) if (lockAxisX) { TooltipUtility.SetToolTip(xTooltipOn, currentRect); } else { TooltipUtility.SetToolTip(xTooltipOff, currentRect); } GUI.backgroundColor = prevBackgroundColor; #endregion #region "Y" lock button currentRect.x = layoutX; layoutX += currentRect.width; if (lockAxisY) { GUI.backgroundColor = lockedBackgroundColor; } lockAxisY = !GUI.Toggle(currentRect, !lockAxisY, yLabel, skin.yToolbarButton); //(x:56.00, y:0.00, width:17.00, height:18.00) if (lockAxisY) { TooltipUtility.SetToolTip(yTooltipOn, currentRect); } else { TooltipUtility.SetToolTip(yTooltipOff, currentRect); } GUI.backgroundColor = prevBackgroundColor; #endregion #region "Z" lock button currentRect.x = layoutX; layoutX += currentRect.width; if (lockAxisZ) { GUI.backgroundColor = lockedBackgroundColor; } lockAxisZ = !GUI.Toggle(currentRect, !lockAxisZ, zLabel, skin.zToolbarButton); //(x:56.00, y:0.00, width:17.00, height:18.00) if (lockAxisZ) { TooltipUtility.SetToolTip(zTooltipOn, currentRect); } else { TooltipUtility.SetToolTip(zTooltipOff, currentRect); } GUI.backgroundColor = prevBackgroundColor; #endregion } modified = GUI.changed || modified; if (viewWidth >= 800) { layoutX += 6; // (x:91.00, y:0.00, width:6.00, height:6.00) } #region "SnapMode" button GUI.changed = false; { currentRect.width = 27; currentRect.y = 0; currentRect.height = layoutHeight - currentRect.y; currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; switch (snapMode) { case SnapMode.GridSnapping: { var newValue = GUI.Toggle(currentRect, snapMode == SnapMode.GridSnapping, CSG_GUIStyleUtility.Skin.gridSnapIconOn, EditorStyles.toolbarButton); if (GUI.changed) { snapMode = newValue ? SnapMode.GridSnapping : SnapMode.RelativeSnapping; //Debug.Log($"SnapMode.GridSnapping {snapMode}"); } //(x:97.00, y:0.00, width:27.00, height:18.00) TooltipUtility.SetToolTip(gridSnapModeTooltip, currentRect); break; } case SnapMode.RelativeSnapping: { var newValue = GUI.Toggle(currentRect, snapMode == SnapMode.RelativeSnapping, CSG_GUIStyleUtility.Skin.relSnapIconOn, EditorStyles.toolbarButton); if (GUI.changed) { snapMode = newValue ? SnapMode.RelativeSnapping : SnapMode.None; //Debug.Log($"SnapMode.RelativeSnapping {snapMode}"); } //(x:97.00, y:0.00, width:27.00, height:18.00) TooltipUtility.SetToolTip(relativeSnapModeTooltip, currentRect); break; } default: case SnapMode.None: { var newValue = GUI.Toggle(currentRect, snapMode != SnapMode.None, CSG_GUIStyleUtility.Skin.noSnapIconOn, EditorStyles.toolbarButton); if (GUI.changed) { snapMode = newValue ? SnapMode.GridSnapping : SnapMode.None; //Debug.Log($"SnapMode.None {snapMode}"); } //(x:97.00, y:0.00, width:27.00, height:18.00) TooltipUtility.SetToolTip(noSnappingModeTooltip, currentRect); break; } } } modified = GUI.changed || modified; #endregion if (viewWidth >= 460) { if (snapMode != SnapMode.None) { #region "Position" label if (viewWidth >= 500) { if (viewWidth >= 865) { currentRect.width = 44; currentRect.y = 1; currentRect.height = layoutHeight - currentRect.y; currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; uniformGrid = GUI.Toggle(currentRect, uniformGrid, positionLargeLabel, miniTextStyle); //(x:128.00, y:2.00, width:44.00, height:16.00) TooltipUtility.SetToolTip(positionTooltip, currentRect); } else { currentRect.width = 22; currentRect.y = 1; currentRect.height = layoutHeight - currentRect.y; currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; uniformGrid = GUI.Toggle(currentRect, uniformGrid, positionSmallLabel, miniTextStyle); //(x:127.00, y:2.00, width:22.00, height:16.00) TooltipUtility.SetToolTip(positionTooltip, currentRect); } } #endregion layoutX += 2; #region "Position" field if (uniformGrid || viewWidth < 515) { EditorGUI.showMixedValue = !(moveSnapVector.x == moveSnapVector.y && moveSnapVector.x == moveSnapVector.z); GUI.changed = false; { currentRect.width = 70; currentRect.y = 3; currentRect.height = layoutHeight - (currentRect.y - 1); currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; moveSnapVector.x = Units.DistanceUnitToUnity(distanceUnit, EditorGUI.DoubleField(currentRect, Units.UnityToDistanceUnit(distanceUnit, moveSnapVector.x), textInputStyle)); //, MinSnapWidth, MaxSnapWidth)); //(x:176.00, y:3.00, width:70.00, height:16.00) } if (GUI.changed) { modified = true; moveSnapVector.y = moveSnapVector.x; moveSnapVector.z = moveSnapVector.x; } EditorGUI.showMixedValue = false; } else { GUI.changed = false; { currentRect.width = 70; currentRect.y = 3; currentRect.height = layoutHeight - (currentRect.y - 1); currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; layoutX++; moveSnapVector.x = Units.DistanceUnitToUnity(distanceUnit, EditorGUI.DoubleField(currentRect, Units.UnityToDistanceUnit(distanceUnit, moveSnapVector.x), textInputStyle)); //, MinSnapWidth, MaxSnapWidth)); //(x:175.00, y:3.00, width:70.00, height:16.00) currentRect.x = layoutX; layoutX += currentRect.width; layoutX++; moveSnapVector.y = Units.DistanceUnitToUnity(distanceUnit, EditorGUI.DoubleField(currentRect, Units.UnityToDistanceUnit(distanceUnit, moveSnapVector.y), textInputStyle)); //, MinSnapWidth, MaxSnapWidth)); //(x:247.00, y:3.00, width:70.00, height:16.00) currentRect.x = layoutX; layoutX += currentRect.width; moveSnapVector.z = Units.DistanceUnitToUnity(distanceUnit, EditorGUI.DoubleField(currentRect, Units.UnityToDistanceUnit(distanceUnit, moveSnapVector.z), textInputStyle)); //, MinSnapWidth, MaxSnapWidth)); //(x:319.00, y:3.00, width:70.00, height:16.00) } modified = GUI.changed || modified; } #endregion layoutX++; #region "Position" Unit DistanceUnit nextUnit = Units.CycleToNextUnit(distanceUnit); GUIContent unitText = Units.GetUnitGUIContent(distanceUnit); currentRect.width = 22; currentRect.y = 2; currentRect.height = layoutHeight - currentRect.y; currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; if (GUI.Button(currentRect, unitText, miniTextStyle)) //(x:393.00, y:2.00, width:13.00, height:16.00) { distanceUnit = nextUnit; modified = true; } #endregion layoutX += 2; #region "Position" +/- if (viewWidth >= 700) { currentRect.width = 19; currentRect.y = 2; currentRect.height = layoutHeight - (currentRect.y + 1); currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; if (GUI.Button(currentRect, positionPlusLabel, EditorStyles.miniButtonLeft)) { GridUtility.DoubleGridSize(); moveSnapVector = RealtimeCSG.CSGSettings.SnapVector; } //(x:410.00, y:2.00, width:19.00, height:15.00) TooltipUtility.SetToolTip(positionPlusTooltip, currentRect); currentRect.width = 17; currentRect.y = 2; currentRect.height = layoutHeight - (currentRect.y + 1); currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; if (GUI.Button(currentRect, positionMinusLabel, EditorStyles.miniButtonRight)) { GridUtility.HalfGridSize(); moveSnapVector = RealtimeCSG.CSGSettings.SnapVector; } //(x:429.00, y:2.00, width:17.00, height:15.00) TooltipUtility.SetToolTip(positionMinnusTooltip, currentRect); } #endregion layoutX += 2; #region "Angle" label if (viewWidth >= 750) { if (viewWidth >= 865) { currentRect.width = 31; currentRect.y = 1; currentRect.height = layoutHeight - currentRect.y; currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; GUI.Label(currentRect, angleLargeLabel, miniTextStyle); //(x:450.00, y:2.00, width:31.00, height:16.00) } else { currentRect.width = 22; currentRect.y = 1; currentRect.height = layoutHeight - currentRect.y; currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; GUI.Label(currentRect, angleSmallLabel, miniTextStyle); //(x:355.00, y:2.00, width:22.00, height:16.00) } TooltipUtility.SetToolTip(angleTooltip, currentRect); } #endregion layoutX += 2; #region "Angle" field GUI.changed = false; { currentRect.width = 70; currentRect.y = 3; currentRect.height = layoutHeight - (currentRect.y - 1); currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; rotationSnap = EditorGUI.FloatField(currentRect, rotationSnap, textInputStyle); //, MinSnapWidth, MaxSnapWidth); //(x:486.00, y:3.00, width:70.00, height:16.00) if (viewWidth <= 750) { TooltipUtility.SetToolTip(angleTooltip, currentRect); } } modified = GUI.changed || modified; #endregion layoutX++; #region "Angle" Unit if (viewWidth >= 370) { currentRect.width = 14; currentRect.y = 1; currentRect.height = layoutHeight - currentRect.y; currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; GUI.Label(currentRect, angleUnitLabel, miniTextStyle); } #endregion layoutX += 2; #region "Angle" +/- if (viewWidth >= 700) { currentRect.width = 19; currentRect.y = 1; currentRect.height = layoutHeight - (currentRect.y + 1); currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; if (GUI.Button(currentRect, anglePlusLabel, EditorStyles.miniButtonLeft)) { rotationSnap *= 2.0f; modified = true; } //(x:573.00, y:2.00, width:19.00, height:15.00) TooltipUtility.SetToolTip(anglePlusTooltip, currentRect); currentRect.width = 17; currentRect.y = 1; currentRect.height = layoutHeight - (currentRect.y + 1); currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; if (GUI.Button(currentRect, angleMinusLabel, EditorStyles.miniButtonRight)) { rotationSnap /= 2.0f; modified = true; } //(x:592.00, y:2.00, width:17.00, height:15.00) TooltipUtility.SetToolTip(angleMinnusTooltip, currentRect); } #endregion layoutX += 2; #region "Scale" label if (viewWidth >= 750) { if (viewWidth >= 865) { currentRect.width = 31; currentRect.y = 1; currentRect.height = layoutHeight - currentRect.y; currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; GUI.Label(currentRect, scaleLargeLabel, miniTextStyle); //(x:613.00, y:2.00, width:31.00, height:16.00) } else { currentRect.width = 19; currentRect.y = 1; currentRect.height = layoutHeight - currentRect.y; currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; GUI.Label(currentRect, scaleSmallLabel, miniTextStyle); //(x:495.00, y:2.00, width:19.00, height:16.00) } TooltipUtility.SetToolTip(scaleTooltip, currentRect); } #endregion layoutX += 2; #region "Scale" field GUI.changed = false; { currentRect.width = 70; currentRect.y = 3; currentRect.height = layoutHeight - (currentRect.y - 1); currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; scaleSnap = EditorGUI.FloatField(currentRect, scaleSnap, textInputStyle); //, MinSnapWidth, MaxSnapWidth); //(x:648.00, y:3.00, width:70.00, height:16.00) if (viewWidth <= 750) { TooltipUtility.SetToolTip(scaleTooltip, currentRect); } } modified = GUI.changed || modified; #endregion layoutX++; #region "Scale" Unit if (viewWidth >= 370) { currentRect.width = 15; currentRect.y = 1; currentRect.height = layoutHeight - currentRect.y; currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; GUI.Label(currentRect, scaleUnitLabel, miniTextStyle); //(x:722.00, y:2.00, width:15.00, height:16.00) } #endregion layoutX += 2; #region "Scale" +/- if (viewWidth >= 700) { currentRect.width = 19; currentRect.y = 2; currentRect.height = layoutHeight - (currentRect.y + 1); currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; if (GUI.Button(currentRect, scalePlusLabel, EditorStyles.miniButtonLeft)) { scaleSnap *= 10.0f; modified = true; } //(x:741.00, y:2.00, width:19.00, height:15.00) TooltipUtility.SetToolTip(scalePlusTooltip, currentRect); currentRect.width = 17; currentRect.y = 2; currentRect.height = layoutHeight - (currentRect.y + 1); currentRect.y += barSize.y; currentRect.x = layoutX; layoutX += currentRect.width; if (GUI.Button(currentRect, scaleMinusLabel, EditorStyles.miniButtonRight)) { scaleSnap /= 10.0f; modified = true; } //(x:760.00, y:2.00, width:17.00, height:15.00) TooltipUtility.SetToolTip(scaleMinnusTooltip, currentRect); } #endregion } } var prevLayoutX = layoutX; layoutX = viewWidth; #region "Rebuild" currentRect.width = 27; currentRect.y = 0; currentRect.height = layoutHeight - currentRect.y; currentRect.y += barSize.y; layoutX -= currentRect.width; currentRect.x = layoutX; if (GUI.Button(currentRect, CSG_GUIStyleUtility.Skin.rebuildIcon, EditorStyles.toolbarButton)) { Debug.Log("Starting complete rebuild"); var text = new System.Text.StringBuilder(); MaterialUtility.ResetMaterialTypeLookup(); InternalCSGModelManager.skipCheckForChanges = true; RealtimeCSG.CSGSettings.Reload(); UnityCompilerDefineManager.UpdateUnityDefines(); InternalCSGModelManager.registerTime = 0.0; InternalCSGModelManager.validateTime = 0.0; InternalCSGModelManager.hierarchyValidateTime = 0.0; InternalCSGModelManager.updateHierarchyTime = 0.0; var startTime = EditorApplication.timeSinceStartup; InternalCSGModelManager.ForceRebuildAll(); InternalCSGModelManager.OnHierarchyModified(); var hierarchy_update_endTime = EditorApplication.timeSinceStartup; text.AppendFormat(CultureInfo.InvariantCulture, "Full hierarchy rebuild in {0:F} ms. ", (hierarchy_update_endTime - startTime) * 1000); NativeMethodBindings.RebuildAll(); var csg_endTime = EditorApplication.timeSinceStartup; text.AppendFormat(CultureInfo.InvariantCulture, "Full CSG rebuild done in {0:F} ms. ", (csg_endTime - hierarchy_update_endTime) * 1000); InternalCSGModelManager.RemoveForcedUpdates(); // we already did this in rebuild all InternalCSGModelManager.UpdateMeshes(text, forceUpdate: true); updateSurfaces = true; UpdateLoop.ResetUpdateRoutine(); RealtimeCSG.CSGSettings.Save(); InternalCSGModelManager.skipCheckForChanges = false; var scenes = new HashSet <UnityEngine.SceneManagement.Scene>(); foreach (var model in InternalCSGModelManager.Models) { scenes.Add(model.gameObject.scene); } foreach (var scene in scenes) { UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(scene); } text.AppendFormat(CultureInfo.InvariantCulture, "{0} brushes. ", Foundation.CSGManager.TreeBrushCount); Debug.Log(text.ToString()); } //(x:1442.00, y:0.00, width:27.00, height:18.00) TooltipUtility.SetToolTip(rebuildTooltip, currentRect); #endregion if (viewWidth >= 800) { layoutX -= 6; //(x:1436.00, y:0.00, width:6.00, height:6.00) } #region "Helper Surface Flags" Mask if (viewWidth >= 250) { GUI.changed = false; { prevLayoutX += 8; // extra space prevLayoutX += 26; // width of "Show wireframe" button currentRect.width = Mathf.Max(20, Mathf.Min(165, (viewWidth - prevLayoutX - currentRect.width))); currentRect.y = 0; currentRect.height = layoutHeight - currentRect.y; currentRect.y += barSize.y; layoutX -= currentRect.width; currentRect.x = layoutX; SurfaceVisibilityPopup.Button(currentRect); //(x:1267.00, y:2.00, width:165.00, height:16.00) TooltipUtility.SetToolTip(helperSurfacesTooltip, currentRect); } if (GUI.changed) { updateSurfaces = true; modified = true; } } #endregion #region "Show wireframe" button GUI.changed = false; currentRect.width = 26; currentRect.y = 0; currentRect.height = layoutHeight - currentRect.y; currentRect.y += barSize.y; layoutX -= currentRect.width; currentRect.x = layoutX; if (showWireframe) { showWireframe = GUI.Toggle(currentRect, showWireframe, CSG_GUIStyleUtility.Skin.wireframe, EditorStyles.toolbarButton); //(x:1237.00, y:0.00, width:26.00, height:18.00) } else { showWireframe = GUI.Toggle(currentRect, showWireframe, CSG_GUIStyleUtility.Skin.wireframeOn, EditorStyles.toolbarButton); //(x:1237.00, y:0.00, width:26.00, height:18.00) } TooltipUtility.SetToolTip(showWireframeTooltip, currentRect); if (GUI.changed) { wireframeModified = true; modified = true; } #endregion #region Capture mouse clicks in empty space var mousePoint = Event.current.mousePosition; int controlID = GUIUtility.GetControlID(BottomBarEditorOverlayHash, FocusType.Passive, barSize); switch (Event.current.GetTypeForControl(controlID)) { case EventType.MouseDown: { if (barSize.Contains(mousePoint)) { GUIUtility.hotControl = controlID; GUIUtility.keyboardControl = controlID; Event.current.Use(); } break; } case EventType.MouseMove: { if (barSize.Contains(mousePoint)) { Event.current.Use(); } break; } case EventType.MouseUp: { if (GUIUtility.hotControl == controlID) { GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; Event.current.Use(); } break; } case EventType.MouseDrag: { if (GUIUtility.hotControl == controlID) { Event.current.Use(); } break; } case EventType.ScrollWheel: { if (barSize.Contains(mousePoint)) { Event.current.Use(); } break; } } #endregion #region Store modified values rotationSnap = Mathf.Max(1.0f, Mathf.Abs((360 + (rotationSnap % 360))) % 360); moveSnapVector.x = Mathf.Max(1.0f / 1024.0f, moveSnapVector.x); moveSnapVector.y = Mathf.Max(1.0f / 1024.0f, moveSnapVector.y); moveSnapVector.z = Mathf.Max(1.0f / 1024.0f, moveSnapVector.z); scaleSnap = Mathf.Max(MathConstants.MinimumScale, scaleSnap); RealtimeCSG.CSGSettings.SnapMode = snapMode; RealtimeCSG.CSGSettings.SnapVector = moveSnapVector; RealtimeCSG.CSGSettings.SnapRotation = rotationSnap; RealtimeCSG.CSGSettings.SnapScale = scaleSnap; RealtimeCSG.CSGSettings.UniformGrid = uniformGrid; // RealtimeCSG.Settings.SnapVertex = vertexSnap; RealtimeCSG.CSGSettings.GridVisible = showGrid; RealtimeCSG.CSGSettings.LockAxisX = lockAxisX; RealtimeCSG.CSGSettings.LockAxisY = lockAxisY; RealtimeCSG.CSGSettings.LockAxisZ = lockAxisZ; RealtimeCSG.CSGSettings.DistanceUnit = distanceUnit; RealtimeCSG.CSGSettings.VisibleHelperSurfaces = helperSurfaces; if (wireframeModified) { RealtimeCSG.CSGSettings.SetWireframeShown(sceneView, showWireframe); } if (updateSurfaces) { MeshInstanceManager.UpdateHelperSurfaceVisibility(force: true); } if (modified) { GUI.changed = true; RealtimeCSG.CSGSettings.UpdateSnapSettings(); RealtimeCSG.CSGSettings.Save(); CSG_EditorGUIUtility.UpdateSceneViews(); } #endregion }
public static double GetCellWidthByLevel(RectangleShape extent, GeographyUnit extentMapUnit, int level, DistanceUnit returnDistanceUnit) { PointShape centerPoint = extent.GetCenterPoint(); PointShape centerLeft = new PointShape(extent.LowerLeftPoint.X, centerPoint.Y); PointShape centerRight = new PointShape(extent.UpperRightPoint.X, centerPoint.Y); PointShape centerUpper = new PointShape(centerPoint.X, extent.UpperLeftPoint.Y); PointShape centerLower = new PointShape(centerPoint.X, extent.LowerLeftPoint.Y); double centerWidth = centerLeft.GetDistanceTo(centerRight, extentMapUnit, returnDistanceUnit); double centerHeight = centerUpper.GetDistanceTo(centerLower, extentMapUnit, returnDistanceUnit); double longestEdge = Math.Max(centerWidth, centerHeight); double cellWidth = longestEdge / Math.Sqrt(Math.Pow(4, level - 1)); return(cellWidth); }
public static int GetLevelByCellWidth(RectangleShape extent, GeographyUnit extentMapUnit, double cellWidth, DistanceUnit widthDistanceUnit) { PointShape centerPoint = extent.GetCenterPoint(); PointShape centerLeft = new PointShape(extent.LowerLeftPoint.X, centerPoint.Y); PointShape centerRight = new PointShape(extent.UpperRightPoint.X, centerPoint.Y); PointShape centerUpper = new PointShape(centerPoint.X, extent.UpperLeftPoint.Y); PointShape centerLower = new PointShape(centerPoint.X, extent.LowerLeftPoint.Y); double centerWidth = centerLeft.GetDistanceTo(centerRight, extentMapUnit, widthDistanceUnit); double centerHeight = centerUpper.GetDistanceTo(centerLower, extentMapUnit, widthDistanceUnit); double longestEdge = Math.Max(centerWidth, centerHeight); double level = Math.Round(2 * Math.Log((longestEdge / cellWidth), 4) + 1); return (int)level; }
/// <summary> /// <para>BDC on the specified canvas</para> /// <para>Call this method after drawing the reticle</para> /// <para>NOTE: BDC puts the distance at the next trajectory point after the trajectory crossed the BDC level. So, for acceptable precision, the trajectory step must be equal or less than 25 yards.</para> /// </summary> /// <param name="trajectory">The trajectory to get the BDC parameters</param> /// <param name="zero">The Zero distance</param> /// <param name="closeBdc">The flag indicating whether BDC point should take distance closer than zero (`true`) or more far than zero (`false`)</param> /// <param name="units">The units of the distance for BDC labels</param> /// <param name="color">The text color for BDC labels</param> public void DrawBulletDropCompensator(IEnumerable <TrajectoryPoint> trajectory, Measurement <DistanceUnit> zero, bool closeBdc, DistanceUnit units, string color) { foreach (var bdc in CalculateBdc(reticle, trajectory, zero, closeBdc, units, color)) { DrawElement(bdc); } }
/// <summary> /// Convert the current pixel-distance based value to the desired unit /// </summary> public static float In(this float valueInPixels, DistanceUnit toUnit) { return(valueInPixels.Convert(DistanceUnit.Pixels, toUnit)); }
/// <summary> /// Sort result by geo distance using specified field. /// There can be several Sort parameters (order is important). /// </summary> /// <param name="field">The field.</param> /// <param name="geohash">The geohash.</param> /// <param name="unit">The distance unit.</param> /// <param name="order">The sort order. By default results will be sorted ascending.</param> public Sort <T> GeoDistance(string field, string geohash, DistanceUnit unit, SortDirection order = SortDirection.@default) { string geoField = "'{0}.location': '{1}'".AltQuoteF(field, geohash); return(AddGeoDistancePart(geoField, unit, order)); }
private IEnumerable <ReticleElement> CalculateBdc(ReticleDefinition reticle, IEnumerable <TrajectoryPoint> trajectory, Measurement <DistanceUnit> zero, bool closeBdc, DistanceUnit distanceUnits, string color) { TrajectoryPoint previousPoint = null; foreach (var point in trajectory) { if (!closeBdc && point.Distance < zero) { previousPoint = point; continue; } if (closeBdc && point.Distance >= zero) { break; } if (previousPoint != null) { foreach (var bdcPoint in reticle.BulletDropCompensator) { if ((previousPoint.DropAdjustment >= bdcPoint.Position.Y && point.DropAdjustment <= bdcPoint.Position.Y) || (previousPoint.DropAdjustment <= bdcPoint.Position.Y && point.DropAdjustment >= bdcPoint.Position.Y)) { var x = bdcPoint.Position.X + bdcPoint.TextOffset; var y = bdcPoint.Position.Y - bdcPoint.TextHeight / 2; yield return(new ReticleText() { Position = new ReticlePosition() { X = x, Y = y }, TextHeight = bdcPoint.TextHeight, Text = Math.Round(point.Distance.In(distanceUnits)).ToString(), Color = color, }); } } } previousPoint = point; } }
public static GUIContent GetUnitGUIContent(DistanceUnit unit) { return(distanceUnitGUIContent[(int)unit]); }
/// <summary> /// Formats this distance in a specific unit of measurement. /// </summary> /// <param name="unit">The desired unit of measurement.</param> /// <param name="appendAbbrev">True if units abbreviation should be appended (default was TRUE)</param> /// <returns></returns> internal string Format(DistanceUnit unit, bool appendAbbrev) { return(unit.Format(m_ObservedMetric, appendAbbrev)); }
/// <summary> /// Sort result by geo distance using specified field. /// There can be several Sort parameters (order is important). /// </summary> /// <param name="field">The field.</param> /// <param name="lat">The latitude.</param> /// <param name="lon">The longitude.</param> /// <param name="unit">The distance unit.</param> /// <param name="order">The sort order. By default results will be sorted ascending.</param> public Sort <T> GeoDistance(string field, double lat, double lon, DistanceUnit unit, SortDirection order = SortDirection.@default) { string geoField = "'{0}': {{ 'lat': {1},'lon': {2} }}".AltQuoteF(field, lat.AsString(), lon.AsString()); return(AddGeoDistancePart(geoField, unit, order)); }
public GeoDistanceQueryDescriptor <T> Distance(double distance, DistanceUnit unit) => Assign(new Distance(distance, unit), (a, v) => a.Distance = v);
/// <summary> /// Sort result by geo distance using specified field. /// There can be several Sort parameters (order is important). /// </summary> /// <param name="field">The field.</param> /// <param name="geohash">The geohash.</param> /// <param name="unit">The distance unit.</param> /// <param name="order">The sort order. By default results will be sorted ascending.</param> public Sort <T> GeoDistance(Expression <Func <T, object> > field, string geohash, DistanceUnit unit, SortDirection order = SortDirection.@default) { var fieldName = field.GetPropertyPath(); return(GeoDistance(fieldName, geohash, unit, order)); }
/// <summary> /// Returns this distance in a specific type of unit. /// </summary> /// <param name="unit">The desired unit of measurement.</param> /// <returns></returns> double GetDistance(DistanceUnit unit) { return(unit.FromMetric(m_ObservedMetric)); }
// convert a 2D motion vector from one distance unit to another one public static Vector2 Convert(Vector2 v, DistanceUnit fromUnit, DistanceUnit toUnit) { return(new Vector2(Convert(v.x, fromUnit, toUnit), Convert(v.y, fromUnit, toUnit))); }
/// <summary> /// Obtains a string that corresponds to the observed distances for spans on this face. /// </summary> /// <param name="defaultEntryUnit">The distance units that should be treated as the default /// (null if there is no default). /// Formatted distances that were specified using these units will not contain the units /// abbreviation. Specify null if the units should always be appended.</param> /// <returns>A data entry string corresponding to the distances for this face</returns> string GetEntryString(DistanceUnit defaultEntryUnit) { // Return if there are no observed spans. if (NumSpan==0) return String.Empty; string[] dists = new string[m_Spans.Length]; // Format each distance. for (int i=0; i<m_Spans.Length; i++) { SpanInfo sd = m_Spans[i]; Distance d = sd.ObservedDistance; if (d == null) // is this possible? dists[i] = String.Empty; else { // Get the formatted distance string distString = FormatDistance(d, defaultEntryUnit); // Append any qualifiers if (sd.IsMissConnect) distString += "/-"; if (sd.IsOmitPoint) distString += "/*"; dists[i] = distString; } } // Output the first distance var str = new StringBuilder(); str.Append(dists[0]); // Output subsequent distances (with possible repeat count for unqualified spans) int numDist = (dists[0].Contains("/") ? 0 : 1); for (int i=1; i<dists.Length; i++) { // If the current distance has a qualifier, flush out any repeat count and // the current distance (rather than something like 10*4/-, we output 10*3 10/-). // This is just to avoid potential confusion. if (dists[i].Contains("/")) { if (numDist>1) str.Append("*"+numDist); str.Append(" "); str.Append(dists[i]); numDist = 0; } else { if (dists[i] == dists[i-1]) numDist++; else { if (numDist>1) str.Append("*"+numDist); str.Append(" "); str.Append(dists[i]); numDist = 1; } } } if (numDist>1) str.Append("*"+numDist); return str.ToString(); }
/// <summary> /// Sort result by geo distance using specified field. /// There can be several Sort parameters (order is important). /// </summary> /// <param name="field">The field.</param> /// <param name="lat">The latitude.</param> /// <param name="lon">The longitude.</param> /// <param name="unit">The distance unit.</param> /// <param name="order">The sort order. By default results will be sorted ascending.</param> public Sort <T> GeoDistance(Expression <Func <T, object> > field, double lat, double lon, DistanceUnit unit, SortDirection order = SortDirection.@default) { var fieldName = field.GetPropertyPath(); return(GeoDistance(fieldName, lat, lon, unit, order)); }
public static string GetUnitString(DistanceUnit unit) { return(distanceUnitStrings[(int)unit]); }
public LinearGeoPointFunction(string field, GeoPoint origin, DistanceUnit scale) : base(field, origin, scale, "linear") { }
public static void Reload() { LockAxisX = EditorPrefs.GetBool("LockAxisX", false); LockAxisY = EditorPrefs.GetBool("LockAxisY", false); LockAxisZ = EditorPrefs.GetBool("LockAxisZ", false); UniformGrid = EditorPrefs.GetBool("UniformGrid", true); EditMode = GetEnum("EditMode", ToolEditMode.Generate); SnapVector = GetVector3("MoveSnap", Vector3.one); DefaultMoveOffset = GetVector3("DefaultMoveOffset", Vector3.zero); DefaultRotateOffset = GetVector3("DefaultRotateOffset", Vector3.zero); ShapeBuildMode = GetEnum("ShapeBuildMode", ShapeMode.Box); DefaultTexGenFlags = GetEnum("DefaultTexGenFlags", defaultTextGenFlagsState); GridVisible = EditorPrefs.GetBool("ShowGrid", true); SnapMode = (SnapMode)EditorPrefs.GetInt("SnapMode", (int)(EditorPrefs.GetBool("ForceSnapToGrid", true) ? SnapMode.GridSnapping : SnapMode.None)); VisibleHelperSurfaces = GetEnum("HelperSurfaces", DefaultHelperSurfaceFlags); ClipMode = GetEnum("ClipMode", ClipMode.RemovePositive); EnableRealtimeCSG = EditorPrefs.GetBool("EnableRealtimeCSG", true); DefaultMaterial = GetMaterial("DefaultMaterial", MaterialUtility.WallMaterial); SnapScale = EditorPrefs.GetFloat("ScaleSnap", 0.1f); SnapRotation = EditorPrefs.GetFloat("RotationSnap", 15.0f); DefaultShapeHeight = EditorPrefs.GetFloat("DefaultShapeHeight", 1.0f); CurveSides = (uint)EditorPrefs.GetInt("CurveSides", 10); SelectionVertex = EditorPrefs.GetBool("SelectionVertex", true); SelectionEdge = EditorPrefs.GetBool("SelectionEdge", true); SelectionSurface = EditorPrefs.GetBool("SelectionSurface", true); HiddenSurfacesNotSelectable = EditorPrefs.GetBool("HiddenSurfacesNotSelectable", true); // HiddenSurfacesOrthoSelectable = EditorPrefs.GetBool("HiddenSurfacesOrthoSelectable", true); ShowTooltips = EditorPrefs.GetBool("ShowTooltips", true); DefaultPreserveUVs = EditorPrefs.GetBool("DefaultPreserveUVs", (CSGModel.DefaultSettings & ModelSettingsFlags.PreserveUVs) == ModelSettingsFlags.PreserveUVs); SnapNonCSGObjects = EditorPrefs.GetBool("SnapNonCSGObjects", true); AutoCommitExtrusion = EditorPrefs.GetBool("AutoCommitExtrusion", false); MaxSphereSplits = Mathf.Max(3, EditorPrefs.GetInt("MaxSphereSplits", 9)); CircleSides = Mathf.Max(3, EditorPrefs.GetInt("CircleSides", 18)); MaxCircleSides = Mathf.Max(3, EditorPrefs.GetInt("MaxCircleSides", 144)); CircleOffset = EditorPrefs.GetFloat("CircleOffset", 0); CircleSmoothShading = EditorPrefs.GetBool("CircleSmoothShading", true); CircleSingleSurfaceEnds = EditorPrefs.GetBool("CircleSingleSurfaceEnds", true); CircleDistanceToSide = EditorPrefs.GetBool("CircleDistanceToSide", true); CircleRecenter = EditorPrefs.GetBool("CircleRecenter", true); SphereSplits = Mathf.Max(1, EditorPrefs.GetInt("SphereSplits", 1)); SphereOffset = EditorPrefs.GetFloat("SphereOffset", 0); SphereSmoothShading = EditorPrefs.GetBool("SphereSmoothShading", true); SphereDistanceToSide = EditorPrefs.GetBool("SphereDistanceToSide", true); HemiSphereMode = EditorPrefs.GetBool("HemiSphereMode", false); LinearStairsStepLength = EditorPrefs.GetFloat("LinearStairsStepLength", 0.30f); LinearStairsStepHeight = EditorPrefs.GetFloat("LinearStairsStepHeight", 0.20f); LinearStairsStepWidth = EditorPrefs.GetFloat("LinearStairsStepWidth", 1.0f); LinearStairsTotalSteps = EditorPrefs.GetInt("LinearStairsTotalSteps", 4); LinearStairsLength = EditorPrefs.GetFloat("LinearStairsLength", 16.0f); LinearStairsHeight = EditorPrefs.GetFloat("LinearStairsHeight", 16.0f); LinearStairsLengthOffset = EditorPrefs.GetFloat("LinearStairsLengthOffset", 0.0f); LinearStairsHeightOffset = EditorPrefs.GetFloat("LinearStairsHeightOffset", 0.0f); DistanceUnit = GetEnum("DistanceUnit", DistanceUnit.Meters); var sceneViews = SortedSceneViews(); EnsureValidSceneviewNames(sceneViews); var arrayString = EditorPrefs.GetString("Wireframe", string.Empty); if (arrayString.Contains(',')) { LegacyLoadWireframeSettings(sceneViews, arrayString); } else { LoadWireframeSettings(sceneViews, arrayString); } UpdateSnapSettings(); }
/// <summary> /// Calculate the distance between two sets of <see cref="Coordinate" /> objects /// </summary> /// <param name="originCoordinate">A <see cref="Coordinate" /> object representing the origin location</param> /// <param name="destinationCoordinate">A <see cref="Coordinate" /> object representing the destination location</param> /// <param name="decimalPlaces">The number of decimal places to round the return value to</param> /// <param name="distanceUnit">The unit of distance</param> /// <returns>A <see cref="double" /> value representing the distance in miles from the origin to the destination coordinate</returns> public static double GetDistance(Coordinate originCoordinate, Coordinate destinationCoordinate, int decimalPlaces = 1, DistanceUnit distanceUnit = DistanceUnit.Miles) { return(GetDistance( originCoordinate.Latitude, originCoordinate.Longitude, destinationCoordinate.Latitude, destinationCoordinate.Longitude, decimalPlaces, distanceUnit)); }
/// <summary> /// Convert the current Vector2 from 'fromUnit' to 'toUnit' /// </summary> public static Vector2 Convert(this Vector2 v, DistanceUnit fromUnit, DistanceUnit toUnit) { return(FingerGestures.Convert(v, fromUnit, toUnit)); }
static void OnBottomBarGUI(SceneView sceneView) { var snapToGrid = RealtimeCSG.CSGSettings.SnapToGrid; var uniformGrid = RealtimeCSG.CSGSettings.UniformGrid; var moveSnapVector = RealtimeCSG.CSGSettings.SnapVector; var rotationSnap = RealtimeCSG.CSGSettings.SnapRotation; var scaleSnap = RealtimeCSG.CSGSettings.SnapScale; var showGrid = RealtimeCSG.CSGSettings.GridVisible; var lockAxisX = RealtimeCSG.CSGSettings.LockAxisX; var lockAxisY = RealtimeCSG.CSGSettings.LockAxisY; var lockAxisZ = RealtimeCSG.CSGSettings.LockAxisZ; var distanceUnit = RealtimeCSG.CSGSettings.DistanceUnit; var helperSurfaces = RealtimeCSG.CSGSettings.VisibleHelperSurfaces; var showWireframe = RealtimeCSG.CSGSettings.IsWireframeShown(sceneView); var updateSurfaces = false; bool wireframeModified = false; var viewWidth = sceneView.position.width; bool modified = false; EditorGUILayout.BeginHorizontal(GUIStyleUtility.ContentEmpty); { EditorGUI.BeginChangeCheck(); { var skin = GUIStyleUtility.Skin; if (showGrid) { showGrid = GUILayout.Toggle(showGrid, skin.gridIconOn, EditorStyles.toolbarButton); } else { showGrid = GUILayout.Toggle(showGrid, skin.gridIcon, EditorStyles.toolbarButton); } TooltipUtility.SetToolTip(showGridTooltip); if (viewWidth >= 800) { EditorGUILayout.Space(); } if (viewWidth >= 200) { var prevBackgroundColor = GUI.backgroundColor; var lockedBackgroundColor = skin.lockedBackgroundColor; if (lockAxisX) { GUI.backgroundColor = lockedBackgroundColor; } lockAxisX = !GUILayout.Toggle(!lockAxisX, xLabel, skin.xToolbarButton); if (lockAxisX) { TooltipUtility.SetToolTip(xTooltipOn); } else { TooltipUtility.SetToolTip(xTooltipOff); } GUI.backgroundColor = prevBackgroundColor; if (lockAxisY) { GUI.backgroundColor = lockedBackgroundColor; } lockAxisY = !GUILayout.Toggle(!lockAxisY, yLabel, skin.yToolbarButton); if (lockAxisY) { TooltipUtility.SetToolTip(yTooltipOn); } else { TooltipUtility.SetToolTip(yTooltipOff); } GUI.backgroundColor = prevBackgroundColor; if (lockAxisZ) { GUI.backgroundColor = lockedBackgroundColor; } lockAxisZ = !GUILayout.Toggle(!lockAxisZ, zLabel, skin.zToolbarButton); if (lockAxisZ) { TooltipUtility.SetToolTip(zTooltipOn); } else { TooltipUtility.SetToolTip(zTooltipOff); } GUI.backgroundColor = prevBackgroundColor; } } modified = EditorGUI.EndChangeCheck() || modified; if (viewWidth >= 800) { EditorGUILayout.Space(); } EditorGUI.BeginChangeCheck(); { if (viewWidth >= 475) { if (snapToGrid && viewWidth >= 310) { snapToGrid = GUILayout.Toggle(snapToGrid, GUIStyleUtility.Skin.snappingIconOn, EditorStyles.toolbarButton); TooltipUtility.SetToolTip(snapToGridTooltip); if (viewWidth >= 865) { uniformGrid = GUILayout.Toggle(uniformGrid, positionLargeLabel, miniTextStyle); } else { uniformGrid = GUILayout.Toggle(uniformGrid, positionSmallLabel, miniTextStyle); } TooltipUtility.SetToolTip(positionTooltip); } else { snapToGrid = GUILayout.Toggle(snapToGrid, GUIStyleUtility.Skin.snappingIcon, EditorStyles.toolbarButton); TooltipUtility.SetToolTip(snapToGridTooltip); } } } modified = EditorGUI.EndChangeCheck() || modified; if (viewWidth >= 310) { if (snapToGrid) { if (uniformGrid || viewWidth < 515) { EditorGUI.showMixedValue = !(moveSnapVector.x == moveSnapVector.y && moveSnapVector.x == moveSnapVector.z); EditorGUI.BeginChangeCheck(); { moveSnapVector.x = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, moveSnapVector.x), textInputStyle, MinSnapWidth, MaxSnapWidth)); } if (EditorGUI.EndChangeCheck()) { modified = true; moveSnapVector.y = moveSnapVector.x; moveSnapVector.z = moveSnapVector.x; } EditorGUI.showMixedValue = false; } else { EditorGUI.BeginChangeCheck(); { moveSnapVector.x = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, moveSnapVector.x), textInputStyle, MinSnapWidth, MaxSnapWidth)); moveSnapVector.y = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, moveSnapVector.y), textInputStyle, MinSnapWidth, MaxSnapWidth)); moveSnapVector.z = Units.DistanceUnitToUnity(distanceUnit, EditorGUILayout.DoubleField(Units.UnityToDistanceUnit(distanceUnit, moveSnapVector.z), textInputStyle, MinSnapWidth, MaxSnapWidth)); } modified = EditorGUI.EndChangeCheck() || modified; } DistanceUnit nextUnit = Units.CycleToNextUnit(distanceUnit); GUIContent unitText = Units.GetUnitGUIContent(distanceUnit); if (GUILayout.Button(unitText, miniTextStyle)) { distanceUnit = nextUnit; modified = true; } if (viewWidth >= 700) { if (GUILayout.Button(positionPlusLabel, EditorStyles.miniButtonLeft)) { GridUtility.DoubleGridSize(); moveSnapVector = RealtimeCSG.CSGSettings.SnapVector; } TooltipUtility.SetToolTip(positionPlusTooltip); if (GUILayout.Button(positionMinusLabel, EditorStyles.miniButtonRight)) { GridUtility.HalfGridSize(); moveSnapVector = RealtimeCSG.CSGSettings.SnapVector; } TooltipUtility.SetToolTip(positionMinnusTooltip); } if (viewWidth >= 750) { if (viewWidth >= 865) { GUILayout.Label(angleLargeLabel, miniTextStyle); } else { GUILayout.Label(angleSmallLabel, miniTextStyle); } TooltipUtility.SetToolTip(angleTooltip); } EditorGUI.BeginChangeCheck(); { rotationSnap = EditorGUILayout.FloatField(rotationSnap, textInputStyle, MinSnapWidth, MaxSnapWidth); if (viewWidth <= 750) { TooltipUtility.SetToolTip(angleTooltip); } } modified = EditorGUI.EndChangeCheck() || modified; if (viewWidth >= 370) { GUILayout.Label(angleUnitLabel, miniTextStyle); } if (viewWidth >= 700) { if (GUILayout.Button(anglePlusLabel, EditorStyles.miniButtonLeft)) { rotationSnap *= 2.0f; modified = true; } TooltipUtility.SetToolTip(anglePlusTooltip); if (GUILayout.Button(angleMinusLabel, EditorStyles.miniButtonRight)) { rotationSnap /= 2.0f; modified = true; } TooltipUtility.SetToolTip(angleMinnusTooltip); } if (viewWidth >= 750) { if (viewWidth >= 865) { GUILayout.Label(scaleLargeLabel, miniTextStyle); } else { GUILayout.Label(scaleSmallLabel, miniTextStyle); } TooltipUtility.SetToolTip(scaleTooltip); } EditorGUI.BeginChangeCheck(); { scaleSnap = EditorGUILayout.FloatField(scaleSnap, textInputStyle, MinSnapWidth, MaxSnapWidth); if (viewWidth <= 750) { TooltipUtility.SetToolTip(scaleTooltip); } } modified = EditorGUI.EndChangeCheck() || modified; if (viewWidth >= 370) { GUILayout.Label(scaleUnitLabel, miniTextStyle); } if (viewWidth >= 700) { if (GUILayout.Button(scalePlusLabel, EditorStyles.miniButtonLeft)) { scaleSnap *= 10.0f; modified = true; } TooltipUtility.SetToolTip(scalePlusTooltip); if (GUILayout.Button(scaleMinusLabel, EditorStyles.miniButtonRight)) { scaleSnap /= 10.0f; modified = true; } TooltipUtility.SetToolTip(scaleMinnusTooltip); } } } if (viewWidth >= 750) { GUILayout.FlexibleSpace(); } EditorGUI.BeginChangeCheck(); if (showWireframe) { showWireframe = GUILayout.Toggle(showWireframe, GUIStyleUtility.Skin.wireframe, EditorStyles.toolbarButton); } else { showWireframe = GUILayout.Toggle(showWireframe, GUIStyleUtility.Skin.wireframeOn, EditorStyles.toolbarButton); } TooltipUtility.SetToolTip(showWireframeTooltip); if (EditorGUI.EndChangeCheck()) { wireframeModified = true; modified = true; } if (viewWidth >= 250) { EditorGUI.BeginChangeCheck(); { helperSurfaces = (HelperSurfaceFlags)EditorGUILayout.MaskField((int)helperSurfaces, helperSurfaceFlagStrings, EnumMaxWidth, EnumMinWidth); TooltipUtility.SetToolTip(helperSurfacesTooltip); } if (EditorGUI.EndChangeCheck()) { updateSurfaces = true; modified = true; } } if (viewWidth >= 800) { EditorGUILayout.Space(); } if (GUILayout.Button(GUIStyleUtility.Skin.rebuildIcon, EditorStyles.toolbarButton)) { Debug.Log("Starting complete rebuild"); InternalCSGModelManager.skipRefresh = true; RealtimeCSG.CSGSettings.Reload(); SceneViewEventHandler.UpdateDefines(); var startTime = EditorApplication.timeSinceStartup; InternalCSGModelManager.Rebuild(); InternalCSGModelManager.OnHierarchyModified(); var hierarchy_update_endTime = EditorApplication.timeSinceStartup; CSGBindings.RebuildAll(); var csg_endTime = EditorApplication.timeSinceStartup; InternalCSGModelManager.UpdateMeshes(); MeshInstanceManager.UpdateHelperSurfaceVisibility(); var meshupdate_endTime = EditorApplication.timeSinceStartup; updateSurfaces = true; SceneViewEventHandler.ResetUpdateRoutine(); RealtimeCSG.CSGSettings.Save(); InternalCSGModelManager.skipRefresh = false; Debug.Log(string.Format(CultureInfo.InvariantCulture, "Full hierarchy rebuild in {0:F} ms. Full CSG rebuild done in {1:F} ms. Mesh update done in {2:F} ms.", (hierarchy_update_endTime - startTime) * 1000, (csg_endTime - hierarchy_update_endTime) * 1000, (meshupdate_endTime - csg_endTime) * 1000 )); } TooltipUtility.SetToolTip(rebuildTooltip); } EditorGUILayout.EndHorizontal(); var mousePoint = Event.current.mousePosition; var currentArea = GUILayoutUtility.GetLastRect(); int controlID = GUIUtility.GetControlID(BottomBarEditorOverlayHash, FocusType.Passive, currentArea); switch (Event.current.GetTypeForControl(controlID)) { case EventType.MouseDown: { if (currentArea.Contains(mousePoint)) { GUIUtility.hotControl = controlID; GUIUtility.keyboardControl = controlID; Event.current.Use(); } break; } case EventType.MouseMove: { if (currentArea.Contains(mousePoint)) { Event.current.Use(); } break; } case EventType.MouseUp: { if (GUIUtility.hotControl == controlID) { GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; Event.current.Use(); } break; } case EventType.MouseDrag: { if (GUIUtility.hotControl == controlID) { Event.current.Use(); } break; } case EventType.ScrollWheel: { if (currentArea.Contains(mousePoint)) { Event.current.Use(); } break; } } rotationSnap = Mathf.Max(1.0f, Mathf.Abs((360 + (rotationSnap % 360))) % 360); moveSnapVector.x = Mathf.Max(1.0f / 1024.0f, moveSnapVector.x); moveSnapVector.y = Mathf.Max(1.0f / 1024.0f, moveSnapVector.y); moveSnapVector.z = Mathf.Max(1.0f / 1024.0f, moveSnapVector.z); scaleSnap = Mathf.Max(MathConstants.MinimumScale, scaleSnap); RealtimeCSG.CSGSettings.SnapToGrid = snapToGrid; RealtimeCSG.CSGSettings.SnapVector = moveSnapVector; RealtimeCSG.CSGSettings.SnapRotation = rotationSnap; RealtimeCSG.CSGSettings.SnapScale = scaleSnap; RealtimeCSG.CSGSettings.UniformGrid = uniformGrid; // RealtimeCSG.Settings.SnapVertex = vertexSnap; RealtimeCSG.CSGSettings.GridVisible = showGrid; RealtimeCSG.CSGSettings.LockAxisX = lockAxisX; RealtimeCSG.CSGSettings.LockAxisY = lockAxisY; RealtimeCSG.CSGSettings.LockAxisZ = lockAxisZ; RealtimeCSG.CSGSettings.DistanceUnit = distanceUnit; RealtimeCSG.CSGSettings.VisibleHelperSurfaces = helperSurfaces; if (wireframeModified) { RealtimeCSG.CSGSettings.SetWireframeShown(sceneView, showWireframe); } if (updateSurfaces) { MeshInstanceManager.UpdateHelperSurfaceVisibility(); } if (modified) { GUI.changed = true; RealtimeCSG.CSGSettings.UpdateSnapSettings(); RealtimeCSG.CSGSettings.Save(); SceneView.RepaintAll(); } }
public static double GetCellWidthByLevel(RectangleShape extent, GeographyUnit extentMapUnit, int level, DistanceUnit returnDistanceUnit) { PointShape centerPoint = extent.GetCenterPoint(); PointShape centerLeft = new PointShape(extent.LowerLeftPoint.X, centerPoint.Y); PointShape centerRight = new PointShape(extent.UpperRightPoint.X, centerPoint.Y); PointShape centerUpper = new PointShape(centerPoint.X, extent.UpperLeftPoint.Y); PointShape centerLower = new PointShape(centerPoint.X, extent.LowerLeftPoint.Y); double centerWidth = centerLeft.GetDistanceTo(centerRight, extentMapUnit, returnDistanceUnit); double centerHeight = centerUpper.GetDistanceTo(centerLower, extentMapUnit, returnDistanceUnit); double longestEdge = Math.Max(centerWidth, centerHeight); double cellWidth = longestEdge / Math.Sqrt(Math.Pow(4, level - 1)); return cellWidth; }
/// <summary> /// Convert the current pixel-based Vector2 to the desired unit /// </summary> public static Vector2 In(this Vector2 vecInPixels, DistanceUnit toUnit) { return(vecInPixels.Convert(DistanceUnit.Pixels, toUnit)); }
/// <summary> /// Gets the distance. /// </summary> /// <returns>The distance.</returns> /// <param name="lat1">Lat1.</param> /// <param name="lon1">Lon1.</param> /// <param name="lat2">Lat2.</param> /// <param name="lon2">Lon2.</param> /// <param name="unit">Unit.</param> public static double GetDistance(double lat1, double lon1, double lat2, double lon2, DistanceUnit unit = DistanceUnit.Miles) { var theta = lon1 - lon2; var dist = Math.Sin(DegreesToRadians(lat1)) * Math.Sin(DegreesToRadians(lat2)) + Math.Cos(DegreesToRadians(lat1)) * Math.Cos(DegreesToRadians(lat2)) * Math.Cos(DegreesToRadians(theta)); dist = Math.Acos(dist); dist = RadiansToDegrees(dist); dist = dist * 60 * 1.1515; //miles switch (unit) { case DistanceUnit.Kilometers: dist *= 1.609344; break; case DistanceUnit.NauticalMiles: dist *= 0.8684; break; } return(dist); }
public static int GetLevelByCellWidth(RectangleShape extent, GeographyUnit extentMapUnit, double cellWidth, DistanceUnit widthDistanceUnit) { PointShape centerPoint = extent.GetCenterPoint(); PointShape centerLeft = new PointShape(extent.LowerLeftPoint.X, centerPoint.Y); PointShape centerRight = new PointShape(extent.UpperRightPoint.X, centerPoint.Y); PointShape centerUpper = new PointShape(centerPoint.X, extent.UpperLeftPoint.Y); PointShape centerLower = new PointShape(centerPoint.X, extent.LowerLeftPoint.Y); double centerWidth = centerLeft.GetDistanceTo(centerRight, extentMapUnit, widthDistanceUnit); double centerHeight = centerUpper.GetDistanceTo(centerLower, extentMapUnit, widthDistanceUnit); double longestEdge = Math.Max(centerWidth, centerHeight); double level = Math.Round(2 * Math.Log((longestEdge / cellWidth), 4) + 1); return((int)level); }