public ClipPath(Sector sector, PathUtil.PathType borderPathType) { float[] edgex, edgey; RenderUtil.HexEdges(borderPathType, out edgex, out edgey); Rectangle bounds = sector.Bounds; List <Point> clip = new List <Point>(); clip.AddRange(Util.Sequence(1, Astrometrics.SectorWidth).Select(x => new Point(x, 1))); clip.AddRange(Util.Sequence(2, Astrometrics.SectorHeight).Select(y => new Point(Astrometrics.SectorWidth, y))); clip.AddRange(Util.Sequence(Astrometrics.SectorWidth - 1, 1).Select(x => new Point(x, Astrometrics.SectorHeight))); clip.AddRange(Util.Sequence(Astrometrics.SectorHeight - 1, 1).Select(y => new Point(1, y))); for (int i = 0; i < clip.Count; ++i) { Point pt = clip[i]; pt.Offset(bounds.Location); clip[i] = pt; } PathUtil.ComputeBorderPath(clip, edgex, edgey, out clipPathPoints, out clipPathPointTypes); PointF min = clipPathPoints[0]; PointF max = clipPathPoints[0]; for (int i = 1; i < clipPathPoints.Length; ++i) { PointF pt = clipPathPoints[i]; if (pt.X < min.X) { min.X = pt.X; } if (pt.Y < min.Y) { min.Y = pt.Y; } if (pt.X > max.X) { max.X = pt.X; } if (pt.Y > max.Y) { max.Y = pt.Y; } } this.bounds = new RectangleF(min, new SizeF(max.X - min.X, max.Y - min.Y)); }
public ClipPath(Sector sector, PathUtil.PathType borderPathType) { float[] edgex, edgey; RenderUtil.HexEdges(borderPathType, out edgex, out edgey); IEnumerable <Hex> hexes = Util.Sequence(1, Astrometrics.SectorWidth).Select(x => new Hex((byte)x, 1)) .Concat(Util.Sequence(2, Astrometrics.SectorHeight).Select(y => new Hex(Astrometrics.SectorWidth, (byte)y))) .Concat(Util.Sequence(Astrometrics.SectorWidth - 1, 1).Select(x => new Hex((byte)x, Astrometrics.SectorHeight))) .Concat(Util.Sequence(Astrometrics.SectorHeight - 1, 1).Select(y => new Hex(1, (byte)y))); Rectangle bounds = sector.Bounds; IEnumerable <Point> points = (from hex in hexes select new Point(hex.X + bounds.X, hex.Y + bounds.Y)).ToList(); PathUtil.ComputeBorderPath(points, edgex, edgey, out clipPathPoints, out clipPathPointTypes); PointF min = clipPathPoints[0]; PointF max = clipPathPoints[0]; for (int i = 1; i < clipPathPoints.Length; ++i) { PointF pt = clipPathPoints[i]; if (pt.X < min.X) { min.X = pt.X; } if (pt.Y < min.Y) { min.Y = pt.Y; } if (pt.X > max.X) { max.X = pt.X; } if (pt.Y > max.Y) { max.Y = pt.Y; } } this.bounds = new RectangleF(min, new SizeF(max.X - min.X, max.Y - min.Y)); }
private void Page_Load(object sender, System.EventArgs e) { if (!ServiceConfiguration.CheckEnabled("jumpmap", Response)) { return; } // NOTE: This (re)initializes a static data structure used for // resolving names into sector locations, so needs to be run // before any other objects (e.g. Worlds) are loaded. ResourceManager resourceManager = new ResourceManager(Server, Cache); // // Jump // int jump = Util.Clamp(GetIntOption("jump", 6), 0, 12); // // Content & Coordinates // Selector selector; Location loc; if (Request.HttpMethod == "POST") { Sector sector; try { sector = GetPostedSector(); } catch (Exception ex) { SendError(400, "Invalid request", ex.Message); return; } if (sector == null) { SendError(400, "Invalid request", "Either file or data must be supplied in the POST data."); return; } int hex = GetIntOption("hex", Astrometrics.SectorCentralHex); loc = new Location(new Point(0, 0), hex); selector = new HexSectorSelector(resourceManager, sector, loc.HexLocation, jump); } else { SectorMap map = SectorMap.FromName(SectorMap.DefaultSetting, resourceManager); if (HasOption("sector") && HasOption("hex")) { string sectorName = GetStringOption("sector"); int hex = GetIntOption("hex", 0); loc = new Location(map.FromName(sectorName).Location, hex); } else if (HasOption("sx") && HasOption("sy") && HasOption("hx") && HasOption("hy")) { int sx = GetIntOption("sx", 0); int sy = GetIntOption("sy", 0); int hx = GetIntOption("hx", 0); int hy = GetIntOption("hy", 0); loc = new Location(map.FromLocation(sx, sy).Location, hx * 100 + hy); } else if (HasOption("x") && HasOption("y")) { loc = Astrometrics.CoordinatesToLocation(GetIntOption("x", 0), GetIntOption("y", 0)); } else { loc = new Location(map.FromName("Spinward Marches").Location, 1910); } selector = new HexSelector(map, resourceManager, loc, jump); } // // Scale // double scale = Util.Clamp(GetDoubleOption("scale", 64), MinScale, MaxScale); // // Options & Style // MapOptions options = MapOptions.BordersMajor | MapOptions.BordersMinor | MapOptions.ForceHexes; Stylesheet.Style style = Stylesheet.Style.Poster; ParseOptions(ref options, ref style); // // Border // bool border = GetBoolOption("border", defaultValue: true); // // Clip // bool clip = GetBoolOption("clip", defaultValue: true); // // What to render // RectangleF tileRect = new RectangleF(); Point coords = Astrometrics.LocationToCoordinates(loc); tileRect.X = coords.X - jump - 1; tileRect.Width = jump + 1 + jump; tileRect.Y = coords.Y - jump - 1; tileRect.Height = jump + 1 + jump; // Account for jagged hexes tileRect.Y += (coords.X % 2 == 0) ? 0 : 0.5f; tileRect.Inflate(0.35f, 0.15f); Size tileSize = new Size((int)Math.Floor(tileRect.Width * scale * Astrometrics.ParsecScaleX), (int)Math.Floor(tileRect.Height * scale * Astrometrics.ParsecScaleY)); // Construct clipping path List <Point> clipPath = new List <Point>(jump * 6 + 1); Point cur = coords; for (int i = 0; i < jump; ++i) { // Move J parsecs to the upper-left (start of border path logic) cur = Astrometrics.HexNeighbor(cur, 1); } clipPath.Add(cur); for (int dir = 0; dir < 6; ++dir) { for (int i = 0; i < jump; ++i) { cur = Astrometrics.HexNeighbor(cur, (dir + 3) % 6); // Clockwise from upper left clipPath.Add(cur); } } Stylesheet styles = new Stylesheet(scale, options, style); // If any names are showing, show them all if (styles.worldDetails.HasFlag(WorldDetails.KeyNames)) { styles.worldDetails |= WorldDetails.AllNames; } // Compute path float[] edgeX, edgeY; RenderUtil.HexEdges(styles.microBorderStyle == MicroBorderStyle.Square ? PathUtil.PathType.Square : PathUtil.PathType.Hex, out edgeX, out edgeY); PointF[] boundingPathCoords; byte[] boundingPathTypes; PathUtil.ComputeBorderPath(clipPath, edgeX, edgeY, out boundingPathCoords, out boundingPathTypes); Render.RenderContext ctx = new Render.RenderContext(); ctx.resourceManager = resourceManager; ctx.selector = selector; ctx.tileRect = tileRect; ctx.scale = scale; ctx.options = options; ctx.styles = styles; ctx.tileSize = tileSize; ctx.border = border; ctx.clipPath = clip ? new XGraphicsPath(boundingPathCoords, boundingPathTypes, XFillMode.Alternate) : null; ProduceResponse("Jump Map", ctx, tileSize, transparent: clip); }
public override void Process() { // NOTE: This (re)initializes a static data structure used for // resolving names into sector locations, so needs to be run // before any other objects (e.g. Worlds) are loaded. ResourceManager resourceManager = new ResourceManager(context.Server); // // Jump // int jump = Util.Clamp(GetIntOption("jump", 6), 0, 12); // // Content & Coordinates // Selector selector; Location loc; if (context.Request.HttpMethod == "POST") { Sector sector; bool lint = GetBoolOption("lint", defaultValue: false); ErrorLogger errors = new ErrorLogger(); sector = GetPostedSector(context.Request, errors); if (lint && !errors.Empty) { throw new HttpError(400, "Bad Request", errors.ToString()); } if (sector == null) { throw new HttpError(400, "Bad Request", "Either file or data must be supplied in the POST data."); } int hex = GetIntOption("hex", Astrometrics.SectorCentralHex); loc = new Location(new Point(0, 0), hex); selector = new HexSectorSelector(resourceManager, sector, loc.Hex, jump); } else { SectorMap.Milieu map = SectorMap.ForMilieu(resourceManager, GetStringOption("milieu")); if (HasOption("sector") && HasOption("hex")) { string sectorName = GetStringOption("sector"); int hex = GetIntOption("hex", 0); Sector sector = map.FromName(sectorName); if (sector == null) { throw new HttpError(404, "Not Found", string.Format("The specified sector '{0}' was not found.", sectorName)); } loc = new Location(sector.Location, hex); } else if (HasLocation()) { loc = GetLocation(); } else { loc = new Location(map.FromName("Spinward Marches").Location, 1910); } selector = new HexSelector(map, resourceManager, loc, jump); } // // Scale // double scale = Util.Clamp(GetDoubleOption("scale", 64), MinScale, MaxScale); // // Options & Style // MapOptions options = MapOptions.BordersMajor | MapOptions.BordersMinor | MapOptions.ForceHexes; Stylesheet.Style style = Stylesheet.Style.Poster; ParseOptions(ref options, ref style); // // Border // bool border = GetBoolOption("border", defaultValue: true); // // Clip // bool clip = GetBoolOption("clip", defaultValue: true); // // What to render // RectangleF tileRect = new RectangleF(); Point coords = Astrometrics.LocationToCoordinates(loc); tileRect.X = coords.X - jump - 1; tileRect.Width = jump + 1 + jump; tileRect.Y = coords.Y - jump - 1; tileRect.Height = jump + 1 + jump; // Account for jagged hexes tileRect.Y += (coords.X % 2 == 0) ? 0 : 0.5f; tileRect.Inflate(0.35f, 0.15f); Size tileSize = new Size((int)Math.Floor(tileRect.Width * scale * Astrometrics.ParsecScaleX), (int)Math.Floor(tileRect.Height * scale * Astrometrics.ParsecScaleY)); // Construct clipping path List <Point> clipPath = new List <Point>(jump * 6 + 1); Point cur = coords; for (int i = 0; i < jump; ++i) { // Move J parsecs to the upper-left (start of border path logic) cur = Astrometrics.HexNeighbor(cur, 1); } clipPath.Add(cur); for (int dir = 0; dir < 6; ++dir) { for (int i = 0; i < jump; ++i) { cur = Astrometrics.HexNeighbor(cur, (dir + 3) % 6); // Clockwise from upper left clipPath.Add(cur); } } Stylesheet styles = new Stylesheet(scale, options, style); // If any names are showing, show them all if (styles.worldDetails.HasFlag(WorldDetails.KeyNames)) { styles.worldDetails |= WorldDetails.AllNames; } // Compute path float[] edgeX, edgeY; RenderUtil.HexEdges(styles.hexStyle == HexStyle.Square ? PathUtil.PathType.Square : PathUtil.PathType.Hex, out edgeX, out edgeY); PointF[] boundingPathCoords; byte[] boundingPathTypes; PathUtil.ComputeBorderPath(clipPath, edgeX, edgeY, out boundingPathCoords, out boundingPathTypes); RenderContext ctx = new RenderContext(resourceManager, selector, tileRect, scale, options, styles, tileSize); ctx.DrawBorder = border; ctx.ClipOutsectorBorders = true; // TODO: Widen path to allow for single-pixel border ctx.ClipPath = clip ? new AbstractPath(boundingPathCoords, boundingPathTypes) : null; ProduceResponse(context, "Jump Map", ctx, tileSize, transparent: clip); }