< Summary

Information
Class: Morpho25.Geometry.CellDimension
Assembly: Morpho25
File(s): D:\a\Morpho\Morpho\project\Morpho\Morpho25\Geometry\CellDimension.cs
Line coverage
47%
Covered lines: 25
Uncovered lines: 28
Coverable lines: 53
Total lines: 114
Line coverage: 47.1%
Branch coverage
44%
Covered branches: 8
Total branches: 18
Branch coverage: 44.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
get_X()100%1100%
get_Y()100%1100%
get_Z()100%1100%
Serialize()100%10%
Deserialize(...)100%10%
Equals(...)50%1080%
Equals(...)0%40%
GetHashCode()100%10%
op_Equality(...)75%4100%
op_Inequality(...)100%1100%

File(s)

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

#LineLine coverage
 1using Newtonsoft.Json;
 2using System;
 3using System.ComponentModel.DataAnnotations;
 4
 5namespace Morpho25.Geometry
 6{
 7    /// <summary>
 8    /// Cell dimension struct.
 9    /// </summary>
 10    public class CellDimension : IEquatable<CellDimension>
 11    {
 12        [JsonConstructor]
 13        /// <summary>
 14        /// Create a new cell.
 15        /// </summary>
 16        /// <param name="x">X coordinate.</param>
 17        /// <param name="y">Y coordinate.</param>
 18        /// <param name="z">Z coordinate.</param>
 1219        public CellDimension(double x, double y, double z)
 1220        {
 1221            X = x;
 1222            Y = y;
 1223            Z = z;
 1224        }
 25
 26        [Range(0.1, double.MaxValue, ErrorMessage = "Only positive number allowed.")]
 27        [JsonProperty("x")]
 28        /// <summary>
 29        /// X coordinate.
 30        /// </summary>
 181831        public double X { get; }
 32
 33        [Range(0.1, double.MaxValue, ErrorMessage = "Only positive number allowed.")]
 34        [JsonProperty("y")]
 35        /// <summary>
 36        /// Y coordinate.
 37        /// </summary>
 181838        public double Y { get; }
 39
 40        [Range(0.1, double.MaxValue, ErrorMessage = "Only positive number allowed.")]
 41        [JsonProperty("z")]
 42        /// <summary>
 43        /// Z coordinate.
 44        /// </summary>
 4445        public double Z { get; }
 46
 47        public string Serialize()
 048        {
 049            return JsonConvert.SerializeObject(this);
 050        }
 51
 52        public static CellDimension Deserialize(string json)
 053        {
 54            try
 055            {
 056                return JsonConvert.DeserializeObject<CellDimension>(json);
 57            }
 058            catch (Exception e)
 059            {
 060                throw new Exception(e.Message);
 61            }
 062        }
 63        public bool Equals(CellDimension other)
 264        {
 265            if (other == null)
 066                return false;
 67
 268            if (other != null
 269                && other.X == this.X
 270                && other.Y == this.Y
 271                && other.Z == this.Z)
 272                return true;
 73            else
 074                return false;
 275        }
 76
 77        public override bool Equals(Object obj)
 078        {
 079            if (obj == null)
 080                return false;
 81
 082            var dimObj = obj as CellDimension;
 083            if (dimObj == null)
 084                return false;
 85            else
 086                return Equals(dimObj);
 087        }
 88
 89        public override int GetHashCode()
 090        {
 91            unchecked
 092            {
 093                int hash = 17;
 094                hash = hash * 23 + X.GetHashCode();
 095                hash = hash * 23 + Y.GetHashCode();
 096                hash = hash * 23 + Z.GetHashCode();
 097                return hash;
 98            }
 099        }
 100
 101        public static bool operator ==(CellDimension dim1, CellDimension dim2)
 6102        {
 6103            if (((object)dim1) == null || ((object)dim2) == null)
 4104                return Object.Equals(dim1, dim2);
 105
 2106            return dim1.Equals(dim2);
 6107        }
 108
 109        public static bool operator !=(CellDimension dim1, CellDimension dim2)
 2110        {
 2111            return !(dim1 == dim2);
 2112        }
 113    }
 114}