private void GenerateFaces() { var xValues = x.Values; var yValues = y.Values; faces = new MultiDimensionalArray <IGridFace>(new [] { Size1 - 1, Size2 - 1 }); // build quad tree facesIndex = new Quadtree(); for (var i = 0; i < Size1 - 1; i++) { for (var j = 0; j < Size2 - 1; j++) { var points = new Coordinate[5]; points[0] = new Coordinate(xValues[i, j], yValues[i, j]); points[1] = new Coordinate(xValues[i, j + 1], yValues[i, j + 1]); points[2] = new Coordinate(xValues[i + 1, j + 1], yValues[i + 1, j + 1]); points[3] = new Coordinate(xValues[i + 1, j], yValues[i + 1, j]); points[4] = points[0]; var face = new Face { Geometry = new Polygon(new LinearRing(points)), I = i, J = j, Index = MultiDimensionalArrayHelper.GetIndex1d(new[] { i, j }, xValues.Stride), Grid = this }; Faces[i, j] = face; facesIndex.Insert(face.Geometry.EnvelopeInternal, face); } } }
private void Fill() { while (changing) { Thread.Sleep(0); } changing = true; RaiseListChangedEvents = false; IFunction function = functions.FirstOrDefault(); // fill in binding list rows if (function.Components.Count > 0) { values = function.Components[0].Values; for (var i = 0; i < values.Count; i++) { Add(new MultipleFunctionBindingListRow(this)); } } RaiseListChangedEvents = true; // raise Reset in subscribers ResetBindings(); changing = false; }
private static void DumpToStringBuilder(IMultiDimensionalArray array, StringBuilder sb, int[] indexes, int dimension) { if (dimension >= array.Rank) { return; } for (int i = 0; i < array.Shape[dimension]; i++, indexes[dimension]++) { if (dimension == array.Rank - 1) { sb.Append(array[indexes] ?? "<null>"); if (i != array.Shape[dimension] - 1) { sb.Append(", "); } } else { sb.Append("{"); DumpToStringBuilder(array, sb, indexes, dimension + 1); sb.Append("}"); if (i < array.Shape[dimension] - 1) { sb.Append(", "); } } } indexes[dimension] = 0; // reset }
public static string ToString(IMultiDimensionalArray array) { var indexes = new int[array.Rank]; var culture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; var sb = new StringBuilder(); sb.Append("{"); if (array.Count > 20) { sb.Append("<array with total size "); sb.Append(array.Count); sb.Append(">"); } else { DumpToStringBuilder(array, sb, indexes, 0); } sb.Append("}"); var str = sb.ToString(); Thread.CurrentThread.CurrentCulture = culture; return(str); }
public void ConvertOneArgumentOfTwoDimensionalFunction() { IFunction func = new Function(); IVariable <int> x = new Variable <int>("x"); IVariable <DateTime> t = new Variable <DateTime>("t"); var fx = new Variable <int>(); func.Arguments.Add(x); func.Arguments.Add(t); func.Components.Add(fx); DateTime t0 = DateTime.Now; func[10, t0] = 4; IFunction convertedFunction = new ConvertedFunction <string, int>(func, x, Convert.ToInt32, Convert.ToString); //notice both argument and component are converted Assert.IsTrue(convertedFunction.Arguments[0] is IVariable <string>); Assert.IsTrue(convertedFunction.Components[0] is IVariable <int>); //notice the argument has been converted to a string variable Assert.AreEqual(4, convertedFunction["10", t0]); Assert.AreEqual(4, convertedFunction.Components[0].Values[0, 0]); //arguments of components are converted as well :) Assert.AreEqual(4, convertedFunction.Components[0]["10", t0]); convertedFunction["30", t0] = 10; IMultiDimensionalArray <string> strings = (IMultiDimensionalArray <string>)convertedFunction.Arguments[0].Values; Assert.IsTrue(new[] { "10", "30" }.SequenceEqual(strings)); }
public void FilterUsingComponent() { IFunction f = new Function(); IVariable c1 = new Variable <int>("c1"); IVariable c2 = new Variable <int>("c2"); IVariable x = new Variable <int>("x"); IVariable y = new Variable <int>("y"); f.Components.Add(c1); f.Components.Add(c2); f.Arguments.Add(x); f.Arguments.Add(y); f.SetValues( new[] { 100, 200 }, new VariableValueFilter <int>(x, new[] { 1, 2, 3, 4, 5 }), new VariableValueFilter <int>(y, new[] { 1, 2, 3 }) ); IFunction filtered = f.Filter(new ComponentFilter(c1)); IMultiDimensionalArray <int> values = filtered.GetValues <int>(new VariableValueFilter <int>(x, new[] { 1, 2, 3 })); Assert.IsTrue(values.Shape.SequenceEqual(new[] { 3, 3 })); Assert.AreEqual(100, values[2, 2]); }
private void SubscribeToArray(IMultiDimensionalArray array) { ((INotifyPropertyChange)array).PropertyChanged += FunctionValuesPropertyChanged; ((INotifyPropertyChange)array).PropertyChanging += FunctionValuesPropertyChanging; array.CollectionChanging += FunctionValuesValuesChanging; array.CollectionChanged += FunctionValuesValuesChanged; }
//private bool DisableEvents { get; set; } /// <summary> /// Returns the indexes of the variable for the given values /// </summary> /// <param name="filter"></param> /// <returns></returns> /// TODO: move to function. In store work with indexes. Gives problems on insert. private IList <int> GetVariableValueFilterIndexes(IVariableValueFilter filter) { IMultiDimensionalArray values = FunctionValues[Functions.IndexOf(filter.Variable)]; if (values.Rank != 1) { throw new NotSupportedException("Filtering on multidimensional variable is not supported"); } //traverse the array and find out matching indexes var result = new List <int>(); ArrayList filterValues = new ArrayList(filter.Values); for (int fi = 0; fi < filterValues.Count; fi++) { int index = values.IsAutoSorted ? values.BinaryHintedSearch(filterValues[fi]) : values.IndexOf(filterValues[fi]); if (index >= 0) { result.Add(index); } } //make sure the output is ordered ascending result.Sort(); return(result); }
private void UnsubscribeFromArray(IMultiDimensionalArray array) { ((INotifyPropertyChange)array).PropertyChanged -= FunctionValuesPropertyChanged; ((INotifyPropertyChange)array).PropertyChanging -= FunctionValuesPropertyChanging; array.CollectionChanging -= FunctionValuesValuesChanging; array.CollectionChanged -= FunctionValuesValuesChanged; }
private void UpdateCoverageGeometry() { if (Locations == null) { return; } IMultiDimensionalArray <INetworkLocation> locations = Locations.Values; if (locations.Count == 0) { return; } // Create a geometry object that is defined by all covered feature geometries var geometries = new IGeometry[locations.Count]; for (int i = 0; i < locations.Count; i++) { geometries[i] = locations[i].Geometry; if (geometries[i] == null) { // geometry-less feature return; } } Geometry = new GeometryCollection(geometries); }
public virtual object this[params object[] argumentValues] { get { var filters = CreateArgumentFilters(argumentValues); IMultiDimensionalArray values = GetValues(filters); if (values.Count == 0) { return(null); } return(values.Count == 1 ? values[0] : values); } set { var filters = CreateArgumentFilters(argumentValues); //dont treat string like ienumerable although it is IEnumerable values = value is IEnumerable && !(value is string) ? (IEnumerable)value : new[] { value }; if (Components.Count == 1) //quicker this way { Components[0].SetValues(values, filters); } else { SetValues(values, filters); } } }
private void Fill() { while (changing) { Wait(); } changing = true; AllowNew = function.Arguments.Count <= 1 && function.Components.Count >= 1 && function.IsEditable; AllowEdit = function.Arguments.Count <= 1 && function.Components.Count >= 1 && function.IsEditable; AllowRemove = function.Arguments.Count <= 1 && function.Components.Count >= 1 && function.IsEditable; // fill in binding list rows RaiseListChangedEvents = false; Clear(); if (function.Components.Count > 0) { values = function.Components[0].Values; for (var i = 0; i < values.Count; i++) { //We use AddNewCore since AddNew is SLOW because it uses IndexOf to determine the //insertion index (to support cancellation). Add some reflection if we also need this. AddNewCore(); } } RaiseListChangedEvents = true; // raise Reset in subscribers ResetBindings(); changing = false; }
public virtual void AddIndependendVariableValues <T>(IVariable variable, IEnumerable <T> values) { if (!Functions.Contains(variable)) { throw new ArgumentOutOfRangeException("variable", "Function is not a part of the store, add it to the Functions first."); } IMultiDimensionalArray variableValuesArray = FunctionValues[Functions.IndexOf(variable)]; bool addingNewValues = variableValuesArray.Count == 0; foreach (T o in values) { if (addingNewValues) { variableValuesArray.Add(o); } else { if (!variableValuesArray.Contains(o)) // TODO: slow, optimize it somehow { variableValuesArray.Add(o); } } } }
public void GetValuesWithVariableIndexRangeFilters() { string fileName = rasterDataPath + "SchematisatieInt.bil"; var functionStore = new GdalFunctionStore { Path = fileName }; functionStore.Open(); var grid = (IRegularGridCoverage)functionStore.Functions.First(f => f is IRegularGridCoverage); IMultiDimensionalArray <int> values = grid.GetValues <int>( new VariableIndexRangeFilter(grid.X, 1, 2), new VariableIndexRangeFilter(grid.Y, 1, 2) ); //7 8 9 //4 *5 *6 //1 *2 *3 Assert.AreEqual(4, values.Count); Assert.AreEqual(5, values[0, 0]); Assert.AreEqual(6, values[0, 1]); Assert.AreEqual(2, values[1, 0]); Assert.AreEqual(3, values[1, 1]); }
public void GetValuesWithSampleFilters() { // 1 2 3 4 5 6 7 8 9 // 10 11* 12 13 14* 15 16 17* 18 // 19 20 21 22 23 24 25 26 27 // 28 29 30 31 32 33 34 35 36 // 37 38* 39 40 41* 42 43 44* 45 // 46 47 48 49 50 51 52 53 54 // 55 56 57 58 59 60 61 62 63 // 64 65* 66 67 68* 69 70 71* 72 // 73 74 75 76 77 78 79 80 81 string fileName = rasterDataPath + "SchematisatieInt9x9.asc"; var functionStore = new GdalFunctionStore { Path = fileName }; functionStore.Open(); var grid = (IRegularGridCoverage)functionStore.Functions.First(f => f is IRegularGridCoverage); var sampleSize = 3; IMultiDimensionalArray <int> values = grid.GetValues <int>( new VariableAggregationFilter(grid.X, 4, 0, grid.X.Values.Count - 1), new VariableAggregationFilter(grid.Y, 4, 0, grid.Y.Values.Count - 1) ); Assert.AreEqual(sampleSize * sampleSize, values.Count); //Assert.AreEqual(new[]{11,14,17,38,41,44,65,68,71}, values.ToArray()); //Lower Left Corner Based Assert.AreEqual(new[] { 65, 68, 71, 38, 41, 44, 11, 14, 17 }, values.ToArray()); }
private void Fill() { while (changing) { Thread.Sleep(0); } changing = true; AllowNew = function.Arguments.Count <= 1 && function.IsEditable; AllowEdit = function.Arguments.Count <= 1 && function.IsEditable; AllowRemove = function.Arguments.Count <= 1 && function.IsEditable; // fill in binding list rows RaiseListChangedEvents = false; Clear(); if (function.Components.Count > 0) { values = function.Components[0].Values; for (var i = 0; i < values.Count; i++) { AddNew(); } } RaiseListChangedEvents = true; // raise Reset in subscribers ResetBindings(); changing = false; }
private void OpenGdalDataset(string path) { if (IsOpen) { Close(); } CheckAndFixHeaders(path); gdalDataset = Gdal.Open(path.ToLower(), Access.GA_Update); SetDriver(path); var geoTrans = new double[6]; gdalDataset.GetGeoTransform(geoTrans); var transform = new RegularGridGeoTransform(geoTrans); int sizeX = gdalDataset.RasterXSize; int sizeY = gdalDataset.RasterYSize; // double deltaX = sizeX/gdalDataset.RasterCount; double deltaX = transform.HorizontalPixelResolution; double deltaY = transform.VerticalPixelResolution; var origin = new Coordinate(transform.Left, transform.Top - deltaY * sizeY); yValues = GetValuesArray(deltaY, sizeY, origin.Y); xValues = GetValuesArray(deltaX, sizeX, origin.X); }
public MultiDimensionalArray(bool isReadOnly, bool isFixedSize, object defaultValue, IMultiDimensionalArray array) : this(isReadOnly, isFixedSize, defaultValue, array.Shape) { int i = 0; foreach (object value in array) { values[i++] = value; } }
public void MakeFilteringLessTypeSensitive() { IVariable <double> x = new Variable <double>(); x.SetValues(new[] { 1.0, 2.0, 3.0 }); IMultiDimensionalArray <double> xValues = x.Store.GetVariableValues <double>(x, new VariableValueFilter <double>(x, 2)); Assert.AreEqual(2.0, xValues[0]); }
public MultiDimensionalArrayView(IMultiDimensionalArray parent) { Parent = parent; SelectedIndexes = new int[parent.Rank][]; if (parent is ICachedMultiDimensionalArray) { ((ICachedMultiDimensionalArray)parent).Cache(this); } }
public MultiDimensionalArrayView(IMultiDimensionalArray parent) { Parent = parent; SelectedIndexes = new int[parent.Rank][]; if (parent is ICachedMultiDimensionalArray) { ((ICachedMultiDimensionalArray)parent).Cache(this); } }
private void UpdateTheme() { // If there was no theme attached to the layer yet, generate a default theme if (featureCoverage == null || featureCoverage.Features == null || featureCoverage.Features.Count == 0) { return; } Style.GeometryType = GetFeatureGeometryType(featureCoverage.Features[0] as IFeature); // Values to base the theme on //List<IVariableFilter> filters = new List<IVariableFilter>(); if (Coverage.Time != null) { if (CurrentTime == null && Coverage.Time.Values.Count != 0) { CurrentTime = Coverage.Time.Values[0]; } //filters.Add(new VariableValueFilter(featureCoverage.Time, CurrentTime)); } IMultiDimensionalArray <double> values = featureCoverage.GetValues <double>(); if (null == values) { return; } // NOTE: we're getting all values here! var featureValues = new List <double>(values.Where(v => !double.IsNaN(v))); if (0 == featureValues.Count) { log.Error("Unable to generate default theme; no values available"); return; //throw new ArgumentException(); } featureValues.Sort(); double minValue = featureValues.Min(); double maxValue = featureValues.Max(); if (minValue == maxValue) { // Only a single value, so no gradient theme needed/wanted: create a 'blue' single feature theme Theme = ThemeFactory.CreateSingleFeatureTheme(Style.GeometryType, Color.Blue, 10); } else { // Create 'green to blue' gradient theme Theme = ThemeFactory.CreateGradientTheme(Coverage.Components[0].Name, Style, new ColorBlend(new Color[] { Color.Green, Color.Blue }, new float[] { 0f, 1f }), (float)minValue, (float)maxValue, 1, 1, false, true); } }
/// <summary> /// Gives function value for the given argument values (interpolated,extrapolated or defined). Used by evaluate. /// TODO: name is WRONG! /// </summary> /// <typeparam name="T"></typeparam> /// <param name="argumentValues"></param> /// <returns></returns> private T EvaluateArguments <T>(object[] argumentValues) { int freeArgumentIndex = -1; for (int i = 0; i < argumentValues.Length; i++) { if (!Arguments[i].Values.Contains(argumentValues[i])) { freeArgumentIndex = i; break; } } //no free arguments..found if (freeArgumentIndex == -1) { //convert back to argument filters var argumentFilters = new List <IVariableValueFilter>(); for (int i = 0; i < argumentValues.Length; i++) { argumentFilters.Add(Arguments[i].CreateValueFilter(argumentValues[i])); } #if MONO IVariableFilter[] filters = argumentFilters.ToArray(); IMultiDimensionalArray array = GetValues <T>(filters); return((T)array[0]); #else return(GetValues <T>(argumentFilters.ToArray())[0]); #endif } //TODO : get extrapolation working here by returning null and doing something IComparable argumentValue = (IComparable)argumentValues[freeArgumentIndex]; IComparable leftArgumentValue = GetLeftValue(freeArgumentIndex, argumentValue); IComparable rightArgumentValue = GetRightValue(freeArgumentIndex, argumentValue); if (leftArgumentValue == null || rightArgumentValue == null) { return(GetExtrapolatedValue <T>(argumentValues, freeArgumentIndex, leftArgumentValue, rightArgumentValue)); } //interpolate linear or constant if (Arguments[freeArgumentIndex].InterpolationType == InterpolationType.Linear) { return(GetLinearInterpolatedValue <T>(argumentValues, freeArgumentIndex, argumentValue, leftArgumentValue, rightArgumentValue)); } if (Arguments[freeArgumentIndex].InterpolationType == InterpolationType.Constant) { object[] leftArgumentValues = (object[])argumentValues.Clone(); leftArgumentValues[freeArgumentIndex] = leftArgumentValue; return(EvaluateArguments <T>(leftArgumentValues)); } throw new ArgumentOutOfRangeException("No interpolation method specified"); }
/// <summary> /// Initializes a new MultiDimensionalArrayBindingList from data. /// </summary> /// <param name="array">data of data.</param> public MultiDimensionalArrayBindingList(IMultiDimensionalArray array) { if (array.Rank != 2) { throw new ArgumentException("Supports only two dimensional arrays", "array"); } Array = array; ColumnDimension = 0; RowDimension = 1; }
private void SetIndependendFunctionValues(IVariable variable, IVariableFilter[] filters, IEnumerable values) { IMultiDimensionalArray array = FunctionValues[functions.IndexOf(variable)]; if (filters.Length != 0) { throw new ArgumentException("don't use filters to set independend variables. the only exception is an index filter with index equal to count"); } array.AddRange(values); }
/// <summary> /// Initializes a new MultiDimensionalArrayBindingList from data. /// </summary> /// <param name="array">data of data.</param> public MultiDimensionalArrayBindingList(IMultiDimensionalArray array) { if (array.Rank != 2) { throw new ArgumentException("Supports only two dimensional arrays", "array"); } Array = array; ColumnDimension = 0; RowDimension = 1; }
public static IComparable GetLastValueSmallerThan(IComparable value, IMultiDimensionalArray values) { int i = 0; while (i < values.Count &&((IComparable)values[i]).IsSmaller(value)) { i++; } var itemIndex = i - 1; if (itemIndex < 0) return null; return (IComparable) values[itemIndex]; }
public MultiDimensionalArrayView(IMultiDimensionalArray parent, int dimension, int[] indexes) { Parent = parent; SelectedIndexes = new int[parent.Rank][]; SelectedIndexes[dimension] = SelectedIndexes[dimension] != null ? indexes.Concat(SelectedIndexes[dimension]).ToArray() : indexes; if (parent is ICachedMultiDimensionalArray) { ((ICachedMultiDimensionalArray) parent).Cache(this); } }
public MultiDimensionalArrayView(IMultiDimensionalArray parent, int dimension, int[] indexes) { Parent = parent; SelectedIndexes = new int[parent.Rank][]; SelectedIndexes[dimension] = SelectedIndexes[dimension] != null?indexes.Concat(SelectedIndexes[dimension]).ToArray() : indexes; if (parent is ICachedMultiDimensionalArray) { ((ICachedMultiDimensionalArray)parent).Cache(this); } }
/// <summary> /// Initializes a new MultiDimensionalArrayBindingList from data with custom column names. /// </summary> /// <param name="array">data of data.</param> /// <param name="columnNames">collection of column names.</param> public MultiDimensionalArrayBindingList(IMultiDimensionalArray array, object[] columnNames) : this(array) { if (columnNames.Length != Array.Shape[ColumnDimension]) { throw new ArgumentException("column names must correspond to data columns.", "columnNames"); } this.columnNames = new string[columnNames.Length]; for (int i = 0; i < columnNames.Length; i++) { this.columnNames[i] = columnNames[i].ToString(); } }
/// <summary> /// Initializes a new MultiDimensionalArrayBindingList from data with custom column names. /// </summary> /// <param name="array">data of data.</param> /// <param name="columnNames">collection of column names.</param> public MultiDimensionalArrayBindingList(IMultiDimensionalArray array, object[] columnNames) : this(array) { if (columnNames.Length != Array.Shape[ColumnDimension]) { throw new ArgumentException("column names must correspond to data columns.", "columnNames"); } this.columnNames = new string[columnNames.Length]; for (int i = 0; i < columnNames.Length; i++) { this.columnNames[i] = columnNames[i].ToString(); } }
public void ResizeParentAndUpdateShapeOfSubArray() { //create a 2D grid of 3x3 IMultiDimensionalArray array = new MultiDimensionalArray(3, 3); //select rows [1, 2). So skip the first row IMultiDimensionalArray subArray = array.Select(0, 1, int.MaxValue); Assert.IsTrue(subArray.Shape.SequenceEqual(new[] { 2, 3 })); //resize the parent. Add one row and one column. Check the shape of the subArray changes array.Resize(new[] { 4, 4 }); Assert.IsTrue(subArray.Shape.SequenceEqual(new[] { 3, 4 })); }
public MultiDimensionalArrayView(IMultiDimensionalArray parent, int dimension, int start, int end) { Parent = parent; OffsetStart[dimension] = start; OffsetEnd[dimension] = end; SelectedIndexes = new int[parent.Rank][]; if (parent is ICachedMultiDimensionalArray) { ((ICachedMultiDimensionalArray)parent).Cache(this); } }
public MultiDimensionalArrayView(IMultiDimensionalArray parent, int dimension, int start, int end) { Parent = parent; OffsetStart[dimension] = start; OffsetEnd[dimension] = end; SelectedIndexes = new int[parent.Rank][]; if (parent is ICachedMultiDimensionalArray) { ((ICachedMultiDimensionalArray)parent).Cache(this); } }
private static int FindNearest(IMultiDimensionalArray <double> values, double first) { if (first <= values[0] || values.Count == 1) { return(0); } for (int i = 1; i < values.Count; i++) { if (values[i] > first) { return(i); } } return(values.Count - 1); }
public static void UpdateSegments(INetworkCoverage coverage, IBranch branch, IMultiDimensionalArray <INetworkLocation> allLocations) { if (coverage.Network == null) { return; } // remove old segments for selected branch foreach (var segment in coverage.Segments.Values.Where(s => s.Branch == branch).ToArray()) { coverage.Segments.Values.Remove(segment); } var branchNetworkLocations = allLocations.Where(l => l.Branch == branch).Cast <INetworkLocation>(); var skipFirst = branchNetworkLocations.FirstOrDefault() == allLocations.FirstOrDefault(); var skipLast = branchNetworkLocations.LastOrDefault() == allLocations.LastOrDefault(); IEnumerable <INetworkSegment> segments; switch (coverage.SegmentGenerationMethod) { case SegmentGenerationMethod.RouteBetweenLocations: segments = NetworkHelper.GenerateSegmentsBetweenLocations(branchNetworkLocations, branch, skipFirst, skipLast); break; case SegmentGenerationMethod.SegmentBetweenLocations: //segments = NetworkHelper.GenerateSegmentsPerLocation(branchNetworkLocations, branch); segments = UpdateSegmentsBranchSegmentBetweenLocations(false, branch, branchNetworkLocations); break; case SegmentGenerationMethod.SegmentPerLocation: segments = NetworkHelper.GenerateSegmentsPerLocation(branchNetworkLocations, branch); break; default: throw new ArgumentException( string.Format("Method {0} not supported", coverage.SegmentGenerationMethod), "coverage"); } foreach (var s in segments) { // todo set branch and offset to NetworkSegmentAttributeAccessor? // assume number of location to be at least number of segments per branch coverage.Segments.Values.Add(s); } }
/// <summary> /// Create a attached copy of the parent array /// </summary> /// <param name="parent">Parent array</param> /// <param name="start">Start for dimension</param> /// <param name="end">End for dimension</param> public MultiDimensionalArrayView(IMultiDimensionalArray parent,IList<int> start,IList<int> end) { if (start.Count != parent.Rank || end.Count != parent.Rank) { throw new ArgumentOutOfRangeException("Rank of array and number of elements in the arguments are not equal"); } Parent = parent; OffsetStart = start; OffsetEnd = end; SelectedIndexes = new int[parent.Rank][]; if (parent is ICachedMultiDimensionalArray) { ((ICachedMultiDimensionalArray)parent).Cache(this); } }
public static void UpdateSegments(INetworkCoverage coverage, IBranch branch, IMultiDimensionalArray<INetworkLocation> allLocations) { if (coverage.Network == null) { return; } // remove old segments for selected branch foreach (var segment in coverage.Segments.Values.Where(s => s.Branch == branch).ToArray()) { coverage.Segments.Values.Remove(segment); } var branchNetworkLocations = allLocations.Where(l => l.Branch == branch).Cast<INetworkLocation>(); var skipFirst = branchNetworkLocations.FirstOrDefault() == allLocations.FirstOrDefault(); var skipLast = branchNetworkLocations.LastOrDefault() == allLocations.LastOrDefault(); IEnumerable<INetworkSegment> segments; switch (coverage.SegmentGenerationMethod) { case SegmentGenerationMethod.RouteBetweenLocations: segments = NetworkHelper.GenerateSegmentsBetweenLocations(branchNetworkLocations, branch, skipFirst, skipLast); break; case SegmentGenerationMethod.SegmentBetweenLocations: //segments = NetworkHelper.GenerateSegmentsPerLocation(branchNetworkLocations, branch); segments = UpdateSegmentsBranchSegmentBetweenLocations(false, branch, branchNetworkLocations); break; case SegmentGenerationMethod.SegmentPerLocation: segments = NetworkHelper.GenerateSegmentsPerLocation(branchNetworkLocations, branch); break; default: throw new ArgumentException( string.Format("Method {0} not supported", coverage.SegmentGenerationMethod), "coverage"); } foreach (var s in segments) { // todo set branch and offset to NetworkSegmentAttributeAccessor? // assume number of location to be at least number of segments per branch coverage.Segments.Values.Add(s); } }
public static string ToString(IMultiDimensionalArray array) { var indexes = new int[array.Rank]; var culture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; var sb = new StringBuilder(); sb.Append("{"); if (array.Count > 20) { sb.Append("<array with total size "); sb.Append(array.Count); sb.Append(">"); } else { DumpToStringBuilder(array, sb, indexes, 0); } sb.Append("}"); var str = sb.ToString(); Thread.CurrentThread.CurrentCulture = culture; return str; }
public MultiDimensionalArrayEnumerator(MultiDimensionalArray array) { this.array = array; Reset(); }
private static void DumpToStringBuilder(IMultiDimensionalArray array, StringBuilder sb, int[] indexes, int dimension) { if (dimension >= array.Rank) { return; } for (int i = 0; i < array.Shape[dimension]; i++, indexes[dimension]++) { if (dimension == array.Rank - 1) { sb.Append(array[indexes] ?? "<null>"); if (i != array.Shape[dimension] - 1) { sb.Append(", "); } } else { sb.Append("{"); DumpToStringBuilder(array, sb, indexes, dimension + 1); sb.Append("}"); if (i < array.Shape[dimension] - 1) { sb.Append(", "); } } } indexes[dimension] = 0; // reset }
public MultiDimensionalArrayEnumerator(MultiDimensionalArray array) { this.array = array; index = new int[array.Rank]; Reset(); }