< Summary

Information
Class: Morpho25.Geometry.Plant3d
Assembly: Morpho25
File(s): D:\a\Morpho\Morpho\project\Morpho\Morpho25\Geometry\Plant3d.cs
Line coverage
57%
Covered lines: 44
Uncovered lines: 32
Coverable lines: 76
Total lines: 162
Line coverage: 57.8%
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_Material()100%1100%
set_Material(...)50%266.66%
get_Pixel()100%10%
.ctor(...)75%4100%
SetPixel(...)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\Plant3d.cs

#LineLine coverage
 1using Morpho25.Utility;
 2using MorphoGeometry;
 3using Newtonsoft.Json;
 4using System;
 5using System.ComponentModel;
 6
 7namespace Morpho25.Geometry
 8{
 9    [DisplayName("Plant3D")]
 10    /// <summary>
 11    /// Plant 3D class.
 12    /// </summary>
 13    public class Plant3d : Entity, IEquatable<Plant3d>
 14    {
 15        private const int SHIFT = 1;
 16
 17        [DisplayName("Name")]
 18        [Description("Name of the plant3D group")]
 19        [JsonProperty("name")]
 20        /// <summary>
 21        /// Name of the plant 3D.
 22        /// </summary>
 323        public override string Name { get; }
 24
 25        [DisplayName("Geometry")]
 26        [Description("Point geometry")]
 27        [JsonProperty("geometry", Required = Required.Always)]
 28        /// <summary>
 29        /// Geometry of the plant 3D.
 30        /// </summary>
 631        public Vector Geometry { get; set; }
 32
 33        [DisplayName("Material")]
 34        [Description("Plant3D type")]
 35        [JsonProperty("material")]
 36        /// <summary>
 37        /// Material of the plant 3D.
 38        /// </summary>
 39        public override Material Material
 40        {
 941            get { return _material; }
 42            protected set
 443            {
 444                if (value.IDs.Length != 1)
 045                    throw new ArgumentOutOfRangeException(
 046                          $"{nameof(value)}  must contains 1 material code.");
 47
 448                _material = value;
 449            }
 50
 51        }
 52
 53        [JsonIgnore]
 54        /// <summary>
 55        /// Location of the plant 3D in the grid.
 56        /// </summary>
 057        public Pixel Pixel { get; private set; }
 58        /// <summary>
 59        /// Create a new plant 3D.
 60        /// </summary>
 61        /// <param name="geometry">Geometry of the plant 3D.</param>
 62        /// <param name="code">Code of the material.</param>
 63        /// <param name="name">Name of the plant 3D.</param>
 364        public Plant3d(Vector geometry,
 365            string code = null, string name = null)
 366        {
 367            Geometry = geometry;
 368            Material = (code != null)
 369                ? CreateMaterial(Material.DEFAULT_PLANT_3D, code)
 370                : CreateMaterial(Material.DEFAULT_PLANT_3D);
 371            Name = name ?? "PlantGroup";
 372        }
 73
 74        public void SetPixel(Grid grid)
 075        {
 076            Pixel = new Pixel
 077            {
 078                I = Util.ClosestValue(grid.Xaxis, Geometry.x) + SHIFT,
 079                J = Util.ClosestValue(grid.Yaxis, Geometry.y) + SHIFT,
 080                K = 0
 081            };
 082        }
 83        /// <summary>
 84        /// String representation of the plant 3D.
 85        /// </summary>
 86        /// <returns>String representation.</returns>
 87        public override string ToString()
 088        {
 089            return String.Format("Plant3D::{0}::{1}::{2}",
 090                Name, Material.IDs[0], String.Join(",",
 091                Pixel.I, Pixel.J, Pixel.K));
 092        }
 93
 94        public string Serialize()
 195        {
 196            return JsonConvert.SerializeObject(this);
 197        }
 98
 99        public static Plant3d Deserialize(string json)
 1100        {
 101            try
 1102            {
 1103                return JsonConvert.DeserializeObject<Plant3d>(json);
 104            }
 0105            catch (Exception e)
 0106            {
 0107                throw new Exception(e.Message);
 108            }
 1109        }
 110
 111        public bool Equals(Plant3d other)
 1112        {
 1113            if (other == null)
 0114                return false;
 115
 1116            if (other != null
 1117                && other.Name == this.Name
 1118                && other.Material == this.Material
 1119                && other.Geometry == this.Geometry)
 1120                return true;
 121            else
 0122                return false;
 1123        }
 124
 125        public override bool Equals(Object obj)
 3126        {
 3127            if (obj == null)
 0128                return false;
 129
 3130            var plantObj = obj as Plant3d;
 3131            if (plantObj == null)
 3132                return false;
 133            else
 0134                return Equals(plantObj);
 3135        }
 136
 137        public override int GetHashCode()
 0138        {
 139            unchecked
 0140            {
 0141                int hash = 17;
 0142                hash = hash * 23 + Name.GetHashCode();
 0143                hash = hash * 23 + Material.GetHashCode();
 0144                hash = hash * 23 + Geometry.GetHashCode();
 0145                return hash;
 146            }
 0147        }
 148
 149        public static bool operator ==(Plant3d plant1, Plant3d plant2)
 5150        {
 5151            if (((object)plant1) == null || ((object)plant2) == null)
 5152                return Object.Equals(plant1, plant2);
 153
 0154            return plant1.Equals(plant2);
 5155        }
 156
 157        public static bool operator !=(Plant3d plant1, Plant3d plant2)
 1158        {
 1159            return !(plant1 == plant2);
 1160        }
 161    }
 162}