public void GivenGaussianFilterWithDimension9_AndDeviation2_WhenCalculatingAreaUnderMask_ThenEquals1 () { // act var filter = new GaussianFilter(9, 2); // assert var sum = filter.Filter.Sum(); var comparer = new DoubleComparer(1e-8); Assert.AreEqual(0, comparer.Compare(1, sum)); }
/// <summary> /// /// </summary> /// <param name="contextGeometries"></param> /// <param name="sortAscending"></param> /// <returns></returns> public Autodesk.DesignScript.Geometry.Geometry[] SortByDistance(Geometry[] contextGeometries, bool sortAscending) { if (contextGeometries == null) throw new System.ArgumentNullException("contextGeometries"); else if (contextGeometries.Length == 0) { throw new System.ArgumentException(string.Format(Properties.Resources.IsZero, "number of context geometries"), "contextGeometries"); } // insert all the geometries with their distance from this point in this sorted dictionary // //SortedDictionary<double, Geometry> geomsWithDistance = new SortedDictionary<double, Geometry>(); List<KeyValuePair<double, Geometry>> geomsWithDistance = new List<KeyValuePair<double, Geometry>>(); foreach (var geom in contextGeometries) { geomsWithDistance.Add(new KeyValuePair<double, Geometry>(geom.GeomEntity.DistanceTo(PointEntity), geom)); } DoubleComparer comparer = new DoubleComparer(sortAscending); geomsWithDistance.Sort((KeyValuePair<double, Geometry> x, KeyValuePair<double, Geometry> y) => comparer.Compare(x.Key, y.Key)); Geometry[] sortedList = new Geometry[geomsWithDistance.Count]; int i = 0; foreach (var item in geomsWithDistance) { sortedList[i++] = item.Value; } return sortedList; }
public static int Compare(double x, double y) { return(DoubleComparer.Compare(x, y)); }