mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-18 22:41:46 +00:00
experimental label position calculator
This commit is contained in:
parent
bf318ac472
commit
c678e615a2
2 changed files with 80 additions and 2 deletions
|
@ -50,7 +50,7 @@ namespace CodeImp.DoomBuilder.Geometry
|
|||
#endregion
|
||||
|
||||
#region ================== Constants
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Pathfinding
|
||||
|
@ -579,5 +579,59 @@ namespace CodeImp.DoomBuilder.Geometry
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Sector Labels
|
||||
|
||||
// This finds the ideal label position for a sector
|
||||
public static Vector2D FindLabelPosition(Sector s, float resolution)
|
||||
{
|
||||
Vector2D foundpoint = new Vector2D();
|
||||
float founddist = 0.0f;
|
||||
|
||||
// Calculate grid numbers
|
||||
RectangleF bbox = s.CreateBBox();
|
||||
int nodesx = (int)(bbox.Width / resolution);
|
||||
int nodesy = (int)(bbox.Height / resolution);
|
||||
|
||||
// Make list of linedefs
|
||||
List<Linedef> lines = new List<Linedef>(s.Sidedefs.Count);
|
||||
foreach(Sidedef sd in s.Sidedefs) lines.Add(sd.Line);
|
||||
|
||||
// Scan the polygon
|
||||
for(int x = 0; x < nodesx; x++)
|
||||
{
|
||||
for(int y = 0; y < nodesy; y++)
|
||||
{
|
||||
// Calculate absolute point
|
||||
Vector2D p = new Vector2D(bbox.X + (float)x * resolution,
|
||||
bbox.Y + (float)y * resolution);
|
||||
|
||||
// Point inside sector?
|
||||
Linedef ld = MapSet.NearestLinedef(lines, p);
|
||||
Sidedef sd = (ld.SideOfLine(p) < 0) ? ld.Front : ld.Back;
|
||||
if((sd != null) && (sd.Sector == s))
|
||||
{
|
||||
// Go for all linedefs to calculate the smallest distance
|
||||
float mindist = int.MaxValue;
|
||||
foreach(Linedef l in lines)
|
||||
{
|
||||
float dist = l.DistanceToSq(p, true);
|
||||
if(dist < mindist) mindist = dist;
|
||||
}
|
||||
|
||||
// Better match?
|
||||
if(mindist > founddist)
|
||||
{
|
||||
foundpoint = p;
|
||||
founddist = mindist;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return foundpoint;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -247,7 +247,31 @@ namespace CodeImp.DoomBuilder.Map
|
|||
#endregion
|
||||
|
||||
#region ================== Methods
|
||||
|
||||
|
||||
// This creates a bounding box rectangle
|
||||
// This requires the sector polygon to be up-to-date!
|
||||
public RectangleF CreateBBox()
|
||||
{
|
||||
// Setup
|
||||
float left = float.MaxValue;
|
||||
float top = float.MaxValue;
|
||||
float right = float.MinValue;
|
||||
float bottom = float.MinValue;
|
||||
|
||||
// Go for vertices
|
||||
foreach(FlatVertex v in vertices)
|
||||
{
|
||||
// Update rect
|
||||
if(v.x < left) left = v.x;
|
||||
if(v.y < top) top = v.y;
|
||||
if(v.x > right) right = v.x;
|
||||
if(v.y > bottom) bottom = v.y;
|
||||
}
|
||||
|
||||
// Return rectangle
|
||||
return new RectangleF(left, top, right - left, bottom - top);
|
||||
}
|
||||
|
||||
// This joins the sector with another sector
|
||||
// This sector will be disposed
|
||||
public void Join(Sector other)
|
||||
|
|
Loading…
Reference in a new issue