< Summary

Information
Class: MorphoGeometry.Ray
Assembly: MorphoGeometry
File(s): D:\a\Morpho\Morpho\project\Morpho\MorphoGeometry\Ray.cs
Line coverage
70%
Covered lines: 36
Uncovered lines: 15
Coverable lines: 51
Total lines: 111
Line coverage: 70.5%
Branch coverage
56%
Covered branches: 9
Total branches: 16
Branch coverage: 56.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
ToString()100%10%
Serialize()100%1100%
Deserialize(...)100%1100%
Equals(...)50%877.77%
Equals(...)50%475%
GetHashCode()100%10%
op_Equality(...)75%480%
op_Inequality(...)100%1100%

File(s)

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

#LineLine coverage
 1using Newtonsoft.Json;
 2using System;
 3
 4namespace MorphoGeometry
 5{
 6    /// <summary>
 7    /// Ray class.
 8    /// </summary>
 9    public class Ray : IEquatable<Ray>
 10    {
 11        [JsonProperty(Required = Required.Always)]
 12        /// <summary>
 13        /// Ray origin.
 14        /// </summary>
 15        public Vector origin;
 16
 17        [JsonProperty(Required = Required.Always)]
 18        /// <summary>
 19        /// Direction of the ray.
 20        /// </summary>
 21        public Vector direction;
 22
 23        [JsonConstructor]
 24        /// <summary>
 25        /// Create a new Ray.
 26        /// </summary>
 27        /// <param name="origin">Origin of the ray.</param>
 28        /// <param name="direction">Direction of the ray.</param>
 329        public Ray(Vector origin,
 330            Vector direction)
 331        {
 332            this.origin = origin;
 333            this.direction = direction;
 334        }
 35
 36        /// <summary>
 37        /// String representation of the ray.
 38        /// </summary>
 39        /// <returns>String representation.</returns>
 40        public override String ToString()
 041        {
 042            return string.Format("Ray::{0}", direction);
 043        }
 44
 45        public string Serialize()
 146        {
 147            return JsonConvert.SerializeObject(this);
 148        }
 49
 50        public static Ray Deserialize(string json)
 251        {
 52            try
 253            {
 254                return JsonConvert.DeserializeObject<Ray>(json);
 55            }
 156            catch (Exception e)
 157            {
 158                throw new Exception(e.Message);
 59            }
 160        }
 61
 62        public bool Equals(Ray other)
 163        {
 164            if (other == null)
 065                return false;
 66
 167            if (other != null
 168                && other.origin == this.origin
 169                && other.direction == this.direction)
 170                return true;
 71            else
 072                return false;
 173        }
 74
 75        public override bool Equals(Object obj)
 276        {
 277            if (obj == null)
 078                return false;
 79
 280            var rayObj = obj as Ray;
 281            if (rayObj == null)
 282                return false;
 83            else
 084                return Equals(rayObj);
 285        }
 86
 87        public override int GetHashCode()
 088        {
 89            unchecked
 090            {
 091                int hash = 17;
 092                hash = hash * 23 + origin.GetHashCode();
 093                hash = hash * 23 + direction.GetHashCode();
 094                return hash;
 95            }
 096        }
 97
 98        public static bool operator ==(Ray ray1, Ray ray2)
 499        {
 4100            if (((object)ray1) == null || ((object)ray2) == null)
 4101                return Object.Equals(ray1, ray2);
 102
 0103            return ray1.Equals(ray2);
 4104        }
 105
 106        public static bool operator !=(Ray ray1, Ray ray2)
 1107        {
 1108            return !(ray1 == ray2);
 1109        }
 110    }
 111}