< Summary

Information
Class: Morpho25.Geometry.Size
Assembly: Morpho25
File(s): D:\a\Morpho\Morpho\project\Morpho\Morpho25\Geometry\Size.cs
Line coverage
70%
Covered lines: 64
Uncovered lines: 27
Coverable lines: 91
Total lines: 226
Line coverage: 70.3%
Branch coverage
59%
Covered branches: 13
Total branches: 22
Branch coverage: 59%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
.ctor()100%1100%
get_CellDimension()100%1100%
get_NumX()100%1100%
get_NumY()100%1100%
get_NumZ()100%1100%
get_MinX()100%1100%
get_MinY()100%1100%
get_MaxX()100%10%
get_MaxY()100%10%
get_DimX()100%1100%
get_DimY()100%1100%
get_DimZ()100%1100%
get_Origin()100%1100%
ToString()100%10%
Serialize()100%1100%
Deserialize(...)100%10%
Equals(...)50%1483.33%
Equals(...)50%475%
GetHashCode()100%10%
op_Equality(...)100%4100%
op_Inequality(...)100%1100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.ComponentModel;
 3using System.ComponentModel.DataAnnotations;
 4using MorphoGeometry;
 5using Newtonsoft.Json;
 6
 7namespace Morpho25.Geometry
 8{
 9    /// <summary>
 10    /// Grid size struct.
 11    /// </summary>
 12    public class Size : IEquatable<Size>
 13    {
 14        [JsonConstructor]
 15        /// <summary>
 16        /// Create a new size object.
 17        /// </summary>
 18        /// <param name="origin">Origin of the grid.</param>
 19        /// <param name="cellDimension">Cell dimension.</param>
 20        /// <param name="numX">Number of X cells.</param>
 21        /// <param name="numY">Number of Y cells.</param>
 22        /// <param name="numZ">Number of Z cells.</param>
 1023        public Size(Vector origin,
 1024            CellDimension cellDimension,
 1025            int numX, int numY,
 1026            int numZ)
 1027        {
 1028            Origin = origin;
 1029            NumX = numX;
 1030            NumY = numY;
 1031            NumZ = numZ;
 32
 1033            CellDimension = cellDimension;
 34
 1035            MinX = Origin.x;
 936            MinY = Origin.y;
 937            MaxX = Origin.x + (NumX * cellDimension.X);
 938            MaxY = Origin.y + (NumY * cellDimension.Y);
 939        }
 40
 41        /// <summary>
 42        /// Default constructor.
 43        /// </summary>
 244        public Size()
 245        {
 246            Origin = new Vector(0, 0, 0);
 247            NumX = 50;
 248            NumY = 50;
 249            NumZ = 25;
 50
 251            CellDimension = new CellDimension(3.0, 3.0, 3.0);
 52
 253            MinX = Origin.x;
 254            MinY = Origin.y;
 255            MaxX = Origin.x + (NumX * CellDimension.X);
 256            MaxY = Origin.y + (NumY * CellDimension.Y);
 257        }
 58
 59        [DisplayName("Cell Dimension")]
 60        [Description("Size of the cell.")]
 61        [JsonProperty("cellDimension")]
 62        /// <summary>
 63        /// Number of X cells.
 64        /// </summary>
 364865        public CellDimension CellDimension { get; }
 66
 67        [DisplayName("Num X")]
 68        [Description("Number of cells in X.")]
 69        [Range(0, int.MaxValue, ErrorMessage = "Only positive number allowed.")]
 70        [JsonProperty("numX")]
 71        /// <summary>
 72        /// Number of X cells.
 73        /// </summary>
 185674        public int NumX { get; }
 75
 76        [DisplayName("Num Y")]
 77        [Description("Number of cells in Y.")]
 78        [Range(0, int.MaxValue, ErrorMessage = "Only positive number allowed.")]
 79        [JsonProperty("numY")]
 80        /// <summary>
 81        /// Number of Y cells.
 82        /// </summary>
 185683        public int NumY { get; }
 84
 85        [DisplayName("Num Z")]
 86        [Description("Number of cells in Z.")]
 87        [Range(0, int.MaxValue, ErrorMessage = "Only positive number allowed.")]
 88        [JsonProperty("numZ")]
 89        /// <summary>
 90        /// Number of Z cells.
 91        /// </summary>
 2692        public int NumZ { get; }
 93
 94        [JsonIgnore]
 95        /// <summary>
 96        /// X of the lower left corner of the grid.
 97        /// </summary>
 180098        public double MinX { get; }
 99
 100        [JsonIgnore]
 101        /// <summary>
 102        /// Y of the lower left corner of the grid.
 103        /// </summary>
 1800104        public double MinY { get; }
 105
 106        [JsonIgnore]
 107        /// <summary>
 108        /// X of the upper right corner of the grid.
 109        /// </summary>
 0110        public double MaxX { get; }
 111
 112        [JsonIgnore]
 113        /// <summary>
 114        /// Y of the upper right corner of the grid.
 115        /// </summary>
 0116        public double MaxY { get; }
 117
 118        [JsonIgnore]
 119        /// <summary>
 120        /// X dimension of the cell.
 121        /// </summary>
 1800122        public double DimX => CellDimension.X;
 123
 124        [JsonIgnore]
 125        /// <summary>
 126        /// Y dimension of the cell.
 127        /// </summary>
 1800128        public double DimY => CellDimension.Y;
 129
 130        [JsonIgnore]
 131        /// <summary>
 132        /// Z dimension of the cell.
 133        /// </summary>
 37134        public double DimZ => CellDimension.Z;
 135
 136        [DisplayName("Origin")]
 137        [Description("Origin of the grid.")]
 138        [JsonProperty("origin")]
 139        /// <summary>
 140        /// Origin of the grid. Lower left corner.
 141        /// </summary>
 52142        public Vector Origin { get; }
 143
 144        /// <summary>
 145        /// String representation of the Grid Size.
 146        /// </summary>
 147        /// <returns>String representation.</returns>
 148        public override string ToString()
 0149        {
 0150            return String.Format("Size::{0},{1},{2}::{3},{4},{5}",
 0151                NumX, NumY, NumZ, DimX, DimY, DimZ);
 0152        }
 153
 154        public string Serialize()
 1155        {
 1156            return JsonConvert.SerializeObject(this);
 1157        }
 158
 159        public static Size Deserialize(string json)
 0160        {
 161            try
 0162            {
 0163                return JsonConvert.DeserializeObject<Size>(json);
 164            }
 0165            catch (Exception e)
 0166            {
 0167                throw new Exception(e.Message);
 168            }
 0169        }
 170
 171        public bool Equals(Size other)
 2172        {
 2173            if (other == null)
 0174                return false;
 175
 2176            if (other != null
 2177                && other.Origin == this.Origin
 2178                && other.CellDimension == this.CellDimension
 2179                && other.NumX == this.NumX
 2180                && other.NumY == this.NumY
 2181                && other.NumZ == this.NumZ)
 2182                return true;
 183            else
 0184                return false;
 2185        }
 186
 187        public override bool Equals(Object obj)
 6188        {
 6189            if (obj == null)
 0190                return false;
 191
 6192            var sizeObj = obj as Size;
 6193            if (sizeObj == null)
 6194                return false;
 195            else
 0196                return Equals(sizeObj);
 6197        }
 198
 199        public override int GetHashCode()
 0200        {
 201            unchecked
 0202            {
 0203                int hash = 17;
 0204                hash = hash * 23 + NumX.GetHashCode();
 0205                hash = hash * 23 + NumY.GetHashCode();
 0206                hash = hash * 23 + NumZ.GetHashCode();
 0207                hash = hash * 23 + CellDimension.GetHashCode();
 0208                hash = hash * 23 + Origin.GetHashCode();
 0209                return hash;
 210            }
 0211        }
 212
 213        public static bool operator ==(Size size1, Size size2)
 12214        {
 12215            if (((object)size1) == null || ((object)size2) == null)
 10216                return Object.Equals(size1, size2);
 217
 2218            return size1.Equals(size2);
 12219        }
 220
 221        public static bool operator !=(Size size1, Size size2)
 2222        {
 2223            return !(size1 == size2);
 2224        }
 225    }
 226}