mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-30 15:41:30 +00:00
131 lines
2.9 KiB
C#
131 lines
2.9 KiB
C#
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
/*
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
* This program is released under GNU General Public License
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
*/
|
|
|
|
#endregion
|
|
|
|
#region ================== Namespaces
|
|
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Text;
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
using CodeImp.DoomBuilder.Rendering;
|
|
using SlimDX.Direct3D;
|
|
using System.Drawing;
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
#endregion
|
|
|
|
namespace CodeImp.DoomBuilder.Geometry
|
|
{
|
|
public class LinedefTracePath : List<Linedef>
|
|
{
|
|
#region ================== Constants
|
|
|
|
#endregion
|
|
|
|
#region ================== Variables
|
|
|
|
#endregion
|
|
|
|
#region ================== Properties
|
|
|
|
#endregion
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
// Constructor
|
|
public LinedefTracePath()
|
|
{
|
|
// Initialize
|
|
}
|
|
|
|
// Constructor
|
|
public LinedefTracePath(IEnumerable<Linedef> lines) : base(lines)
|
|
{
|
|
// Initialize
|
|
}
|
|
|
|
// Constructor
|
|
public LinedefTracePath(ICollection<LinedefSide> lines) : base(lines.Count)
|
|
{
|
|
// Initialize
|
|
foreach(LinedefSide ls in lines) base.Add(ls.Line);
|
|
}
|
|
|
|
// Constructor
|
|
public LinedefTracePath(LinedefTracePath p, Linedef add) : base(p)
|
|
{
|
|
// Initialize
|
|
base.Add(add);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ================== Methods
|
|
|
|
// This checks if the polygon is closed
|
|
public bool CheckIsClosed()
|
|
{
|
|
// There must be at least 2 sidedefs
|
|
if(base.Count > 1)
|
|
{
|
|
// The end sidedef must share a vertex with the first
|
|
return (base[0].Start == base[base.Count - 1].Start) ||
|
|
(base[0].Start == base[base.Count - 1].End) ||
|
|
(base[0].End == base[base.Count - 1].Start) ||
|
|
(base[0].End == base[base.Count - 1].End);
|
|
}
|
|
else
|
|
{
|
|
// Not closed
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// This makes a polygon from the path
|
|
public Polygon MakePolygon()
|
|
{
|
|
Polygon p = new Polygon();
|
|
bool forward = true;
|
|
|
|
// Any sides at all?
|
|
if(base.Count > 0)
|
|
{
|
|
p.AddLast(new EarClipVertex(base[0].Start.Position));
|
|
|
|
// Add all lines, but the first
|
|
for(int i = 1; i < base.Count; i++)
|
|
{
|
|
// Traverse direction changes?
|
|
if((base[i - 1].Start == base[i].Start) ||
|
|
(base[i - 1].End == base[i].End))
|
|
forward = !forward;
|
|
|
|
// Add next vertex
|
|
if(forward)
|
|
p.AddLast(new EarClipVertex(base[i].Start.Position));
|
|
else
|
|
p.AddLast(new EarClipVertex(base[i].End.Position));
|
|
}
|
|
}
|
|
|
|
return p;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|