public void PrecisionModelToleranceTest() { for (Int32 i = 0; i < _values.Length; i++) { Assert.IsTrue(_defaultModel.Tolerance(_values[i]) > _values[i] * Math.Pow(10, -16)); Assert.IsTrue(_defaultModel.Tolerance(_values[i]) <= _values[i] * Math.Pow(10, -15)); Assert.IsTrue(_floatingModel.Tolerance(_values[i]) > _values[i] * Math.Pow(10, -16)); Assert.IsTrue(_floatingModel.Tolerance(_values[i]) <= _values[i] * Math.Pow(10, -15)); Assert.IsTrue(_floatingSingleModel.Tolerance(_values[i]) > _values[i] * Math.Pow(10, -6)); Assert.IsTrue(_floatingSingleModel.Tolerance(_values[i]) <= _values[i] * Math.Pow(10, -5)); Assert.AreEqual(0.0005, _fixedLargeModel1.Tolerance(_values[i])); Assert.AreEqual(0.0000000000005, _fixedLargeModel2.Tolerance(_values[i])); Assert.AreEqual(500, _fixedSmallModel1.Tolerance(_values[i])); Assert.AreEqual(500000000000, _fixedSmallModel2.Tolerance(_values[i])); } }
/// <summary> /// Computes the planar orientation of a polygon. /// </summary> /// <param name="shell">The coordinates of the polygon shell.</param> /// <param name="precisionModel">The precision model.</param> /// <returns>The orientation of the polygon. If the polygon is invalid <see cref="AEGIS.Orientation.Undefined" /> is returned.</returns> /// <exception cref="System.ArgumentNullException">The shell is null.</exception> public static Orientation Orientation(IEnumerable <Coordinate> shell, PrecisionModel precisionModel) { if (shell == null) { throw new ArgumentNullException(nameof(shell)); } // check for polygon properties IEnumerator <Coordinate> enumerator = shell.GetEnumerator(); Double sum = 0; Int32 count = 1; if (!enumerator.MoveNext()) { return(AEGIS.Orientation.Undefined); } Coordinate first = enumerator.Current, previous = first, current = first; while (enumerator.MoveNext()) { current = enumerator.Current; sum += (current.X - previous.X) * (current.Y + previous.Y); count++; previous = current; } if (count < 3) { return(AEGIS.Orientation.Undefined); } if (precisionModel == null) { precisionModel = PrecisionModel.Default; } if (!precisionModel.AreEqual(first, current)) { sum += (first.X - current.X) * (first.Y + current.Y); } if (Math.Abs(sum) <= precisionModel.Tolerance(shell)) { return(AEGIS.Orientation.Collinear); } return((sum > 0) ? AEGIS.Orientation.Clockwise : AEGIS.Orientation.Counterclockwise); }