some fixes and additions with floating point vertices

This commit is contained in:
codeimp 2008-05-05 22:22:53 +00:00
parent 4522698765
commit d0f6963fb2
11 changed files with 68 additions and 11 deletions

View file

@ -291,6 +291,7 @@
<Compile Include="IO\DoomPictureReader.cs" />
<Compile Include="IO\FileImageReader.cs" />
<Compile Include="IO\IImageReader.cs" />
<Compile Include="IO\IMapSetIO.cs" />
<Compile Include="IO\Lump.cs" />
<Compile Include="IO\MapSetIO.cs" />
<Compile Include="IO\UniversalMapSetIO.cs" />

View file

@ -301,6 +301,9 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
// Stitch geometry
if(snaptonearest) General.Map.Map.StitchGeometry();
// Snap to map format accuracy
General.Map.Map.SnapAllToAccuracy();
// Update cached values
General.Map.Map.Update();

View file

@ -332,6 +332,9 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
// Make corrections for backward linedefs
MapSet.FlipBackwardLinedefs(newlines);
// Snap to map format accuracy
General.Map.Map.SnapAllToAccuracy();
// Update cached values
map.Update();

View file

@ -103,7 +103,7 @@ namespace CodeImp.DoomBuilder
public GameConfiguration Config { get { return config; } }
public GridSetup Grid { get { return grid; } }
public UndoManager UndoRedo { get { return undoredo; } }
public Type Type { get { return io.GetType(); } }
public IMapSetIO FormatInterface { get { return io; } }
#endregion

View file

@ -47,6 +47,7 @@ namespace CodeImp.DoomBuilder.IO
#region ================== Properties
public override int MaxSidedefs { get { return 65534; } }
public override int VertexDecimals { get { return 0; } }
#endregion

View file

@ -47,6 +47,7 @@ namespace CodeImp.DoomBuilder.IO
#region ================== Properties
public override int MaxSidedefs { get { return 65534; } }
public override int VertexDecimals { get { return 0; } }
#endregion

38
Source/IO/IMapSetIO.cs Normal file
View file

@ -0,0 +1,38 @@
#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 System.IO;
using CodeImp.DoomBuilder.Map;
using System.Reflection;
using System.Diagnostics;
#endregion
namespace CodeImp.DoomBuilder.IO
{
public interface IMapSetIO
{
int MaxSidedefs { get; }
int VertexDecimals { get; }
}
}

View file

@ -30,7 +30,7 @@ using System.Diagnostics;
namespace CodeImp.DoomBuilder.IO
{
internal abstract class MapSetIO
internal abstract class MapSetIO : IMapSetIO
{
#region ================== Constants
@ -49,13 +49,14 @@ namespace CodeImp.DoomBuilder.IO
#region ================== Properties
public abstract int MaxSidedefs { get; }
public abstract int VertexDecimals { get; }
#endregion
#region ================== Constructor / Disposer
// Constructor
public MapSetIO(WAD wad, MapManager manager)
internal MapSetIO(WAD wad, MapManager manager)
{
// Initialize
this.wad = wad;

View file

@ -48,6 +48,7 @@ namespace CodeImp.DoomBuilder.IO
#region ================== Properties
public override int MaxSidedefs { get { return int.MaxValue; } }
public override int VertexDecimals { get { return 3; } }
#endregion

View file

@ -1205,6 +1205,12 @@ namespace CodeImp.DoomBuilder.Map
#region ================== Tools
// This snaps all vertices to the map format accuracy
public void SnapAllToAccuracy()
{
foreach(Vertex v in vertices) v.SnapToAccuracy();
}
// This returns the next unused tag number
public int GetNewTag()
{

View file

@ -194,19 +194,21 @@ namespace CodeImp.DoomBuilder.Map
public void Move(Vector2D newpos)
{
// Change position
this.Move((int)Math.Round(newpos.x), (int)Math.Round(newpos.y));
}
// This moves the vertex
public void Move(int newx, int newy)
{
// Change position
pos = new Vector2D(newx, newy);
pos = newpos;
// Let all lines know they need an update
foreach(Linedef l in linedefs) l.NeedUpdate();
}
// This snaps the vertex to the map format accuracy
public void SnapToAccuracy()
{
// Round the coordinates
Vector2D newpos = new Vector2D((float)Math.Round(pos.x, General.Map.FormatInterface.VertexDecimals),
(float)Math.Round(pos.y, General.Map.FormatInterface.VertexDecimals));
this.Move(newpos);
}
// This snaps the vertex to the grid
public void SnapToGrid()
{