< Summary

Information
Class: Morpho25.Geometry.Plant2d
Assembly: Morpho25
File(s): D:\a\Morpho\Morpho\project\Morpho\Morpho25\Geometry\Plant2d.cs
Line coverage
59%
Covered lines: 46
Uncovered lines: 31
Coverable lines: 77
Total lines: 169
Line coverage: 59.7%
Branch coverage
57%
Covered branches: 15
Total branches: 26
Branch coverage: 57.6%
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%1281.81%
Equals(...)50%475%
GetHashCode()100%10%
op_Equality(...)75%480%
op_Inequality(...)100%1100%

File(s)

D:\a\Morpho\Morpho\project\Morpho\Morpho25\Geometry\Plant2d.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("Simple Plant")]
 11    /// <summary>
 12    /// Plant 2D class.
 13    /// </summary>
 14    public class Plant2d : Entity, IEquatable<Plant2d>
 15    {
 16        [DisplayName("Name")]
 17        [Description("Name of the simple plant group")]
 18        [JsonProperty("name")]
 19        /// <summary>
 20        /// Name of the plant 2D.
 21        /// </summary>
 322        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 plant 2D.
 29        /// </summary>
 630        public FaceGroup Geometry { get; set; }
 31
 32        [JsonIgnore]
 33        /// <summary>
 34        /// Matrix 2D of the plant 2D.
 35        /// </summary>
 036        public Matrix2d IDmatrix { get; private set; }
 37
 38        [DisplayName("Material")]
 39        [Description("Simple plant type")]
 40        [JsonProperty("material")]
 41        /// <summary>
 42        /// Material of the plant 2D.
 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
 58        [JsonConstructor]
 59        /// <summary>
 60        /// Create a new plant 2D.
 61        /// </summary>
 62        /// <param name="geometry">Geometry of the plant 2D.</param>
 63        /// <param name="id">Numerical ID.</param>
 64        /// <param name="code">Code of the material.</param>
 65        /// <param name="name">Name of the plant 2D.</param>
 366        public Plant2d(FaceGroup geometry,
 367            int id, string code = null, string name = null)
 368        {
 369            ID = id;
 370            Geometry = geometry;
 371            Material = (code != null)
 372                ? CreateMaterial(Material.DEFAULT_PLANT_2D, code)
 373                : CreateMaterial(Material.DEFAULT_PLANT_2D);
 374            Name = name ?? "PlantGroup";
 375        }
 76
 77        public void SetMatrix(Grid grid)
 078        {
 079            Matrix2d matrix = new Matrix2d(grid.Size.NumX, grid.Size.NumY, "");
 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
 89        /// <summary>
 90        /// String representation of the plant 2D.
 91        /// </summary>
 92        /// <returns>String representation.</returns>
 93        public override string ToString()
 094        {
 095            return String.Format("Plant2D::{0}::{1}::{2}",
 096                Name, ID, Material.IDs[0]);
 097        }
 98
 99        public string Serialize()
 1100        {
 1101            return JsonConvert.SerializeObject(this);
 1102        }
 103
 104        public static Plant2d Deserialize(string json)
 1105        {
 106            try
 1107            {
 1108                return JsonConvert.DeserializeObject<Plant2d>(json);
 109            }
 0110            catch (Exception e)
 0111            {
 0112                throw new Exception(e.Message);
 113            }
 1114        }
 115
 116        public bool Equals(Plant2d other)
 1117        {
 1118            if (other == null)
 0119                return false;
 120
 1121            if (other != null
 1122                && other.ID == this.ID
 1123                && other.Name == this.Name
 1124                && other.Material == this.Material
 1125                && other.Geometry == this.Geometry)
 1126                return true;
 127            else
 0128                return false;
 1129        }
 130
 131        public override bool Equals(Object obj)
 14132        {
 14133            if (obj == null)
 0134                return false;
 135
 14136            var plantObj = obj as Plant2d;
 14137            if (plantObj == null)
 14138                return false;
 139            else
 0140                return Equals(plantObj);
 14141        }
 142
 143        public override int GetHashCode()
 0144        {
 145            unchecked
 0146            {
 0147                int hash = 17;
 0148                hash = hash * 23 + ID.GetHashCode();
 0149                hash = hash * 23 + Name.GetHashCode();
 0150                hash = hash * 23 + Material.GetHashCode();
 0151                hash = hash * 23 + Geometry.GetHashCode();
 0152                return hash;
 153            }
 0154        }
 155
 156        public static bool operator ==(Plant2d plant1, Plant2d plant2)
 16157        {
 16158            if (((object)plant1) == null || ((object)plant2) == null)
 16159                return Object.Equals(plant1, plant2);
 160
 0161            return plant1.Equals(plant2);
 16162        }
 163
 164        public static bool operator !=(Plant2d plant1, Plant2d plant2)
 1165        {
 1166            return !(plant1 == plant2);
 1167        }
 168    }
 169}