@@ -62,22 +62,6 @@ public bool IsCloserThan(CloseToMouse otherItem)
6262 return this . ClosestMouseDistanceSquared < otherItem . ClosestMouseDistanceSquared ;
6363 }
6464
65- /// <summary>
66- /// get distance between two world locations not taking the height in account
67- /// </summary>
68- /// <param name="location1">first location</param>
69- /// <param name="location2">second location</param>
70- /// <returns>Distance squared</returns>
71- /// <remarks>Very similar to WordlLocation.GetDistanceSquared</remarks>
72- public static float GetGroundDistanceSquared ( WorldLocation location1 , WorldLocation location2 )
73- {
74- float dx = location1 . Location . X - location2 . Location . X ;
75- float dz = location1 . Location . Z - location2 . Location . Z ;
76- dx += 2048 * ( location1 . TileX - location2 . TileX ) ;
77- dz += 2048 * ( location1 . TileZ - location2 . TileZ ) ;
78- return dx * dx + dz * dz ;
79- }
80-
8165 }
8266
8367 /// <summary>
@@ -144,7 +128,7 @@ public CloseToMouseJunctionOrEnd(TrackNode junctionOrEndNode, string description
144128 /// <param name="description">The type of item (needed for later printing in statusbar)</param>
145129 public void CheckMouseDistance ( WorldLocation location , WorldLocation mouseLocation , TrackNode junctionOrEndNode , string description )
146130 {
147- float distanceSquared = CloseToMouse . GetGroundDistanceSquared ( location , mouseLocation ) ;
131+ float distanceSquared = WorldLocation . GetDistanceSquared2D ( location , mouseLocation ) ;
148132 if ( distanceSquared < ClosestDistanceSquared )
149133 {
150134 ClosestDistanceSquared = distanceSquared ;
@@ -210,7 +194,7 @@ public override void Reset()
210194 /// <param name="trItem">The track Item that will be stored when it is indeed the closest</param>
211195 public void CheckMouseDistance ( WorldLocation location , WorldLocation mouseLocation , DrawableTrackItem trItem )
212196 {
213- float distanceSquared = CloseToMouse . GetGroundDistanceSquared ( location , mouseLocation ) ;
197+ float distanceSquared = WorldLocation . GetDistanceSquared2D ( location , mouseLocation ) ;
214198
215199 if ( distanceSquared < ClosestDistanceSquared )
216200 {
@@ -317,7 +301,7 @@ public void CheckMouseDistance(WorldLocation location, WorldLocation mouseLocati
317301 TrackNode trackNode , TrVectorSection vectorSection , int tvsi , double pixelsPerMeter )
318302 {
319303 storedMouseLocation = mouseLocation ;
320- float distanceSquared = CloseToMouse . GetGroundDistanceSquared ( location , mouseLocation ) ;
304+ float distanceSquared = WorldLocation . GetDistanceSquared2D ( location , mouseLocation ) ;
321305 // to make unique distances becasue they also act as Key
322306 double distanceSquaredIndexed = ( ( double ) distanceSquared ) * ( 1 + 1e-16 * trackNode . Index ) ;
323307 if ( distanceSquaredIndexed < sortedTrackCandidates . First ( ) . Key )
@@ -386,8 +370,8 @@ DistanceLon CalcRealDistanceSquared(TrVectorSection trackVectorSection, TrackSec
386370 X = storedMouseLocation . Location . X - trackVectorSection . X ,
387371 Z = storedMouseLocation . Location . Z - trackVectorSection . Z
388372 } ;
389- vectorToMouse . X + = ( storedMouseLocation . TileX - trackVectorSection . TileX ) * 2048 ;
390- vectorToMouse . Z + = ( storedMouseLocation . TileZ - trackVectorSection . TileZ ) * 2048 ;
373+ vectorToMouse . X = ( float ) ( vectorToMouse . X + ( storedMouseLocation . TileX - trackVectorSection . TileX ) * WorldLocation . TileSize ) ;
374+ vectorToMouse . Z = ( float ) ( vectorToMouse . Z + ( storedMouseLocation . TileZ - trackVectorSection . TileZ ) * WorldLocation . TileSize ) ;
391375
392376 //Now rotate the vector such that a direction along the track is in a direction (x=0, z=1)
393377 vectorToMouse = Vector3 . Transform ( vectorToMouse , Matrix . CreateRotationY ( - trackVectorSection . AY ) ) ;
0 commit comments