< Summary

Class:Azure.AI.FormRecognizer.Models.BoundingBox
Assembly:Azure.AI.FormRecognizer
File(s):C:\Git\azure-sdk-for-net\sdk\formrecognizer\Azure.AI.FormRecognizer\src\BoundingBox.cs
Covered lines:10
Uncovered lines:1
Coverable lines:11
Total lines:57
Line coverage:90.9% (10 of 11)
Covered branches:6
Total branches:6
Branch coverage:100% (6 of 6)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
get_Points()-100%100%
get_Item(...)-100%100%
ToString()-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\formrecognizer\Azure.AI.FormRecognizer\src\BoundingBox.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Drawing;
 7using System.Linq;
 8
 9namespace Azure.AI.FormRecognizer.Models
 10{
 11    /// <summary>
 12    /// A sequence of four <see cref="PointF"/> representing a quadrilateral that outlines
 13    /// the text of an element in a recognized form. Coordinates are specified relative to the
 14    /// top-left of the original image, and points are ordered clockwise from the top-left corner
 15    /// relative to the text orientation. Units are in pixels for images and inches for PDF. The
 16    /// <see cref="LengthUnit"/> type of a recognized page can be found at <see cref="FormPage.Unit"/>.
 17    /// </summary>
 18    public readonly struct BoundingBox
 19    {
 20        private readonly PointF[] _points;
 21
 22        internal BoundingBox(IReadOnlyList<float> boundingBox)
 23        {
 2484024            if (boundingBox.Count == 0)
 25            {
 426                _points = Array.Empty<PointF>();
 427                return;
 28            }
 29
 2483630            int count = boundingBox.Count / 2;
 31
 2483632            _points = new PointF[count];
 24836033            for (int i = 0; i < count; i++)
 34            {
 9934435                _points[i] = new PointF(boundingBox[2 * i], boundingBox[(2 * i) + 1]);
 36            }
 2483637        }
 38
 39        /// <summary>
 40        /// </summary>
 4184841        internal PointF[] Points => _points ?? Array.Empty<PointF>();
 42
 43        /// <summary>
 44        /// Gets one of the points that set the limits of this <see cref="BoundingBox"/>.
 45        /// Coordinates are specified relative to the top-left of the original image, and points
 46        /// are ordered clockwise from the top-left corner relative to the text orientation.
 47        /// </summary>
 48        /// <param name="index">The 0-based index of the point to be retrieved.</param>
 49        /// <returns>A <see cref="PointF"/> corresponding to the specified <paramref name="index"/>.</returns>
 450        public PointF this[int index] => Points[index];
 51
 52        /// <summary>
 53        /// Returns string representation for <see cref="BoundingBox"/>.
 54        /// </summary>
 055        public override string ToString() => string.Join(",", Points.Select(p => p.ToString()).ToArray());
 56    }
 57}