< Summary - ReFlex - Library

Information
Class: ReFlex.Core.Interactivity.Components.RemoteDepthRaster
Assembly: ReFlex.Core.Interactivity
File(s): D:\a\reflex\reflex\library\src\Core\Interactivity\Components\RemoteDepthRaster.cs
Line coverage
92%
Covered lines: 48
Uncovered lines: 4
Coverable lines: 52
Total lines: 74
Line coverage: 92.3%
Branch coverage
84%
Covered branches: 32
Total branches: 38
Branch coverage: 84.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_SensorWidth()100%11100%
get_SensorHeight()100%11100%
get_Width()100%11100%
get_Height()100%11100%
get_SampleStep()100%11100%
get_Depths()100%11100%
.ctor(...)87.5%2424100%
ToLittleEndianBytes()25%6450%
TryGetSensorIndex(...)100%44100%
CreateCandidate(...)100%66100%

File(s)

D:\a\reflex\reflex\library\src\Core\Interactivity\Components\RemoteDepthRaster.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Buffers.Binary;
 4using System.Runtime.InteropServices;
 5using ReFlex.Core.Common.Components;
 6using ReFlex.Core.Common.Util;
 7
 8namespace ReFlex.Core.Interactivity.Components;
 9
 10/// <summary>A request-local regular raster. Its geometry survives settings changes during an RPC.</summary>
 11public sealed class RemoteDepthRaster
 12{
 43613    public int SensorWidth { get; }
 3614    public int SensorHeight { get; }
 87815    public int Width { get; }
 10416    public int Height { get; }
 83017    public int SampleStep { get; }
 40418    public IReadOnlyList<float> Depths { get; }
 19    private readonly float[] _depths;
 20
 2221    public RemoteDepthRaster(PointCloud3 cloud, int skip, bool completeDataSet)
 2222    {
 2223        if (cloud == null) throw new ArgumentNullException(nameof(cloud));
 2624        if (skip < 0 || skip == int.MaxValue) throw new ArgumentOutOfRangeException(nameof(skip));
 1825        SensorWidth = cloud.SizeX;
 1826        SensorHeight = cloud.SizeY;
 1827        if (SensorWidth <= 0 || SensorHeight <= 0) throw new ArgumentException("Empty point cloud.", nameof(cloud));
 1828        SampleStep = skip + 1;
 1829        Width = (SensorWidth - 1) / SampleStep + 1;
 1830        Height = (SensorHeight - 1) / SampleStep + 1;
 1831        var values = new float[checked(Width * Height)];
 1832        var points = cloud.AsArray();
 16033        for (var y = 0; y < Height; y++)
 70034        for (var x = 0; x < Width; x++)
 28835        {
 28836            var point = points[y * SampleStep * SensorWidth + x * SampleStep];
 28837            values[y * Width + x] = point != null && float.IsFinite(point.Z) &&
 28838                (completeDataSet || (point.IsValid && !point.IsFiltered)) ? point.Z : float.NaN;
 28839        }
 1840        _depths = values;
 1841        Depths = Array.AsReadOnly(values);
 1842    }
 43
 44    /// <summary>Own row-major IEEE754 float32 payload; NaN keeps its missing-sample meaning.</summary>
 45    public byte[] ToLittleEndianBytes()
 446    {
 447        if (BitConverter.IsLittleEndian)
 448            return MemoryMarshal.AsBytes(_depths.AsSpan()).ToArray();
 049        var bytes = new byte[checked(_depths.Length * sizeof(float))];
 050        for (var index = 0; index < _depths.Length; index++)
 051            BinaryPrimitives.WriteSingleLittleEndian(bytes.AsSpan(index * sizeof(float), sizeof(float)), _depths[index])
 052        return bytes;
 453    }
 54
 55    public bool TryGetSensorIndex(int index, out int sensorIndex)
 11456    {
 11457        sensorIndex = -1;
 12058        if (index < 0 || index >= Depths.Count) return false;
 10859        sensorIndex = (index / Width * SampleStep) * SensorWidth + index % Width * SampleStep;
 10860        return true;
 11461    }
 62
 63    public Interaction CreateCandidate(int index, float depth, int touchId, long time)
 1264    {
 1265        if (!TryGetSensorIndex(index, out var sensorIndex) || !float.IsFinite(depth) || !float.IsFinite(Depths[index]))
 1066            throw new ArgumentException("Remote candidate has an invalid index, missing sample or non-finite depth.");
 267        return new Interaction
 268        {
 269            TouchId = touchId, Time = time, Confidence = 1, Type = InteractionType.None,
 270            // Observers require lateral array coordinates, not sensor world coordinates.
 271            Position = new Point3(sensorIndex % SensorWidth, sensorIndex / SensorWidth, depth)
 272        };
 273    }
 74}