< Summary - ReFlex - Library

Information
Class: PointCloud.Benchmark.Common.PointCloud3
Assembly: ReFlex.PointCloud.Benchmark
File(s): D:\a\reflex\reflex\test\Library\Performance\PointCloud.Benchmark\Common\PointCloud3.cs
Line coverage
40%
Covered lines: 26
Uncovered lines: 39
Coverable lines: 65
Total lines: 222
Line coverage: 40%
Branch coverage
40%
Covered branches: 8
Total branches: 20
Branch coverage: 40%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Item(...)83.33%66100%
set_Item(...)0%620%
get_Item(...)50%22100%
set_Item(...)0%620%
get_Size()100%11100%
get_SizeX()100%11100%
get_SizeY()100%11100%
.ctor(...)100%11100%
Update(...)100%22100%
Update(...)0%620%
Update2(...)0%620%
UpdateParallel(...)100%210%
Update(...)0%620%
UpdateParallel(...)100%210%
Initialize(...)100%11100%
AsArray()100%11100%
AsSpan()100%11100%
AsMemory()100%210%
AsJaggedArray()100%11100%
Update(...)100%210%

File(s)

D:\a\reflex\reflex\test\Library\Performance\PointCloud.Benchmark\Common\PointCloud3.cs

#LineLine coverage
 1using ReFlex.Core.Common.Components;
 2using ReFlex.Core.Common.Interfaces;
 3
 4namespace PointCloud.Benchmark.Common
 5{
 6    /// <summary>
 7    /// A ordered Quantity of <see cref="Point3" />
 8    /// </summary>
 9    /// <seealso cref="IPointCloud{Point3}" />
 10    /// <inheritdoc />
 11    public class PointCloud3 : IDepthImage<Point3>
 12    {
 13        #region fields
 14
 15        private Point3[] _values1D;
 16        private Point3[][] _values2D;
 17
 18        #endregion
 19
 20        #region indexer
 21
 22        /// <summary>
 23        /// Gets or sets the <see cref="Point3" /> at the specified index.
 24        /// </summary>
 25        /// <value>
 26        /// The <see cref="Point3" />.
 27        /// </value>
 28        /// <param name="index">The index.</param>
 29        /// <returns></returns>
 30        /// <inheritdoc />
 31        public Point3 this[int index]
 32        {
 33            get
 210953634            {
 210953635                if(index < 0 || index >= Size)
 236                    return new Point3();
 210953437                return _values1D[index] ?? (_values1D[index] = new Point3());
 210953638            }
 039            set => _values1D[index]?.Set(value);
 40        }
 41
 42        /// <summary>
 43        /// Gets or sets the <see cref="Point3" /> with the specified x.
 44        /// </summary>
 45        /// <value>
 46        /// The <see cref="Point3" />.
 47        /// </value>
 48        /// <param name="x">The x.</param>
 49        /// <param name="y">The y.</param>
 50        /// <returns></returns>
 51        /// <inheritdoc />
 52        public Point3 this[int x, int y]
 53        {
 106096254            get => _values2D[x][y] ?? (_values2D[x][y] = new Point3());
 055            set => _values2D[x][y]?.Set(value);
 56        }
 57
 58        #endregion
 59
 60        #region properties
 61
 62        /// <summary>
 63        /// Gets the size.
 64        /// </summary>
 65        /// <value>
 66        /// The size.
 67        /// </value>
 68        /// <inheritdoc />
 216016269        public int Size { get; private set; }
 70
 71        /// <summary>
 72        /// Gets the horizontal size.
 73        /// </summary>
 74        /// <value>
 75        /// The horizontal size.
 76        /// </value>
 77        /// <inheritdoc />
 263078        public int SizeX { get; private set; }
 79
 80        /// <summary>
 81        /// Gets the vertical size.
 82        /// </summary>
 83        /// <value>
 84        /// The vertical size.
 85        /// </value>
 86        /// <inheritdoc />
 222626387        public int SizeY { get; private set; }
 88
 89        #endregion
 90
 91        #region constructor
 92
 93        /// <summary>
 94        /// Initializes a new instance of the <see cref="PointCloud3" /> class.
 95        /// </summary>
 96        /// <param name="sizeX">The size x.</param>
 97        /// <param name="sizeY">The size y.</param>
 2498        public PointCloud3(int sizeX, int sizeY) => Initialize(sizeX, sizeY);
 99
 100        #endregion
 101
 102        #region methods
 103
 104        /// <summary>
 105        /// Updates [this] instance with the data of the specified source.
 106        /// </summary>
 107        /// <param name="source">The source value.</param>
 108        /// <inheritdoc />
 109        public void Update(Point3[] source)
 12110        {
 13190136111            for (var i = 0; i < source.Length; ++i) {
 4396704112                _values1D[i].Set(source[i]);
 4396704113            }
 12114        }
 115
 116        /// <summary>
 117        /// Updates [this] instance with the data of the specified source.
 118        /// </summary>
 119        /// <param name="source">The source value.</param>
 120        /// <inheritdoc />
 121        public void Update(ReadOnlySpan<Point3> source)
 0122        {
 0123            for (var i = 0; i < source.Length; ++i) {
 0124                _values1D[i].Set(source[i]);
 0125            }
 0126        }
 127
 128        /// <summary>
 129        /// Updates [this] instance with the data of the specified source.
 130        /// </summary>
 131        /// <param name="source">The source value.</param>
 132        /// <inheritdoc />
 133        public void Update2(ReadOnlySpan<Point3> source)
 0134        {
 0135            var valSpan = _values1D.AsSpan();
 136
 0137            for (var i = 0; i < source.Length; ++i) {
 0138                valSpan[i].Set(source[i]);
 0139            }
 0140        }
 141
 142        /// <summary>
 143        /// Updates [this] instance with the data of the specified source.
 144        /// </summary>
 145        /// <param name="source">The source value.</param>
 146        /// <inheritdoc />
 147        public void UpdateParallel(ReadOnlyMemory<Point3> source)
 0148        {
 0149            Parallel.For(0, source.Length, i =>
 0150                // for (var i = 0; i < source.Length; ++i)
 0151                {
 0152                    _values1D[i].Set(source.Span[i]);
 0153                }
 0154            );
 0155        }
 156
 157        /// <summary>
 158        /// Updates [this] instance with the data of the specified source.
 159        /// </summary>
 160        /// <param name="source">The source value.</param>
 161        /// <inheritdoc />
 162        public void Update(ReadOnlyMemory<Point3> source)
 0163        {
 0164            for (var i = 0; i < source.Length; ++i)
 0165            {
 0166                _values1D[i].Set(source.Span[i]);
 0167            }
 168
 0169        }
 170
 171        /// <summary>
 172        /// Updates [this] instance with the data of the specified source.
 173        /// </summary>
 174        /// <param name="source">The source value.</param>
 175        /// <inheritdoc />
 176        [Obsolete("Benchmark showed that this is 3 times slower than Update() method")]
 177        public void UpdateParallel(Point3[] source)
 0178        {
 0179            Parallel.For(0, source.Length, (i) =>
 0180            {
 0181                _values1D[i].Set(source[i]);
 0182            });
 183
 0184            Array.Copy(source, _values1D, source.Length);
 0185            ArrayUtils.ReferencingArrays(_values1D, _values2D);
 186
 187            // for (int i = 0; i < source.Length; ++i) {
 188            //     _values1D[i].Set(source[i]);
 189            // }
 0190        }
 191
 192        /// <summary>
 193        /// Initializes the specified size y.
 194        /// </summary>
 195        /// <param name="sizeX">The size x.</param>
 196        /// <param name="sizeY">The size y.</param>
 197        public void Initialize(int sizeX, int sizeY)
 12198        {
 12199            SizeX = sizeX;
 12200            SizeY = sizeY;
 12201            Size = sizeX * sizeY;
 202
 12203            ArrayUtils.InitializeArray(out _values1D, Size);
 12204            ArrayUtils.InitializeArray(out _values2D, SizeX, sizeY);
 12205            ArrayUtils.ReferencingArrays(_values1D, _values2D);
 12206        }
 207
 3208        public Point3[] AsArray() => _values1D;
 209
 2210        public Span<Point3> AsSpan() => _values1D.AsSpan();
 211
 0212        public Memory<Point3> AsMemory() => _values1D.AsMemory();
 213
 3214        public Point3[][] AsJaggedArray() => _values2D;
 215        public void Update(ReadOnlyMemory<Point3> source, float defaultZ)
 0216        {
 0217            Update(source);
 0218        }
 219
 220        #endregion
 221    }
 222}