why wont this work...

This commit is contained in:
codeimp 2007-12-05 19:39:09 +00:00
parent f6774910cc
commit 0e819705bf
3 changed files with 104 additions and 6 deletions

View file

@ -29,6 +29,7 @@ using CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Rendering;
using CodeImp.DoomBuilder.Geometry;
using System.Drawing;
#endregion
@ -225,6 +226,7 @@ namespace CodeImp.DoomBuilder.Editing
ICollection<Linedef> movinglines;
ICollection<Linedef> fixedlines;
ICollection<Linedef> changedlines;
Rectangle editarea;
int stitches = 0;
int stitchundo;
@ -245,6 +247,11 @@ namespace CodeImp.DoomBuilder.Editing
// ===== BEGIN GEOMETRY STITCHING
// Determine area in which we are editing
editarea = MapSet.AreaFromVertices(selectedverts);
editarea.Inflate((int)Math.Ceiling(General.Settings.StitchDistance),
(int)Math.Ceiling(General.Settings.StitchDistance));
// Make undo for the stitching
stitchundo = General.Map.UndoRedo.CreateUndo("stitch geometry", UndoGroup.None, 0, false);
@ -261,9 +268,11 @@ namespace CodeImp.DoomBuilder.Editing
General.Map.Map.Update();
// Split moving lines with unselected vertices
unselectedverts = MapSet.FilterArea(unselectedverts, ref editarea);
stitches += MapSet.SplitLinesByVertices(movinglines, unselectedverts, General.Settings.StitchDistance, movinglines);
// Split non-moving lines with selected vertices
fixedlines = MapSet.FilterArea(fixedlines, ref editarea);
stitches += MapSet.SplitLinesByVertices(fixedlines, selectedverts, General.Settings.StitchDistance, movinglines);
// Remove looped linedefs

View file

@ -24,6 +24,7 @@ using System.Text;
using CodeImp.DoomBuilder.Geometry;
using CodeImp.DoomBuilder.Rendering;
using SlimDX.Direct3D;
using System.Drawing;
#endregion
@ -64,7 +65,8 @@ namespace CodeImp.DoomBuilder.Map
private float length;
private float lengthinv;
private float angle;
private Rectangle rect;
// Properties
private int flags;
private int action;
@ -99,6 +101,7 @@ namespace CodeImp.DoomBuilder.Map
public float LengthInv { get { return lengthinv; } }
public float Angle { get { return angle; } }
public int AngleDeg { get { return (int)(angle * Angle2D.PIDEG); } }
public Rectangle Rect { get { return rect; } }
#endregion
@ -239,6 +242,7 @@ namespace CodeImp.DoomBuilder.Map
public void Update()
{
Vector2D delta;
int l, t, r, b;
// Update if needed
if(updateneeded)
@ -251,6 +255,11 @@ namespace CodeImp.DoomBuilder.Map
length = (float)Math.Sqrt(lengthsq);
if(length > 0f) lengthinv = 1f / length; else lengthinv = 1f / 0.0000000001f;
angle = delta.GetAngle();
l = Math.Min(start.X, end.X);
t = Math.Min(start.Y, end.Y);
r = Math.Max(start.X, end.X);
b = Math.Max(start.Y, end.Y);
rect = new Rectangle(l, t, r - l, b - t);
// Updated
updateneeded = false;

View file

@ -386,7 +386,87 @@ namespace CodeImp.DoomBuilder.Map
#endregion
#region ================== Static Tools
#region ================== Areas
// This creates an area from vertices
public static Rectangle AreaFromVertices(ICollection<Vertex> verts)
{
int l = int.MaxValue;
int t = int.MaxValue;
int r = int.MinValue;
int b = int.MinValue;
// Go for all vertices
foreach(Vertex v in verts)
{
// Adjust boundaries by vertices
if(v.X < l) l = v.X;
if(v.X > r) r = v.X;
if(v.Y < t) t = v.Y;
if(v.Y > b) b = v.Y;
}
// Return a rect
return new Rectangle(l, t, r - l, b - t);
}
// This filters lines by a square area
public static ICollection<Linedef> FilterArea(ICollection<Linedef> lines, ref Rectangle area)
{
ICollection<Linedef> newlines = new List<Linedef>(lines.Count);
// Go for all lines
foreach(Linedef l in lines)
{
// Check the cs field bits
if((GetCSFieldBits(l.Start, ref area) & GetCSFieldBits(l.End, ref area)) != 0)
{
// The line could be in the area
newlines.Add(l);
}
}
// Return result
return newlines;
}
// This returns the cohen-sutherland field bits for a vertex in a rectangle area
private static byte GetCSFieldBits(Vertex v, ref Rectangle area)
{
byte bits = 0;
if(v.Y < area.Top) bits |= 0x01;
if(v.Y > area.Bottom) bits |= 0x02;
if(v.X < area.Left) bits |= 0x04;
if(v.X > area.Right) bits |= 0x08;
return bits;
}
// This filters vertices by a square area
public static ICollection<Vertex> FilterArea(ICollection<Vertex> verts, ref Rectangle area)
{
ICollection<Vertex> newverts = new List<Vertex>(verts.Count);
// Go for all verts
foreach(Vertex v in verts)
{
// Within rect?
if((v.X >= area.Left) &&
(v.X <= area.Right) &&
(v.Y >= area.Top) &&
(v.Y <= area.Bottom))
{
// The vertex is in the area
newverts.Add(v);
}
}
// Return result
return newverts;
}
#endregion
#region ================== Geometry Tools
// This joins overlapping lines together
// Returns the number of joins made
@ -596,9 +676,9 @@ namespace CodeImp.DoomBuilder.Map
nl.Update();
// Add both lines to changedlines
changedlines.Add(l);
changedlines.Add(nl);
if(changedlines != null) changedlines.Add(l);
if(changedlines != null) changedlines.Add(nl);
// Count the split
splitsdone++;
splitted = true;
@ -762,7 +842,7 @@ namespace CodeImp.DoomBuilder.Map
// A line is unstable when one vertex is selected and the other isn't.
public ICollection<Linedef> LinedefsFromSelectedVertices(bool includeunselected, bool includestable, bool includeunstable)
{
List<Linedef> list = new List<Linedef>();
List<Linedef> list = new List<Linedef>((linedefs.Count / 2) + 1);
// Go for all lines
foreach(Linedef l in linedefs)