< Summary

Information
Class: Morpho25.Geometry.Receptor
Assembly: Morpho25
File(s): D:\a\Morpho\Morpho\project\Morpho\Morpho25\Geometry\Receptor.cs
Line coverage
53%
Covered lines: 34
Uncovered lines: 29
Coverable lines: 63
Total lines: 141
Line coverage: 53.9%
Branch coverage
56%
Covered branches: 9
Total branches: 16
Branch coverage: 56.2%
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_Pixel()100%10%
get_Material()100%10%
set_Material(...)100%10%
.ctor(...)100%1100%
SetPixel(...)100%10%
ToString()100%10%
Serialize()100%1100%
Deserialize(...)100%157.14%
Equals(...)50%877.77%
Equals(...)50%475%
GetHashCode()100%10%
op_Equality(...)75%480%
op_Inequality(...)100%1100%

File(s)

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

#LineLine coverage
 1using Morpho25.Utility;
 2using MorphoGeometry;
 3using Newtonsoft.Json;
 4using System;
 5using System.ComponentModel;
 6
 7namespace Morpho25.Geometry
 8{
 9    [DisplayName("Receptor")]
 10    /// <summary>
 11    /// Receptor class.
 12    /// </summary>
 13    public class Receptor : Entity, IEquatable<Receptor>
 14    {
 15        [DisplayName("Name")]
 16        [Description("Name of the receptor")]
 17        [JsonProperty("name", Required = Required.Always)]
 18        /// <summary>
 19        /// Name of the receptor.
 20        /// </summary>
 321        public override string Name { get; }
 22
 23        [DisplayName("Geometry")]
 24        [Description("Point geometry")]
 25        [JsonProperty("geometry", Required = Required.Always)]
 26        /// <summary>
 27        /// Geometry of the receptor.
 28        /// </summary>
 629        public Vector Geometry { get; set; }
 30
 31        [JsonIgnore]
 32        /// <summary>
 33        /// Location of the receptor in the grid.
 34        /// </summary>
 035        public Pixel Pixel { get; private set; }
 36
 37        [JsonIgnore]
 38        /// <summary>
 39        /// Material of the receptor.
 40        /// </summary>
 41        public override Material Material
 42        {
 043            get => throw new NotImplementedException();
 044            protected set => throw new NotImplementedException();
 45        }
 46        /// <summary>
 47        /// Create a new receptor.
 48        /// </summary>
 49        /// <param name="geometry">Geometry of the receptor.</param>
 50        /// <param name="name">Name of the receptor.</param>
 351        public Receptor(Vector geometry, string name)
 352        {
 353            Geometry = geometry;
 354            Name = name;
 355        }
 56
 57        public void SetPixel(Grid grid)
 058        {
 059            Pixel = new Pixel
 060            {
 061                I = Util.ClosestValue(grid.Xaxis, Geometry.x),
 062                J = Util.ClosestValue(grid.Yaxis, Geometry.y),
 063                K = 0
 064            };
 065        }
 66        /// <summary>
 67        /// String representation of the receptor.
 68        /// </summary>
 69        /// <returns>String representation.</returns>
 70        public override string ToString()
 071        {
 072            return String.Format("Receptor::{0}", Name);
 073        }
 74
 75        public string Serialize()
 176        {
 177            return JsonConvert.SerializeObject(this);
 178        }
 79
 80        public static Receptor Deserialize(string json)
 181        {
 82            try
 183            {
 184                return JsonConvert.DeserializeObject<Receptor>(json);
 85            }
 086            catch (Exception e)
 087            {
 088                throw new Exception(e.Message);
 89            }
 190        }
 91
 92        public bool Equals(Receptor other)
 193        {
 194            if (other == null)
 095                return false;
 96
 197            if (other != null
 198                && other.Name == this.Name
 199                && other.Geometry == this.Geometry)
 1100                return true;
 101            else
 0102                return false;
 1103        }
 104
 105        public override bool Equals(Object obj)
 1106        {
 1107            if (obj == null)
 0108                return false;
 109
 1110            var receptorObj = obj as Receptor;
 1111            if (receptorObj == null)
 1112                return false;
 113            else
 0114                return Equals(receptorObj);
 1115        }
 116
 117        public override int GetHashCode()
 0118        {
 119            unchecked
 0120            {
 0121                int hash = 17;
 0122                hash = hash * 23 + Name.GetHashCode();
 0123                hash = hash * 23 + Geometry.GetHashCode();
 0124                return hash;
 125            }
 0126        }
 127
 128        public static bool operator ==(Receptor receptor1, Receptor receptor2)
 3129        {
 3130            if (((object)receptor1) == null || ((object)receptor2) == null)
 3131                return Object.Equals(receptor1, receptor2);
 132
 0133            return receptor1.Equals(receptor2);
 3134        }
 135
 136        public static bool operator !=(Receptor receptor1, Receptor receptor2)
 1137        {
 1138            return !(receptor1 == receptor2);
 1139        }
 140    }
 141}