private bool IsMirror(Pattern <Patches> pattern) { return(pattern == FlipHorizontally(pattern) && pattern == FlipVertically(pattern)); }
private static Node CreateNode(Pattern <Patches> pattern) { int rowCount = pattern.RowCount; int columnCount = pattern.ColumnCount; GridLayoutNode gridLayoutNode = new GridLayoutNode(rowCount * 2, columnCount * 2); Styles styles = new Styles(); for (int row = 0; row < rowCount; ++row) { for (int column = 0; column < columnCount; ++column) { var layoutRow = row * 2; var layoutColumn = column * 2; switch (pattern.Values[row, column]) { case Patches.Rectangle1: { var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn); gridLayoutNode.SetRowSpan(layoutRow, layoutColumn, 2); gridLayoutNode.SetColumnSpan(layoutRow, layoutColumn, 2); layoutSite.Node = CreateRectangleNode(styles.Rectangle1Style); } break; case Patches.Rectangle2: { var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn); gridLayoutNode.SetRowSpan(layoutRow, layoutColumn, 2); gridLayoutNode.SetColumnSpan(layoutRow, layoutColumn, 2); layoutSite.Node = CreateRectangleNode(styles.Rectangle2Style); } break; case Patches.HalfSquareTriangle: { var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn); gridLayoutNode.SetRowSpan(layoutRow, layoutColumn, 2); gridLayoutNode.SetColumnSpan(layoutRow, layoutColumn, 2); layoutSite.Node = CreateHalfSquareTriangleNode(styles.HalfSquareTriangleStyle1, styles.HalfSquareTriangleStyle2); } break; case Patches.HalfSquareTriangle90: { var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn); gridLayoutNode.SetRowSpan(layoutRow, layoutColumn, 2); gridLayoutNode.SetColumnSpan(layoutRow, layoutColumn, 2); layoutSite.Node = CreateHalfSquareTriangleNode(styles.HalfSquareTriangleStyle1, styles.HalfSquareTriangleStyle2); layoutSite.PathOrientation.PointOffset = 3; } break; case Patches.HalfSquareTriangle180: { var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn); gridLayoutNode.SetRowSpan(layoutRow, layoutColumn, 2); gridLayoutNode.SetColumnSpan(layoutRow, layoutColumn, 2); layoutSite.Node = CreateHalfSquareTriangleNode(styles.HalfSquareTriangleStyle1, styles.HalfSquareTriangleStyle2); layoutSite.PathOrientation.PointOffset = 2; } break; case Patches.HalfSquareTriangle270: { var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn); gridLayoutNode.SetRowSpan(layoutRow, layoutColumn, 2); gridLayoutNode.SetColumnSpan(layoutRow, layoutColumn, 2); layoutSite.Node = CreateHalfSquareTriangleNode(styles.HalfSquareTriangleStyle1, styles.HalfSquareTriangleStyle2); layoutSite.PathOrientation.PointOffset = 1; } break; case Patches.SplitRectangle: { // Left Patch { var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn); gridLayoutNode.SetRowSpan(layoutRow, layoutColumn, 2); layoutSite.Node = CreateRectangleNode(styles.SplitRectangleStyle1); } // Right Patch { var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn + 1); gridLayoutNode.SetRowSpan(layoutRow, layoutColumn + 1, 2); layoutSite.Node = CreateRectangleNode(styles.SplitRectangleStyle2); } } break; case Patches.SplitRectangle90: { // Top Patch { var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn); gridLayoutNode.SetColumnSpan(layoutRow, layoutColumn, 2); layoutSite.Node = CreateRectangleNode(styles.SplitRectangleStyle1); } // Bottom Patch { var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow + 1, layoutColumn); gridLayoutNode.SetColumnSpan(layoutRow + 1, layoutColumn, 2); layoutSite.Node = CreateRectangleNode(styles.SplitRectangleStyle2); } } break; case Patches.SplitRectangle180: { // Right Patch { var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn + 1); gridLayoutNode.SetRowSpan(layoutRow, layoutColumn + 1, 2); layoutSite.Node = CreateRectangleNode(styles.SplitRectangleStyle1); } // Left Patch { var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn); gridLayoutNode.SetRowSpan(layoutRow, layoutColumn, 2); layoutSite.Node = CreateRectangleNode(styles.SplitRectangleStyle2); } } break; case Patches.SplitRectangle270: { // Bottom Patch { var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow + 1, layoutColumn); gridLayoutNode.SetColumnSpan(layoutRow + 1, layoutColumn, 2); layoutSite.Node = CreateRectangleNode(styles.SplitRectangleStyle1); } // Top Patch { var layoutSite = gridLayoutNode.GetLayoutSite(layoutRow, layoutColumn); gridLayoutNode.SetColumnSpan(layoutRow, layoutColumn, 2); layoutSite.Node = CreateRectangleNode(styles.SplitRectangleStyle2); } } break; default: throw new InvalidOperationException(string.Format("Unknown patch {0}", pattern.Values[row, column])); } } } return(gridLayoutNode.GetSimplified()); }
private bool IsPinwheel(Pattern <Patches> pattern) { return(pattern == RotateRight(pattern)); }