public static List <LayoutData> Pack(WebAppContext context, Point sheetMetrics, int spacing, bool allowFlip) { bool[,] sheetHitmap = new bool[sheetMetrics.X, sheetMetrics.Y]; RLEShape rleSheet = null; List <LayoutData> displayTokens = new List <LayoutData>(); foreach (string key in context.sizeOrderedShapeKeys) { WAShape shape = context.shapes[key]; for (int j = 0; j < shape.quantity; j++) { Point? pos = null; bool fliped = false; RLEShape rleShape = RunLengthEncode(shape.GetHitmap(spacing, shape.displayScale)); context.js.ConsoleLog(rleShape.size.X + ":" + shape.size.X); context.js.ConsoleLog(rleShape.size.Y + ":" + shape.size.Y); if (rleSheet == null) { rleSheet = RunLengthEncode(sheetHitmap); } pos = Place(rleSheet, pos, rleShape, sheetMetrics, false); if (allowFlip) { Point?p = Place(rleSheet, pos, rleShape, sheetMetrics, true); if (p.HasValue && (!pos.HasValue || CalcPosValue(p.Value) < CalcPosValue(pos.Value))) { pos = p; fliped = true; } } if (pos.HasValue) { for (int row = 0; row < rleShape.runLengths.Length; row++) { for (int column = 0; column < rleShape.runLengths[row].Length / 2; column++) { for (int x = rleShape.runLengths[row][column * 2]; x <= rleShape.runLengths[row][column * 2 + 1]; x++) { if (fliped) { sheetHitmap[rleShape.size.X - x + pos.Value.X, rleShape.size.Y - row + pos.Value.Y] = true; } else { sheetHitmap[x + pos.Value.X, row + pos.Value.Y] = true; } } } } rleSheet = null; displayTokens.Add(new LayoutData(shape.key, new PointF(pos.Value.X + spacing, pos.Value.Y + spacing), fliped, shape.displayScale)); } } } return(displayTokens); }
public void LinkCanvas(WebAppContext context, string canvasId, PointF canvasSize, PointF pos, float scale = 1, bool fliped = false) { context.js.LinkVertexBuffer(canvasId, GetVertexBuffer(canvasSize, pos, scale, fliped)); }