< Summary

Information
Class: Morpho25.Geometry.Soil
Assembly: Morpho25
File(s): D:\a\Morpho\Morpho\project\Morpho\Morpho25\Geometry\Soil.cs
Line coverage
60%
Covered lines: 46
Uncovered lines: 30
Coverable lines: 76
Total lines: 166
Line coverage: 60.5%
Branch coverage
58%
Covered branches: 14
Total branches: 24
Branch coverage: 58.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_Name()100%1100%
get_Geometry()100%1100%
get_IDmatrix()100%10%
get_Material()100%1100%
set_Material(...)50%266.66%
.ctor(...)75%4100%
SetMatrix(...)100%10%
ToString()100%10%
Serialize()100%1100%
Deserialize(...)100%157.14%
Equals(...)50%1080%
Equals(...)50%475%
GetHashCode()100%10%
op_Equality(...)75%480%
op_Inequality(...)100%1100%

File(s)

D:\a\Morpho\Morpho\project\Morpho\Morpho25\Geometry\Soil.cs

#LineLine coverage
 1using Morpho25.Utility;
 2using MorphoGeometry;
 3using Newtonsoft.Json;
 4using System;
 5using System.Collections.Generic;
 6using System.ComponentModel;
 7
 8namespace Morpho25.Geometry
 9{
 10    [DisplayName("Soil")]
 11    /// <summary>
 12    /// Soil class.
 13    /// </summary>
 14    public class Soil : Entity, IEquatable<Soil>
 15    {
 16        [DisplayName("Name")]
 17        [Description("Name of the soil group")]
 18        [JsonProperty("name")]
 19        /// <summary>
 20        /// Name of the soil.
 21        /// </summary>
 122        public override string Name { get; }
 23
 24        [DisplayName("Geometry")]
 25        [Description("Flat or solid geometry")]
 26        [JsonProperty("geometry", Required = Required.Always)]
 27        /// <summary>
 28        /// Geometry of the soil.
 29        /// </summary>
 630        public FaceGroup Geometry { get; set; }
 31
 32        [JsonIgnore]
 33        /// <summary>
 34        /// Matrix 2D of the soil.
 35        /// </summary>
 036        public Matrix2d IDmatrix { get; private set; }
 37
 38        [DisplayName("Material")]
 39        [Description("Profile of the soil")]
 40        [JsonProperty("material")]
 41        /// <summary>
 42        /// Material of the soil.
 43        /// </summary>
 44        public override Material Material
 45        {
 946            get { return _material; }
 47            protected set
 448            {
 449                if (value.IDs.Length != 1)
 050                    throw new ArgumentOutOfRangeException(
 051                          $"{nameof(value)}  must contains 1 material code.");
 52
 453                _material = value;
 454            }
 55        }
 56
 57        [JsonConstructor]
 58        /// <summary>
 59        /// Create a new soil.
 60        /// </summary>
 61        /// <param name="geometry">Geometry of the soil.</param>
 62        /// <param name="id">Numerical ID.</param>
 63        /// <param name="code">Code of the material.</param>
 64        /// <param name="name">Name of the soil.</param>
 365        public Soil(FaceGroup geometry,
 366            int id, string code = null,
 367            string name = null)
 368        {
 369            ID = id;
 370            Geometry = geometry;
 371            Material = (code != null)
 372                ? CreateMaterial(Material.DEFAULT_SOIL, code)
 373                : CreateMaterial(Material.DEFAULT_SOIL);
 374            Name = name ?? "SoilGroup";
 375        }
 76
 77        public void SetMatrix(Grid grid)
 078        {
 079            Matrix2d matrix = new Matrix2d(grid.Size.NumX, grid.Size.NumY, Material.DEFAULT_SOIL);
 80
 081            List<Ray> rays = EnvimetUtility.GetRayFromFacegroupBbox(grid, Geometry);
 82
 083            var intersection = EnvimetUtility.Raycasting2D(rays, Geometry, false, false);
 084            SetMatrix(intersection, grid, matrix, Material.IDs[0]);
 85
 086            IDmatrix = matrix;
 087        }
 88        /// <summary>
 89        /// String representation of the soil.
 90        /// </summary>
 91        /// <returns>String representation.</returns>
 92        public override string ToString()
 093        {
 094            return String.Format("Soil::{0}::{1}::{2}",
 095                Name, ID, Material.IDs[0]);
 096        }
 97
 98        public string Serialize()
 199        {
 1100            return JsonConvert.SerializeObject(this);
 1101        }
 102
 103        public static Soil Deserialize(string json)
 1104        {
 105            try
 1106            {
 1107                return JsonConvert.DeserializeObject<Soil>(json);
 108            }
 0109            catch (Exception e)
 0110            {
 0111                throw new Exception(e.Message);
 112            }
 1113        }
 114
 115        public bool Equals(Soil other)
 1116        {
 1117            if (other == null)
 0118                return false;
 119
 1120            if (other != null
 1121                && other.ID == this.ID
 1122                && other.Material == this.Material
 1123                && other.Geometry == this.Geometry)
 1124                return true;
 125            else
 0126                return false;
 1127        }
 128
 129        public override bool Equals(Object obj)
 14130        {
 14131            if (obj == null)
 0132                return false;
 133
 14134            var soilObj = obj as Soil;
 14135            if (soilObj == null)
 14136                return false;
 137            else
 0138                return Equals(soilObj);
 14139        }
 140
 141        public override int GetHashCode()
 0142        {
 143            unchecked
 0144            {
 0145                int hash = 17;
 0146                hash = hash * 23 + ID.GetHashCode();
 0147                hash = hash * 23 + Material.GetHashCode();
 0148                hash = hash * 23 + Geometry.GetHashCode();
 0149                return hash;
 150            }
 0151        }
 152
 153        public static bool operator ==(Soil soil1, Soil soil2)
 16154        {
 16155            if (((object)soil1) == null || ((object)soil2) == null)
 16156                return Object.Equals(soil1, soil2);
 157
 0158            return soil1.Equals(soil2);
 16159        }
 160
 161        public static bool operator !=(Soil soil1, Soil soil2)
 1162        {
 1163            return !(soil1 == soil2);
 1164        }
 165    }
 166}