completely got rid of integral vertex coordinates (now all floating point)

This commit is contained in:
codeimp 2008-05-05 22:01:27 +00:00
parent 87ca45f93d
commit 4522698765
10 changed files with 69 additions and 74 deletions

View file

@ -145,7 +145,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
{
foreach(Linedef l in unstablelines)
{
Vector2D delta = new Vector2D(l.End.X - l.Start.X, l.End.Y - l.Start.Y);
Vector2D delta = l.End.Position - l.Start.Position;
Vector2D textpos = l.Start.Position + (delta * 0.5f);
int length = (int)Math.Round(l.Length);
renderer.RenderTextCentered(length.ToString(), textpos, General.Colors.Highlight, true);

View file

@ -154,7 +154,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
\***************************************************/
// Make first vertex
Vertex v1 = map.CreateVertex((int)points[0].pos.x, (int)points[0].pos.y);
Vertex v1 = map.CreateVertex(points[0].pos);
// Keep references
newverts.Add(v1);
@ -164,7 +164,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
for(int i = 1; i < points.Count; i++)
{
// Create vertex for point
Vertex v2 = map.CreateVertex((int)points[i].pos.x, (int)points[i].pos.y);
Vertex v2 = map.CreateVertex(points[i].pos);
// Keep references
newverts.Add(v2);
@ -208,7 +208,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
Vector2D splitpoint = measureline.GetCoordinatesAt(u);
// Make the vertex
Vertex splitvertex = map.CreateVertex((int)splitpoint.x, (int)splitpoint.y);
Vertex splitvertex = map.CreateVertex(splitpoint);
// The Split method ties the end of the original line to the given
// vertex and starts a new line at the given vertex, so continue

View file

@ -92,7 +92,7 @@ namespace CodeImp.DoomBuilder.Geometry
foreach(Vertex v in General.Map.Map.Vertices)
{
// More to the right?
if((foundv == null) || (v.X >= foundv.X))
if((foundv == null) || (v.Position.x >= foundv.Position.x))
{
// Vertex is inside the polygon?
if(p.Intersect(v.Position))

View file

@ -319,8 +319,8 @@ namespace CodeImp.DoomBuilder.Geometry
if(found != null)
{
// Check if more to the right than the previous found
if((sd.Key.Line.Start.X > found.X) && !ignores.ContainsKey(sd.Key.Line.Start)) found = sd.Key.Line.Start;
if((sd.Key.Line.End.X > found.X) && !ignores.ContainsKey(sd.Key.Line.End)) found = sd.Key.Line.End;
if((sd.Key.Line.Start.Position.x > found.Position.x) && !ignores.ContainsKey(sd.Key.Line.Start)) found = sd.Key.Line.Start;
if((sd.Key.Line.End.Position.x > found.Position.x) && !ignores.ContainsKey(sd.Key.Line.End)) found = sd.Key.Line.End;
}
}

View file

@ -150,7 +150,7 @@ namespace CodeImp.DoomBuilder.IO
y = reader.ReadInt16();
// Create new item
v = map.CreateVertex(x, y);
v = map.CreateVertex(new Vector2D((float)x, (float)y));
// Add it to the lookup table
link.Add(i, v);
@ -373,8 +373,8 @@ namespace CodeImp.DoomBuilder.IO
foreach(Vertex v in map.Vertices)
{
// Write properties to stream
writer.Write((Int16)v.X);
writer.Write((Int16)v.Y);
writer.Write((Int16)(int)Math.Round(v.Position.x));
writer.Write((Int16)(int)Math.Round(v.Position.y));
}
// Find insert position and remove old lump

View file

@ -159,7 +159,7 @@ namespace CodeImp.DoomBuilder.IO
y = reader.ReadInt16();
// Create new item
v = map.CreateVertex(x, y);
v = map.CreateVertex(new Vector2D((float)x, (float)y));
// Add it to the lookup table
link.Add(i, v);
@ -395,8 +395,8 @@ namespace CodeImp.DoomBuilder.IO
foreach(Vertex v in map.Vertices)
{
// Write properties to stream
writer.Write((Int16)v.X);
writer.Write((Int16)v.Y);
writer.Write((Int16)(int)Math.Round(v.Position.x));
writer.Write((Int16)(int)Math.Round(v.Position.y));
}
// Find insert position and remove old lump

View file

@ -44,7 +44,7 @@ namespace CodeImp.DoomBuilder.Interface
public void ShowInfo(Vertex v)
{
// Vertex info
position.Text = v.X + ", " + v.Y;
position.Text = v.Position.x.ToString("0.##") + ", " + v.Position.y.ToString("0.##");
// Show the whole thing
this.Show();

View file

@ -65,7 +65,7 @@ namespace CodeImp.DoomBuilder.Map
private float length;
private float lengthinv;
private float angle;
private Rectangle rect;
private RectangleF rect;
// Properties
private int flags;
@ -103,7 +103,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; } }
public RectangleF Rect { get { return rect; } }
public byte[] Args { get { return args; } }
public SortedList<string, object> Fields { get { return fields; } }
@ -249,7 +249,7 @@ namespace CodeImp.DoomBuilder.Map
public void UpdateCache()
{
Vector2D delta;
int l, t, r, b;
float l, t, r, b;
// Update if needed
if(updateneeded)
@ -263,11 +263,11 @@ namespace CodeImp.DoomBuilder.Map
if(length > 0f) lengthinv = 1f / length; else lengthinv = 1f / 0.0000000001f;
if(lengthsq > 0f) lengthsqinv = 1f / lengthsq; else lengthsqinv = 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);
l = Math.Min(start.Position.x, end.Position.x);
t = Math.Min(start.Position.y, end.Position.y);
r = Math.Max(start.Position.x, end.Position.x);
b = Math.Max(start.Position.y, end.Position.y);
rect = new RectangleF(l, t, r - l, b - t);
// Updated
updateneeded = false;

View file

@ -155,7 +155,7 @@ namespace CodeImp.DoomBuilder.Map
foreach(Vertex v in vertices)
{
// Make new vertex
v.Clone = newset.CreateVertex(v.X, v.Y);
v.Clone = newset.CreateVertex(v.Position);
v.CopyPropertiesTo(v.Clone);
}
@ -208,7 +208,7 @@ namespace CodeImp.DoomBuilder.Map
}
// This creates a new vertex
public Vertex CreateVertex(int x, int y)
public Vertex CreateVertex(Vector2D pos)
{
LinkedListNode<Vertex> listitem;
Vertex v;
@ -217,7 +217,7 @@ namespace CodeImp.DoomBuilder.Map
listitem = new LinkedListNode<Vertex>(null);
// Make the vertex
v = new Vertex(this, listitem, x, y);
v = new Vertex(this, listitem, pos);
listitem.Value = v;
// Add vertex to the list
@ -610,55 +610,55 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Areas
// This creates an area from vertices
public static Rectangle CreateArea(ICollection<Vertex> verts)
public static RectangleF CreateArea(ICollection<Vertex> verts)
{
int l = int.MaxValue;
int t = int.MaxValue;
int r = int.MinValue;
int b = int.MinValue;
float l = float.MaxValue;
float t = float.MaxValue;
float r = float.MinValue;
float b = float.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;
if(v.Position.x < l) l = v.Position.x;
if(v.Position.x > r) r = v.Position.x;
if(v.Position.y < t) t = v.Position.y;
if(v.Position.y > b) b = v.Position.y;
}
// Return a rect
return new Rectangle(l, t, r - l, b - t);
return new RectangleF(l, t, r - l, b - t);
}
// This creates an area from linedefs
public static Rectangle CreateArea(ICollection<Linedef> lines)
public static RectangleF CreateArea(ICollection<Linedef> lines)
{
int l = int.MaxValue;
int t = int.MaxValue;
int r = int.MinValue;
int b = int.MinValue;
float l = float.MaxValue;
float t = float.MaxValue;
float r = float.MinValue;
float b = float.MinValue;
// Go for all linedefs
foreach(Linedef ld in lines)
{
// Adjust boundaries by vertices
if(ld.Start.X < l) l = ld.Start.X;
if(ld.Start.X > r) r = ld.Start.X;
if(ld.Start.Y < t) t = ld.Start.Y;
if(ld.Start.Y > b) b = ld.Start.Y;
if(ld.End.X < l) l = ld.End.X;
if(ld.End.X > r) r = ld.End.X;
if(ld.End.Y < t) t = ld.End.Y;
if(ld.End.Y > b) b = ld.End.Y;
if(ld.Start.Position.x < l) l = ld.Start.Position.x;
if(ld.Start.Position.x > r) r = ld.Start.Position.x;
if(ld.Start.Position.y < t) t = ld.Start.Position.y;
if(ld.Start.Position.y > b) b = ld.Start.Position.y;
if(ld.End.Position.x < l) l = ld.End.Position.x;
if(ld.End.Position.x > r) r = ld.End.Position.x;
if(ld.End.Position.y < t) t = ld.End.Position.y;
if(ld.End.Position.y > b) b = ld.End.Position.y;
}
// Return a rect
return new Rectangle(l, t, r - l, b - t);
return new RectangleF(l, t, r - l, b - t);
}
// This filters lines by a square area
public static ICollection<Linedef> FilterByArea(ICollection<Linedef> lines, ref Rectangle area)
public static ICollection<Linedef> FilterByArea(ICollection<Linedef> lines, ref RectangleF area)
{
ICollection<Linedef> newlines = new List<Linedef>(lines.Count);
@ -678,18 +678,18 @@ namespace CodeImp.DoomBuilder.Map
}
// This returns the cohen-sutherland field bits for a vertex in a rectangle area
private static int GetCSFieldBits(Vertex v, ref Rectangle area)
private static int GetCSFieldBits(Vertex v, ref RectangleF area)
{
int 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;
if(v.Position.y < area.Top) bits |= 0x01;
if(v.Position.y > area.Bottom) bits |= 0x02;
if(v.Position.x < area.Left) bits |= 0x04;
if(v.Position.x > area.Right) bits |= 0x08;
return bits;
}
// This filters vertices by a square area
public static ICollection<Vertex> FilterByArea(ICollection<Vertex> verts, ref Rectangle area)
public static ICollection<Vertex> FilterByArea(ICollection<Vertex> verts, ref RectangleF area)
{
ICollection<Vertex> newverts = new List<Vertex>(verts.Count);
@ -697,10 +697,10 @@ namespace CodeImp.DoomBuilder.Map
foreach(Vertex v in verts)
{
// Within rect?
if((v.X >= area.Left) &&
(v.X <= area.Right) &&
(v.Y >= area.Top) &&
(v.Y <= area.Bottom))
if((v.Position.x >= area.Left) &&
(v.Position.x <= area.Right) &&
(v.Position.y >= area.Top) &&
(v.Position.y <= area.Bottom))
{
// The vertex is in the area
newverts.Add(v);
@ -725,7 +725,7 @@ namespace CodeImp.DoomBuilder.Map
ICollection<Vertex> nearbyfixedverts;
ICollection<Vertex> movingverts;
ICollection<Vertex> fixedverts;
Rectangle editarea;
RectangleF editarea;
int stitches = 0;
int stitchundo;
@ -998,8 +998,12 @@ namespace CodeImp.DoomBuilder.Map
if(l.DistanceToSq(v.Position, true) <= splitdist2)
{
// Line is not already referencing v?
if(((l.Start.X != v.X) || (l.Start.Y != v.Y)) &&
((l.End.X != v.X) || (l.End.Y != v.Y)))
Vector2D deltastart = l.Start.Position - v.Position;
Vector2D deltaend = l.End.Position - v.Position;
if(((Math.Abs(deltastart.x) > 0.001f) ||
(Math.Abs(deltastart.y) > 0.001f)) &&
((Math.Abs(deltaend.x) > 0.001f) ||
(Math.Abs(deltaend.y) > 0.001f)))
{
// Split line l with vertex v
nl = l.Split(v);

View file

@ -48,7 +48,6 @@ namespace CodeImp.DoomBuilder.Map
private LinkedListNode<Vertex> mainlistitem;
// Position
private int x, y;
private Vector2D pos;
// References
@ -74,8 +73,6 @@ namespace CodeImp.DoomBuilder.Map
public MapSet Map { get { return map; } }
public ICollection<Linedef> Linedefs { get { return linedefs; } }
public Vector2D Position { get { return pos; } }
public int X { get { return x; } }
public int Y { get { return y; } }
public bool IsDisposed { get { return isdisposed; } }
public bool Selected { get { return selected; } set { selected = value; } }
public bool Marked { get { return marked; } set { marked = value; } }
@ -87,15 +84,13 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Constructor / Disposer
// Constructor
public Vertex(MapSet map, LinkedListNode<Vertex> listitem, int x, int y)
public Vertex(MapSet map, LinkedListNode<Vertex> listitem, Vector2D pos)
{
// Initialize
this.map = map;
this.linedefs = new LinkedList<Linedef>();
this.mainlistitem = listitem;
this.pos = new Vector2D(x, y);
this.x = x;
this.y = y;
this.pos = pos;
// We have no destructor
GC.SuppressFinalize(this);
@ -174,8 +169,6 @@ namespace CodeImp.DoomBuilder.Map
public void CopyPropertiesTo(Vertex v)
{
// Copy properties
v.x = x;
v.y = y;
v.pos = pos;
if(fields != null) v.MakeFields(fields);
v.selected = selected;
@ -208,8 +201,6 @@ namespace CodeImp.DoomBuilder.Map
public void Move(int newx, int newy)
{
// Change position
x = newx;
y = newy;
pos = new Vector2D(newx, newy);
// Let all lines know they need an update