static void SetSymmetricalPixel(Texture2D texture, SymmetryDirection direction, int x, int y, int halfwayPoint) { var readCoordinates = new Vector2Int(); switch (direction) { case SymmetryDirection.Horizontal: readCoordinates = new Vector2Int(x, halfwayPoint - (y + 1 - halfwayPoint)); break; case SymmetryDirection.Vertical: readCoordinates = new Vector2Int(halfwayPoint - (x + 1 - halfwayPoint), y); break; case SymmetryDirection.ForwardDiagonal: break; case SymmetryDirection.BackwardDiagonal: break; } texture.SetPixel(x, y, texture.GetPixel(readCoordinates.x, readCoordinates.y)); }
void ApplySymmetry(ref Texture2D texture, SymmetryDirection direction, SymmetryOutcome symmetryOutcome) { var halfwayPoint = texture.width / 2; for (var rowIndex = 0; rowIndex < texture.height; rowIndex++) { for (var columnIndex = 0; columnIndex < texture.width; columnIndex++) { int referenceValue; switch (direction) { case SymmetryDirection.Horizontal: referenceValue = symmetryOutcome.quarterHorizontalSymmetryResult ? columnIndex : rowIndex; if ((symmetryOutcome.lowerIsDominant && referenceValue >= halfwayPoint - 1) || (!symmetryOutcome.lowerIsDominant && referenceValue <= halfwayPoint + 1)) { SetSymmetricalPixel(texture, direction, columnIndex, rowIndex, halfwayPoint); } break; case SymmetryDirection.Vertical: referenceValue = symmetryOutcome.quarterVerticalSymmetryResult ? rowIndex : columnIndex; if ((symmetryOutcome.lowerIsDominant && referenceValue >= halfwayPoint - 1) || (!symmetryOutcome.lowerIsDominant && referenceValue <= halfwayPoint + 1)) { SetSymmetricalPixel(texture, direction, columnIndex, rowIndex, halfwayPoint); } break; case SymmetryDirection.ForwardDiagonal: if (symmetryOutcome.quarterForwardDiagonalSymmetryResult) { if (symmetryOutcome.lowerIsDominant && columnIndex > rowIndex || !symmetryOutcome.lowerIsDominant && columnIndex < rowIndex) { texture.SetPixel(columnIndex, rowIndex, texture.GetPixel(texture.width - rowIndex, texture.width - columnIndex)); } } else { if (symmetryOutcome.lowerIsDominant && rowIndex < texture.width - columnIndex || !symmetryOutcome.lowerIsDominant && rowIndex > texture.width - columnIndex) { texture.SetPixel(columnIndex, rowIndex, texture.GetPixel(texture.width - rowIndex, texture.width - columnIndex)); } } break; case SymmetryDirection.BackwardDiagonal: if (symmetryOutcome.quarterBackwardDiagonalSymmetryResult) { if (symmetryOutcome.lowerIsDominant && rowIndex < texture.width - columnIndex || !symmetryOutcome.lowerIsDominant && rowIndex > texture.width - columnIndex) { texture.SetPixel(columnIndex, rowIndex, texture.GetPixel(rowIndex, columnIndex)); } } else if (symmetryOutcome.lowerIsDominant && columnIndex > rowIndex || !symmetryOutcome.lowerIsDominant && columnIndex < rowIndex) { texture.SetPixel(columnIndex, rowIndex, texture.GetPixel(rowIndex, columnIndex)); } break; } } } }