< Summary - ReFlex - Library

Information
Class: ReFlex.Core.Common.Components.PointCloud3
Assembly: ReFlex.Core.Common
File(s): D:\a\reflex\reflex\library\src\Core\Common\Components\PointCloud3.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 37
Coverable lines: 37
Total lines: 163
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 14
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Item(...)0%4260%
set_Item(...)0%620%
get_Item(...)0%620%
set_Item(...)0%620%
get_Size()100%210%
get_SizeX()100%210%
get_SizeY()100%210%
.ctor(...)100%210%
Update(...)0%620%
Initialize(...)100%210%
AsArray()100%210%
AsSpan()100%210%
AsMemory()100%210%
AsJaggedArray()100%210%

File(s)

D:\a\reflex\reflex\library\src\Core\Common\Components\PointCloud3.cs

#LineLine coverage
 1using System;
 2using System.Threading.Tasks;
 3using ReFlex.Core.Common.Interfaces;
 4
 5namespace ReFlex.Core.Common.Components
 6{
 7    /// <summary>
 8    /// A ordered Quantity of <see cref="Point3" />
 9    /// </summary>
 10    /// <seealso cref="IPointCloud{Point3}" />
 11    /// <inheritdoc />
 12    public class PointCloud3 : IDepthImage<Point3>
 13    {
 14        #region fields
 15
 16        private Point3[] _values1D;
 17        private Point3[][] _values2D;
 18
 19        #endregion
 20
 21        #region indexer
 22
 23        /// <summary>
 24        /// Gets or sets the <see cref="Point3" /> at the specified index.
 25        /// </summary>
 26        /// <value>
 27        /// The <see cref="Point3" />.
 28        /// </value>
 29        /// <param name="index">The index.</param>
 30        /// <returns></returns>
 31        /// <inheritdoc />
 32        public Point3 this[int index]
 33        {
 34            get
 035            {
 036                if(index < 0 || index >= Size)
 037                    return new Point3();
 038                return _values1D[index] ?? (_values1D[index] = new Point3());
 039            }
 040            set => _values1D[index]?.Set(value);
 41        }
 42
 43        /// <summary>
 44        /// Gets or sets the <see cref="Point3" /> with the specified x.
 45        /// </summary>
 46        /// <value>
 47        /// The <see cref="Point3" />.
 48        /// </value>
 49        /// <param name="x">The x.</param>
 50        /// <param name="y">The y.</param>
 51        /// <returns></returns>
 52        /// <inheritdoc />
 53        public Point3 this[int x, int y]
 54        {
 055            get => _values2D[x][y] ?? (_values2D[x][y] = new Point3());
 056            set => _values2D[x][y]?.Set(value);
 57        }
 58
 59        #endregion
 60
 61        #region properties
 62
 63        /// <summary>
 64        /// Gets the size.
 65        /// </summary>
 66        /// <value>
 67        /// The size.
 68        /// </value>
 69        /// <inheritdoc />
 070        public int Size { get; private set; }
 71
 72        /// <summary>
 73        /// Gets the horizontal size.
 74        /// </summary>
 75        /// <value>
 76        /// The horizontal size.
 77        /// </value>
 78        /// <inheritdoc />
 079        public int SizeX { get; private set; }
 80
 81        /// <summary>
 82        /// Gets the vertical size.
 83        /// </summary>
 84        /// <value>
 85        /// The vertical size.
 86        /// </value>
 87        /// <inheritdoc />
 088        public int SizeY { get; private set; }
 89
 90        #endregion
 91
 92        #region constructor
 93
 94        /// <summary>
 95        /// Initializes a new instance of the <see cref="PointCloud3" /> class.
 96        /// </summary>
 97        /// <param name="sizeX">The size x.</param>
 98        /// <param name="sizeY">The size y.</param>
 099        public PointCloud3(int sizeX, int sizeY) => Initialize(sizeX, sizeY);
 100
 101        #endregion
 102
 103        #region methods
 104
 105        // /// <summary>
 106        // /// Updates [this] instance with the data of the specified source.
 107        // /// </summary>
 108        // /// <param name="source">The source value.</param>
 109        // /// <inheritdoc />
 110        // public void Update(Point3[] source)
 111        // {
 112        //     for (int i = 0; i < source.Length; ++i) {
 113        //         _values1D[i].Set(source[i]);
 114        //     }
 115        // }
 116
 117        /// <summary>
 118        /// Updates [this] instance with the data of the specified source.
 119        /// </summary>
 120        /// <param name="source">The source value.</param>
 121        /// <inheritdoc />
 122        public void Update(ReadOnlyMemory<Point3> source, float defaultZ)
 0123        {
 0124            Parallel.For(0, source.Length, i =>
 0125                {
 0126                    _values1D[i].Set(source.Span[i]);
 0127
 0128                    var val = source.Span[i];
 0129                    var target = _values1D[i];
 0130                    _values1D[i].Set(target.IsValid
 0131                            ? source.Span[i]
 0132                            : new Point3(val.X, val.Y, defaultZ));
 0133                }
 0134            );
 0135        }
 136
 137        /// <summary>
 138        /// Initializes the specified size y.
 139        /// </summary>
 140        /// <param name="sizeX">The size x.</param>
 141        /// <param name="sizeY">The size y.</param>
 142        public void Initialize(int sizeX, int sizeY)
 0143        {
 0144            SizeX = sizeX;
 0145            SizeY = sizeY;
 0146            Size = sizeX * sizeY;
 147
 0148            ArrayUtils.InitializeArray(out _values1D, Size);
 0149            ArrayUtils.InitializeArray(out _values2D, SizeX, sizeY);
 0150            ArrayUtils.ReferencingArrays(_values1D, _values2D);
 0151        }
 152
 0153        public Point3[] AsArray() => _values1D;
 154
 0155        public Span<Point3> AsSpan() => _values1D.AsSpan();
 156
 0157        public Memory<Point3> AsMemory() => _values1D.AsMemory();
 158
 0159        public Point3[][] AsJaggedArray() => _values2D;
 160
 161        #endregion
 162    }
 163}