< Summary

Information
Class: Morpho25.Settings.Location
Assembly: Morpho25
File(s): D:\a\Morpho\Morpho\project\Morpho\Morpho25\Settings\Location.cs
Line coverage
67%
Covered lines: 82
Uncovered lines: 40
Coverable lines: 122
Total lines: 255
Line coverage: 67.2%
Branch coverage
51%
Covered branches: 27
Total branches: 52
Branch coverage: 51.9%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_UTM()100%10%
get_LocationName()100%1100%
get_Latitude()100%1100%
set_Latitude(...)100%4100%
get_Longitude()100%1100%
set_Longitude(...)50%466.66%
get_TimezoneReference()100%1100%
set_TimezoneReference(...)50%466.66%
get_TimeZone()100%1100%
set_TimeZone(...)58.33%1266.66%
get_ModelRotation()100%1100%
set_ModelRotation(...)50%466.66%
.ctor(...)100%1100%
.ctor(...)100%1100%
ToString()100%10%
Serialize()100%1100%
Deserialize(...)100%1100%
Equals(...)50%1684.61%
Equals(...)0%40%
GetHashCode()100%10%
op_Equality(...)50%480%
op_Inequality(...)100%1100%

File(s)

D:\a\Morpho\Morpho\project\Morpho\Morpho25\Settings\Location.cs

#LineLine coverage
 1using Newtonsoft.Json;
 2using System;
 3using System.ComponentModel;
 4using System.ComponentModel.DataAnnotations;
 5using System.Linq;
 6
 7namespace Morpho25.Settings
 8{
 9
 10    public class UTM
 11    {
 12        public UTM(double utmEsting, double utmNorthing, string utmZone)
 13        {
 14            UTMesting = utmEsting;
 15            UTMnorthing = utmNorthing;
 16            UTMzone = utmZone;
 17        }
 18        public double UTMesting { get; }
 19        public double UTMnorthing { get; }
 20        public string UTMzone { get; }
 21
 22        public override string ToString()
 23        {
 24            return String.Format("UTM coordinate::{0}", UTMzone);
 25        }
 26    }
 27
 28
 29    public class Location : IEquatable<Location>
 30    {
 31        public const double TIMEZONE_LONGITUDE = 15.00000;
 32        public const string PROJECTION_SYSTEM = " ";
 33        public const string REALWORLD_POINT = "0.00000";
 34
 35        private double _latitude;
 36        private double _longitude;
 37        private string _timeZone;
 38        private double _modelRotation;
 39        private double _timezoneRefence;
 40
 41        [JsonIgnore]
 042        public UTM UTM { get; set; }
 43
 44        [DisplayName("Name")]
 45        [Description("Location name.")]
 46        [JsonProperty("locationName")]
 747        public string LocationName { get; set; }
 48
 49        [DisplayName("Latitude")]
 50        [Description("Latitude in deg.")]
 51        [Range(-90, 90, ErrorMessage = "Number in range(-90, 90) is required.")]
 52        [JsonProperty("latitude", Required = Required.Always)]
 53        public double Latitude {
 954            get { return _latitude; }
 55            private set
 456            {
 457                if (value > 90.0 || value < -90.0)
 158                    throw new ArgumentOutOfRangeException(
 159                          $"{nameof(value)} must be in range (-90, 90).");
 60
 361                _latitude = value;
 362            }
 63        }
 64
 65        [DisplayName("Longitude")]
 66        [Description("Longitude in deg.")]
 67        [Range(-180, 180, ErrorMessage = "Number in range(-180, 180) is required.")]
 68        [JsonProperty("longitude", Required = Required.Always)]
 69        public double Longitude {
 970            get { return _longitude; }
 71            private set
 372            {
 373                if (value > 180.0 || value < -180.0)
 074                    throw new ArgumentOutOfRangeException(
 075                          $"{nameof(value)} must be in range (-180, 180).");
 76
 377                _longitude = value;
 378            }
 79        }
 80
 81        [DisplayName("Timezone reference")]
 82        [Description("Longitude reference for time zone.")]
 83        [Range(-180, 180, ErrorMessage = "Number in range(-180, 180) is required.")]
 84        [JsonProperty("timezoneReference")]
 85        public double TimezoneReference
 86        {
 987            get { return _timezoneRefence; }
 88            set
 489            {
 490                if (value > 180.0 || value < -180.0)
 091                    throw new ArgumentOutOfRangeException(
 092                          $"{nameof(value)} must be in range (-180, 180).");
 93
 494                _timezoneRefence = value;
 495            }
 96        }
 97
 98        [DisplayName("Timezone")]
 99        [Description("Timezone.")]
 100        [JsonProperty("timeZone")]
 101        public string TimeZone
 102        {
 9103            get { return _timeZone; }
 104            set
 4105            {
 106                int val;
 4107                if (value == "GMT")
 1108                {
 1109                    val = 0;
 1110                }
 3111                else if (value.StartsWith("UTC"))
 0112                {
 0113                    var num = value.Split('C').Last();
 0114                    val = Convert.ToInt32(num);
 0115                } else
 3116                {
 3117                    val = Convert.ToInt32(value);
 3118                }
 119
 4120                if (val > 14 || val < -12)
 0121                    throw new ArgumentOutOfRangeException($"{nameof(value)} must be in range (-12, 14).");
 122
 4123                if (val > 0)
 0124                    _timeZone = "UTC+" + value;
 4125                else if (val < 0)
 0126                    _timeZone = "UTC-" + value;
 127                else
 4128                    _timeZone = "GMT";
 4129            }
 130        }
 131
 132
 133        [DisplayName("Rotation")]
 134        [Description("Model rotation clockwise in deg.")]
 135        [Range(0, 360, ErrorMessage = "Number in range(0, 360) is required.")]
 136        [JsonProperty("modelRotation")]
 137        public double ModelRotation {
 9138            get { return _modelRotation; }
 139            set
 4140            {
 4141                if (value > 360.0 || value < 0.0)
 0142                    throw new ArgumentOutOfRangeException(
 0143                          $"{nameof(value)} must be in range (0, 360) Clockwise.");
 144
 4145                _modelRotation = value;
 4146            }
 147        }
 148
 4149        public Location(double latitude, double longitude)
 4150        {
 4151            Latitude = latitude;
 3152            Longitude = longitude;
 3153            LocationName = "Envimet Location";
 3154            TimeZone = "0";
 3155            ModelRotation = 0.0;
 3156            TimezoneReference = Location.TIMEZONE_LONGITUDE;
 3157        }
 158
 159        [JsonConstructor]
 160        public Location(double latitude,
 161                        double longitude,
 162                        string locationName="EnvimetLocation",
 163                        string timeZone="0",
 164                        double modelRotation=0,
 165                        double timezoneReference=Location.TIMEZONE_LONGITUDE) :
 2166            this(latitude, longitude)
 1167        {
 1168            LocationName = locationName;
 1169            TimeZone = timeZone;
 1170            ModelRotation = modelRotation;
 1171            TimezoneReference = timezoneReference;
 1172        }
 173
 174
 175        public override string ToString()
 0176        {
 0177            return String.Format("{0}::{1}::{2}::{3}", LocationName,
 0178                Latitude, Longitude, ModelRotation);
 0179        }
 180
 181        public string Serialize()
 1182        {
 1183            return JsonConvert.SerializeObject(this);
 1184        }
 185
 186        public static Location Deserialize(string json)
 2187        {
 188            try
 2189            {
 2190                return JsonConvert.DeserializeObject<Location>(json);
 191            }
 1192            catch (Exception e)
 1193            {
 1194                throw new Exception(e.Message);
 195            }
 1196        }
 197
 198        public bool Equals(Location other)
 1199        {
 1200            if (other == null)
 0201                return false;
 202
 1203            if (other != null
 1204                && other.LocationName == this.LocationName
 1205                && other.TimeZone == this.TimeZone
 1206                && other.Latitude == this.Latitude
 1207                && other.Longitude == this.Longitude
 1208                && other.TimezoneReference == this.TimezoneReference
 1209                && other.ModelRotation == this.ModelRotation)
 1210                return true;
 211            else
 0212                return false;
 1213        }
 214
 215        public override bool Equals(Object obj)
 0216        {
 0217            if (obj == null)
 0218                return false;
 219
 0220            var locObj = obj as Location;
 0221            if (locObj == null)
 0222                return false;
 223            else
 0224                return Equals(locObj);
 0225        }
 226
 227        public override int GetHashCode()
 0228        {
 229            unchecked
 0230            {
 0231                int hash = 17;
 0232                hash = hash * 23 + LocationName.GetHashCode();
 0233                hash = hash * 23 + TimeZone.GetHashCode();
 0234                hash = hash * 23 + Latitude.GetHashCode();
 0235                hash = hash * 23 + Longitude.GetHashCode();
 0236                hash = hash * 23 + TimezoneReference.GetHashCode();
 0237                hash = hash * 23 + ModelRotation.GetHashCode();
 0238                return hash;
 239            }
 0240        }
 241
 242        public static bool operator ==(Location loc1, Location loc2)
 2243        {
 2244            if (((object)loc1) == null || ((object)loc2) == null)
 2245                return Object.Equals(loc1, loc2);
 246
 0247            return loc1.Equals(loc2);
 2248        }
 249
 250        public static bool operator !=(Location loc1, Location loc2)
 1251        {
 1252            return !(loc1 == loc2);
 1253        }
 254    }
 255}