< Summary

Information
Class: Morpho25.Geometry.Source
Assembly: Morpho25
File(s): D:\a\Morpho\Morpho\project\Morpho\Morpho25\Geometry\Source.cs
Line coverage
60%
Covered lines: 47
Uncovered lines: 31
Coverable lines: 78
Total lines: 170
Line coverage: 60.2%
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\Source.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("Source")]
 11    /// <summary>
 12    /// Source class.
 13    /// </summary>
 14    public class Source : Entity, IEquatable<Source>
 15    {
 16        [DisplayName("Name")]
 17        [Description("Name of the source group")]
 18        [JsonProperty("name")]
 19        /// <summary>
 20        /// Name of the source.
 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 source.
 29        /// </summary>
 630        public FaceGroup Geometry { get; set; }
 31
 32        [JsonIgnore]
 33        /// <summary>
 34        /// Matrix of the source.
 35        /// </summary>
 036        public Matrix2d IDmatrix { get; private set; }
 37
 38        [DisplayName("Material")]
 39        [Description("Source type")]
 40        [JsonProperty("material")]
 41        /// <summary>
 42        /// Material of the source.
 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 source.
 61        /// </summary>
 62        /// <param name="geometry">Geometry of the source.</param>
 63        /// <param name="id">Numerical ID.</param>
 64        /// <param name="code">Code of the material.</param>
 65        /// <param name="name">Name of the source.</param>
 366        public Source(FaceGroup geometry,
 367            int id, string code = null,
 368            string name = null)
 369        {
 370            ID = id;
 371            Geometry = geometry;
 372            Material = (code != null)
 373                ? CreateMaterial(Material.DEFAULT_SOURCE, code)
 374                : CreateMaterial(Material.DEFAULT_SOURCE);
 375            Name = name ?? "SourceGroup";
 376        }
 77
 78        public void SetMatrix(Grid grid)
 079        {
 080            Matrix2d matrix = new Matrix2d(grid.Size.NumX, grid.Size.NumY, "");
 81
 082            List<Ray> rays = EnvimetUtility.GetRayFromFacegroupBbox(grid, Geometry);
 83
 084            var intersection = EnvimetUtility.Raycasting2D(rays, Geometry, false, false);
 085            SetMatrix(intersection, grid, matrix, Material.IDs[0]);
 86
 087            IDmatrix = matrix;
 088        }
 89        /// <summary>
 90        /// String representation of the source.
 91        /// </summary>
 92        /// <returns>String representation.</returns>
 93        public override string ToString()
 094        {
 095            return String.Format("Source::{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 Source Deserialize(string json)
 1105        {
 106            try
 1107            {
 1108                return JsonConvert.DeserializeObject<Source>(json);
 109            }
 0110            catch (Exception e)
 0111            {
 0112                throw new Exception(e.Message);
 113            }
 1114        }
 115
 116        public bool Equals(Source 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 sourceObj = obj as Source;
 14137            if (sourceObj == null)
 14138                return false;
 139            else
 0140                return Equals(sourceObj);
 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 ==(Source source1, Source source2)
 16157        {
 16158            if (((object)source1) == null || ((object)source2) == null)
 16159                return Object.Equals(source1, source2);
 160
 0161            return source1.Equals(source2);
 16162        }
 163
 164        public static bool operator !=(Source source1, Source source2)
 1165        {
 1166            return !(source1 == source2);
 1167        }
 168
 169    }
 170}