public LineDeepPoints(Matrix matrix, int deep) { AbortIfDeepOutOfRange(deep, matrix.Deep); Deep = deep; IsLastDeep = (deep == matrix.Deep - 1); StartDeepPoint = new DeepPoint(deep, deep); EndDeepPoint = new DeepPoint(matrix.Rows - 1 - deep, matrix.Columns - 1 - deep); }
private void RotateMatrixLineDeep(int deep, int numberRotations) { var watch = System.Diagnostics.Stopwatch.StartNew(); LineDeepElements lineDeepElements = new LineDeepElements(this.Matrix, deep); int realNumberRotation = Math.Abs(numberRotations) % lineDeepElements.TotalElements; // if realNumberRotation is 0 then not apply rotation, line deep keep same position if (realNumberRotation > 0) { DeepPoint positionElementOrigin = null; DeepPoint firstElementOrigin = null; int indexRotation = 1; int nextPosition = 0; var nextValue = Matrix.GetElementFromRowColumn(0, 0); do { if (positionElementOrigin == null || positionElementOrigin.Equals(firstElementOrigin)) { positionElementOrigin = lineDeepElements.GetDeepPointFromLinePositionElement(++nextPosition); firstElementOrigin = (DeepPoint)positionElementOrigin.Clone(); nextValue = this.Matrix.GetElementFromDeepPoint(positionElementOrigin); } int currentPosition = nextPosition + realNumberRotation; if (currentPosition > lineDeepElements.TotalElements) { currentPosition -= lineDeepElements.TotalElements; } DeepPoint positionElementDestination = lineDeepElements.GetDeepPointFromLinePositionElement(currentPosition); var currentValue = this.Matrix.GetElementFromDeepPoint(positionElementDestination); this.Matrix.SetElementFromDeepPoint(positionElementDestination, nextValue); nextValue = currentValue; nextPosition = currentPosition; positionElementOrigin = (DeepPoint)positionElementDestination.Clone(); } while (indexRotation++ < lineDeepElements.TotalElements); } else { System.Diagnostics.Debug.WriteLine("-- Not rotate!!!"); } watch.Stop(); System.Diagnostics.Debug.WriteLine($"-- rotations: {realNumberRotation} - deep: {deep} - elements: {lineDeepElements.TotalElements}. Time exec LineDeep: {watch.ElapsedMilliseconds} ms"); }