< Summary

Information
Class: MorphoGeometry.FaceGroup
Assembly: MorphoGeometry
File(s): D:\a\Morpho\Morpho\project\Morpho\MorphoGeometry\FaceGroup.cs
Line coverage
63%
Covered lines: 46
Uncovered lines: 26
Coverable lines: 72
Total lines: 135
Line coverage: 63.8%
Branch coverage
66%
Covered branches: 12
Total branches: 18
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_Faces()100%1100%
.ctor(...)100%1100%
ToArray()100%10%
TriangulateFaces(...)75%468.75%
ToString()100%10%
Serialize()100%1100%
Deserialize(...)100%1100%
Equals(...)50%675%
Equals(...)50%475%
GetHashCode()100%10%
op_Equality(...)100%4100%
op_Inequality(...)100%1100%

File(s)

D:\a\Morpho\Morpho\project\Morpho\MorphoGeometry\FaceGroup.cs

#LineLine coverage
 1using Newtonsoft.Json;
 2using System;
 3using System.Collections.Generic;
 4using System.Linq;
 5
 6namespace MorphoGeometry
 7{
 8    /// <summary>
 9    /// Facegroup class.
 10    /// </summary>
 11    public class FaceGroup : IEquatable<FaceGroup>
 12    {
 13        [JsonProperty("faces", Required = Required.Always)]
 14        /// <summary>
 15        /// Faces of the facegroup.
 16        /// </summary>
 1817        public List<Face> Faces { get; }
 18
 19        [JsonConstructor]
 20        /// <summary>
 21        /// Create a new facegroup.
 22        /// </summary>
 23        /// <param name="faces">Faces.</param>
 1824        public FaceGroup(List<Face> faces)
 1825        {
 1826            Faces = TriangulateFaces(faces);
 1827        }
 28
 29        /// <summary>
 30        /// Convert facegroup to array of float.
 31        /// </summary>
 32        /// <returns>Jagged array.</returns>
 33        public float[][][] ToArray()
 034        {
 035            return Faces
 036                .Select(face => {
 037                    return face.Vertices
 038                        .Select(_ => _.ToArray())
 039                        .ToArray();
 040                }).ToArray();
 041        }
 42
 43        private static List<Face> TriangulateFaces(List<Face> faces)
 1844        {
 1845            List<Face> outFaces = new List<Face>();
 12646            foreach (Face face in faces)
 3647            {
 3648                if (face.IsQuad())
 049                {
 050                    Face[] tFaces = Face.Triangulate(face);
 051                    outFaces.Add(tFaces[0]);
 052                    outFaces.Add(tFaces[1]);
 053                }
 54                else
 3655                {
 3656                    outFaces.Add(face);
 3657                }
 3658            }
 1859            return outFaces;
 1860        }
 61
 62        /// <summary>
 63        /// String representation of facegroup.
 64        /// </summary>
 65        /// <returns>String representation.</returns>
 66        public override String ToString()
 067        {
 068            return string.Format("FaceGroup::{0}", Faces.Count);
 069        }
 70
 71        public string Serialize()
 172        {
 173            return JsonConvert.SerializeObject(this);
 174        }
 75
 76        public static FaceGroup Deserialize(string json)
 277        {
 78            try
 279            {
 280                return JsonConvert.DeserializeObject<FaceGroup>(json);
 81            }
 182            catch (Exception e)
 183            {
 184                throw new Exception(e.Message);
 85            }
 186        }
 87
 88        public bool Equals(FaceGroup other)
 689        {
 690            if (other == null)
 091                return false;
 92
 693            if (other != null
 694                && Enumerable.SequenceEqual(other.Faces, this.Faces))
 695                return true;
 96            else
 097                return false;
 698        }
 99
 100        public override bool Equals(Object obj)
 66101        {
 66102            if (obj == null)
 0103                return false;
 104
 66105            var fgObj = obj as FaceGroup;
 66106            if (fgObj == null)
 66107                return false;
 108            else
 0109                return Equals(fgObj);
 66110        }
 111
 112        public override int GetHashCode()
 0113        {
 114            unchecked
 0115            {
 0116                int hash = 17;
 0117                hash = hash * 23 + Faces.GetHashCode();
 0118                return hash;
 119            }
 0120        }
 121
 122        public static bool operator ==(FaceGroup faceGroup1, FaceGroup faceGroup2)
 83123        {
 83124            if (((object)faceGroup1) == null || ((object)faceGroup2) == null)
 78125                return Object.Equals(faceGroup1, faceGroup2);
 126
 5127            return faceGroup1.Equals(faceGroup2);
 83128        }
 129
 130        public static bool operator !=(FaceGroup faceGroup1, FaceGroup faceGroup2)
 6131        {
 6132            return !(faceGroup1 == faceGroup2);
 6133        }
 134    }
 135}