public static List <Vector2> CalcLayout( Pattern pattern, Vector2 offsetOnSurface, PartLayoutEnum layout, OriginPositionEnum partOriginPosition, int spacing) { List <Vector2> result = new List <Vector2>(); Vector2 start = new Vector2() { X = 0 + offsetOnSurface.X, Y = 0 + offsetOnSurface.Y }; Vector2 locationPos = new Vector2(); locationPos += start; if (partOriginPosition == OriginPositionEnum.LeftBottom && layout == PartLayoutEnum.LeftToRight) { float tallest = Pattern.CalcTallestPart(pattern); locationPos += new Vector2(0, tallest); } if (partOriginPosition == OriginPositionEnum.Center && layout == PartLayoutEnum.LeftToRight) { float tallest = Pattern.CalcTallestPart(pattern); locationPos += new Vector2(0, tallest / 2); } for (int i = 0; i < pattern.Parts.Count; i++) { PatternPart part = pattern.Parts[i]; Vector2 originOffset = PartExtents.CalcOffsetForOrigin(part, partOriginPosition); PartExtents dims = PartExtents.CalcPartExtents(part); PartExtents partNextDims = null; if (i + 1 < pattern.Parts.Count) { PatternPart partNext = pattern.Parts[i + 1]; partNextDims = PartExtents.CalcPartExtents(partNext); } switch (layout) { default: case PartLayoutEnum.LeftToRight: switch (partOriginPosition) { default: case OriginPositionEnum.LeftTop: case OriginPositionEnum.LeftBottom: case OriginPositionEnum.Center: locationPos = LeftToRight(locationPos, originOffset, dims, result, partOriginPosition, partNextDims, spacing); break; } break; case PartLayoutEnum.TopToBottom: switch (partOriginPosition) { default: case OriginPositionEnum.LeftTop: case OriginPositionEnum.LeftBottom: case OriginPositionEnum.Center: locationPos = TopToBottom(locationPos, originOffset, dims, result, partOriginPosition, partNextDims, spacing); break; } break; } } return(result); }
public static List <List <Vector2> > CalcLayout(List <Pattern> allPatterns, Vector2 offsetOnSurface) { Pattern mainPattern = allPatterns.First(); List <Pattern> layerPatterns = new List <Pattern>(); for (int i = 1; i < allPatterns.Count; i++) //skip first { layerPatterns.Add(allPatterns[i]); } List <List <Vector2> > result = new List <List <Vector2> >(); result.Add(new List <Vector2>()); //mainPattern result layerPatterns.ForEach(x => result.Add(new List <Vector2>())); Vector2 start = new Vector2() { X = 0 + offsetOnSurface.X, Y = 0 + offsetOnSurface.Y }; Vector2 locationPos = new Vector2(); locationPos += start; float tallest = Pattern.CalcTallestPart(mainPattern); locationPos += new Vector2(0, tallest / 2); for (int i = 0; i < mainPattern.Parts.Count; i++) { PatternPart mainPart = mainPattern.Parts[i]; Vector2 mainPartOriginOffset = PartExtents.CalcOffsetForOrigin(mainPart, OriginPositionEnum.Center); PartExtents mainPartExtents = PartExtents.CalcPartExtents(mainPart); PartExtents mainPartNextDims = null; if (i + 1 < mainPattern.Parts.Count) { PatternPart mainPartNext = mainPattern.Parts[i + 1]; mainPartNextDims = PartExtents.CalcPartExtents(mainPartNext); } //pattern main locationPos += new Vector2(-mainPartOriginOffset.X, -mainPartOriginOffset.Y); result[0].Add(locationPos); locationPos += new Vector2(mainPartOriginOffset.X, mainPartOriginOffset.Y); for (int j = 0; j < layerPatterns.Count; j++) { //pattern layer PatternPart layerPart = layerPatterns[j].Parts[i]; Vector2 layerPartOriginOffset = PartExtents.CalcOffsetForOrigin(layerPart, OriginPositionEnum.Center); locationPos += new Vector2(-layerPartOriginOffset.X, -layerPartOriginOffset.Y); result[j + 1].Add(locationPos); locationPos += new Vector2(layerPartOriginOffset.X, layerPartOriginOffset.Y); } //use pattern main to layout locationPos += new Vector2(mainPartExtents.Width / 2, 0); if (mainPartNextDims != null) { locationPos += new Vector2(mainPartNextDims.Width / 2, 0); } locationPos += new Vector2(50, 0);//spacing between parts } return(result); }