< Summary

Information
Class: Morpho25.Settings.Model
Assembly: Morpho25
File(s): D:\a\Morpho\Morpho\project\Morpho\Morpho25\Settings\Model.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 107
Coverable lines: 107
Total lines: 160
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 16
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_EnvimetMatrix()100%10%
get_Workspace()100%10%
get_Grid()100%10%
get_Location()100%10%
get_BuildingObjects()100%10%
get_Plant2dObjects()100%10%
get_Plant3dObjects()100%10%
get_SoilObjects()100%10%
get_TerrainObjects()100%10%
get_SourceObjects()100%10%
get_ReceptorObjects()100%10%
get_IsDetailed()100%10%
get_ShiftEachVoxel()100%10%
.ctor(...)100%10%
.ctor(...)100%10%
Calculation()0%140%
ToString()0%20%
SetBuilding()100%10%
SetSoil()100%10%
SetPlant2d()100%10%
SetPlant3d()100%10%
SetReceptor()100%10%
SetTerrain()100%10%
SetSource()100%10%
SetDefaultMatrix(...)100%10%

File(s)

D:\a\Morpho\Morpho\project\Morpho\Morpho25\Settings\Model.cs

#LineLine coverage
 1using Morpho25.Geometry;
 2using Morpho25.Management;
 3using System;
 4using System.Collections.Generic;
 5using System.Linq;
 6
 7namespace Morpho25.Settings
 8{
 9    public class Model
 10    {
 011        public Dictionary<string, Matrix2d> EnvimetMatrix { get; private set; }
 12
 013        public Workspace Workspace { get; }
 014        public Grid Grid { get; }
 015        public Location Location { get; }
 016        public List<Building> BuildingObjects { get; set; }
 017        public List<Plant2d> Plant2dObjects { get; set; }
 018        public List<Plant3d> Plant3dObjects { get; set; }
 019        public List<Soil> SoilObjects { get; set; }
 020        public List<Terrain> TerrainObjects { get; set; }
 021        public List<Source> SourceObjects { get; set; }
 022        public List<Receptor> ReceptorObjects { get; set; }
 23
 024        public bool IsDetailed { get; set; }
 025        public bool ShiftEachVoxel { get; set; }
 26
 027        public Model(Grid grid, Location location)
 028        {
 029            EnvimetMatrix = new Dictionary<string, Matrix2d>();
 030            Grid = grid;
 031            Location = location;
 032            BuildingObjects = new List<Building>();
 033            Plant2dObjects = new List<Plant2d>();
 034            Plant3dObjects = new List<Plant3d>();
 035            SoilObjects = new List<Soil>();
 036            TerrainObjects = new List<Terrain>();
 037            SourceObjects = new List<Source>();
 038            ReceptorObjects = new List<Receptor>();
 039        }
 40
 41        public Model(Grid grid, Location location, Workspace workspace)
 042            : this(grid, location)
 043        {
 044            Workspace = workspace;
 045        }
 46
 47        public void Calculation()
 048        {
 049            SetDefaultMatrix(Grid);
 50
 051            if (TerrainObjects.Count > 0)
 052                SetTerrain();
 53
 054            if (Plant2dObjects.Count > 0)
 055                SetPlant2d();
 56
 057            if (BuildingObjects.Count > 0)
 058                SetBuilding();
 59
 060            if (Plant3dObjects.Count > 0)
 061                SetPlant3d();
 62
 063            if (ReceptorObjects.Count > 0)
 064                SetReceptor();
 65
 066            if (SoilObjects.Count > 0)
 067                SetSoil();
 68
 069            if (SourceObjects.Count > 0)
 070                SetSource();
 71
 072        }
 73
 74        public override string ToString()
 075        {
 076            var label = IsDetailed ? "3D" : "2.5D";
 077            return String.Format("EnvimetINX::{0}", label);
 078        }
 79
 80
 81        private void SetBuilding()
 082        {
 083            BuildingObjects.ForEach(_ => _.SetMatrix(Grid));
 84
 085            List<Building> buildings = BuildingObjects.OrderBy(b => b.ID).ToList();
 086            List<Matrix2d> topMatrixList = buildings.Select(b => b.TopMatrix).ToList();
 087            List<Matrix2d> bottomMatrixList = buildings.Select(b => b.BottomMatrix).ToList();
 088            List<Matrix2d> idMatrixList = buildings.Select(b => b.IDmatrix).ToList();
 89
 090            Matrix2d topMatrix = Matrix2d.MergeMatrix(topMatrixList, "0");
 091            Matrix2d bottomMatrix = Matrix2d.MergeMatrix(bottomMatrixList, "0");
 092            Matrix2d idMatrix = Matrix2d.MergeMatrix(idMatrixList, "0");
 93
 094            EnvimetMatrix["topMatrix"] = topMatrix;
 095            EnvimetMatrix["bottomMatrix"] = bottomMatrix;
 096            EnvimetMatrix["idMatrix"] = idMatrix;
 097        }
 98
 99        private void SetSoil()
 0100        {
 0101            SoilObjects.ForEach(_ => _.SetMatrix(Grid));
 102
 0103            List<Soil> soils = SoilObjects.OrderBy(e => e.ID).ToList();
 0104            List<Matrix2d> matrixList = soils.Select(e => e.IDmatrix).ToList();
 0105            Matrix2d soilMatrix = Matrix2d.MergeMatrix(matrixList, Material.DEFAULT_SOIL);
 0106            EnvimetMatrix["soilMatrix"] = soilMatrix;
 0107        }
 108
 109        private void SetPlant2d()
 0110        {
 0111            Plant2dObjects.ForEach(_ => _.SetMatrix(Grid));
 112
 0113            List<Plant2d> plants = Plant2dObjects.OrderBy(e => e.ID).ToList();
 0114            List<Matrix2d> matrixList = plants.Select(e => e.IDmatrix).ToList();
 0115            Matrix2d plantMatrix = Matrix2d.MergeMatrix(matrixList, "");
 0116            EnvimetMatrix.Add("plantMatrix", plantMatrix);
 0117        }
 118
 119        private void SetPlant3d()
 0120        {
 0121            Plant3dObjects.ForEach(_ => _.SetPixel(Grid));
 0122        }
 123
 124        private void SetReceptor()
 0125        {
 0126            ReceptorObjects.ForEach(_ => _.SetPixel(Grid));
 0127        }
 128
 129        private void SetTerrain()
 0130        {
 0131            TerrainObjects.ForEach(_ => _.SetMatrix(Grid));
 132
 0133            List<Terrain> terrain = TerrainObjects.OrderBy(e => e.ID).ToList();
 0134            List<Matrix2d> matrixList = terrain.Select(e => e.IDmatrix).ToList();
 0135            Matrix2d terrainMatrix = Matrix2d.MergeMatrix(matrixList, "0");
 0136            EnvimetMatrix["terrainMatrix"] = terrainMatrix;
 0137        }
 138
 139        private void SetSource()
 0140        {
 0141            SourceObjects.ForEach(_ => _.SetMatrix(Grid));
 142
 0143            List<Source> sources = SourceObjects.OrderBy(e => e.ID).ToList();
 0144            List<Matrix2d> matrixList = sources.Select(e => e.IDmatrix).ToList();
 0145            Matrix2d sourceMatrix = Matrix2d.MergeMatrix(matrixList, "");
 0146            EnvimetMatrix.Add("sourceMatrix", sourceMatrix);
 0147        }
 148
 149        private void SetDefaultMatrix(Grid grid)
 0150        {
 0151            Matrix2d matrix = new Matrix2d(grid.Size.NumX, grid.Size.NumY, "0");
 0152            Matrix2d matrixSoil = new Matrix2d(grid.Size.NumX, grid.Size.NumY, Material.DEFAULT_SOIL);
 0153            EnvimetMatrix.Add("topMatrix", matrix);
 0154            EnvimetMatrix.Add("bottomMatrix", matrix);
 0155            EnvimetMatrix.Add("idMatrix", matrix);
 0156            EnvimetMatrix.Add("terrainMatrix", matrix);
 0157            EnvimetMatrix.Add("soilMatrix", matrixSoil);
 0158        }
 159    }
 160}