< Summary

Information
Class: Morpho25.Geometry.Entity
Assembly: Morpho25
File(s): D:\a\Morpho\Morpho\project\Morpho\Morpho25\Geometry\Entity.cs
Line coverage
45%
Covered lines: 9
Uncovered lines: 11
Coverable lines: 20
Total lines: 80
Line coverage: 45%
Branch coverage
37%
Covered branches: 3
Total branches: 8
Branch coverage: 37.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_ID()100%1100%
set_ID(...)50%266.66%
SetMatrix(...)0%40%
CreateMaterial(...)100%2100%

File(s)

D:\a\Morpho\Morpho\project\Morpho\Morpho25\Geometry\Entity.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    /// <summary>
 11    /// Entity class.
 12    /// </summary>
 13    public abstract class Entity
 14    {
 15        protected string _name;
 16        protected Material _material;
 17        protected int _ID;
 18
 19        /// <summary>
 20        /// Material of the entity.
 21        /// </summary>
 22        public abstract Material Material { get; protected set; }
 23
 24        /// <summary>
 25        /// Name of the entity.
 26        /// </summary>
 27        public abstract string Name { get; }
 28
 29        [DisplayName("ID")]
 30        [Description("Numeric ID of the entity")]
 31        [JsonProperty("id")]
 32        /// <summary>
 33        /// ID of the entity.
 34        /// </summary>
 35        public int ID {
 5136            get { return _ID; }
 37            protected set
 1738            {
 1739                if (value < 0)
 040                    throw new ArgumentOutOfRangeException(
 041                          $"{nameof(value)} must be positive.");
 42
 1743                _ID = value;
 1744            }
 45        }
 46
 47        /// <summary>
 48        /// Set 2D Matrix.
 49        /// </summary>
 50        /// <param name="intersection">Intersection points.</param>
 51        /// <param name="grid">Grid object.</param>
 52        /// <param name="matrix">2D Matrix to map.</param>
 53        /// <param name="text">Optional text to use.</param>
 54        protected void SetMatrix(IEnumerable<Vector> intersection,
 55            Grid grid, Matrix2d matrix, String text = "")
 056        {
 057            foreach (Vector vec in intersection)
 058            {
 059                var pixel = vec.ToPixel(grid);
 60
 061                matrix[pixel.I, pixel.J] = (text == String.Empty)
 062                    ? Math.Round(vec.z, 0).ToString()
 063                    : text;
 064            }
 065        }
 66
 67        /// <summary>
 68        /// Create a new material.
 69        /// </summary>
 70        /// <param name="defaultCode">Default material ID.</param>
 71        /// <param name="code">Custom material ID.</param>
 72        /// <returns>New material object.</returns>
 73        protected Material CreateMaterial(string defaultCode, string code = null)
 1274        {
 1275            string material = code ?? defaultCode;
 76
 1277            return new Material(new string[] { material });
 1278        }
 79    }
 80}