// This performs a fast test in object picking public override bool PickFastReject(Vector3D from, Vector3D to, Vector3D dir) { //mxd. Don't highlight when thing sprite is not rendered and thing cages are disabled if (!General.Map.Renderer3D.DrawThingCages && info.DistanceCheckSq < int.MaxValue && (Thing.Position - General.Map.VisualCamera.Position).GetLengthSq() > info.DistanceCheckSq) { return(false); } float distance2 = Line2D.GetDistanceToLineSq(from, to, pos2d, false); return(distance2 <= cageradius2); }
// This performs a fast test in object picking public override bool PickFastReject(Vector3D from, Vector3D to, Vector3D dir) { float distance2 = Line2D.GetDistanceToLineSq(from, to, pos2d, false); return(distance2 <= cageradius2); }
//mxd. Moved here from Tools. This finds the ideal label position for a sector private static LabelPositionInfo FindLabelPosition(Sector s) { // Do we have a triangulation? Triangulation triangles = s.Triangles; if (triangles != null) { // Go for all islands foreach (int iv in triangles.IslandVertices) { Dictionary <Sidedef, Linedef> sides = new Dictionary <Sidedef, Linedef>(iv >> 1); List <Vector2D> candidatepositions = new List <Vector2D>(iv >> 1); float founddistance = float.MinValue; Vector2D foundposition = new Vector2D(); float minx = float.MaxValue; float miny = float.MaxValue; float maxx = float.MinValue; float maxy = float.MinValue; // Make candidate lines that are not along sidedefs // We do this before testing the candidate against the sidedefs so that // we can collect the relevant sidedefs first in the same run for (int t = 0; t < iv; t += 3) { Vector2D v1 = triangles.Vertices[t + 2]; Sidedef sd = triangles.Sidedefs[t + 2]; for (int v = 0; v < 3; v++) { Vector2D v2 = triangles.Vertices[t + v]; // Not along a sidedef? Then this line is across the sector // and guaranteed to be inside the sector! if (sd == null) { // Make the line candidatepositions.Add(v1 + (v2 - v1) * 0.5f); } else { // This sidedefs is part of this island and must be checked // so add it to the dictionary sides[sd] = sd.Line; } // Make bbox of this island minx = Math.Min(minx, v1.x); miny = Math.Min(miny, v1.y); maxx = Math.Max(maxx, v1.x); maxy = Math.Max(maxy, v1.y); // Next sd = triangles.Sidedefs[t + v]; v1 = v2; } } // Any candidate lines found at all? if (candidatepositions.Count > 0) { // Start with the first line foreach (Vector2D candidatepos in candidatepositions) { // Check distance against other lines float smallestdist = int.MaxValue; foreach (KeyValuePair <Sidedef, Linedef> sd in sides) { // Check the distance float distance = sd.Value.DistanceToSq(candidatepos, true); smallestdist = Math.Min(smallestdist, distance); } // Keep this candidate if it is better than previous if (smallestdist > founddistance) { foundposition = candidatepos; founddistance = smallestdist; } } // No cceptable line found, just use the first! return(new LabelPositionInfo(foundposition, (float)Math.Sqrt(founddistance))); } // No candidate lines found. // Check to see if the island is a triangle if (iv == 3) { // Use the center of the triangle // TODO: Use the 'incenter' instead, see http://mathworld.wolfram.com/Incenter.html Vector2D v = (triangles.Vertices[0] + triangles.Vertices[1] + triangles.Vertices[2]) / 3.0f; float d = Line2D.GetDistanceToLineSq(triangles.Vertices[0], triangles.Vertices[1], v, false); d = Math.Min(d, Line2D.GetDistanceToLineSq(triangles.Vertices[1], triangles.Vertices[2], v, false)); d = Math.Min(d, Line2D.GetDistanceToLineSq(triangles.Vertices[2], triangles.Vertices[0], v, false)); return(new LabelPositionInfo(v, (float)Math.Sqrt(d))); } else { // Use the center of this island. float d = Math.Min((maxx - minx) * 0.5f, (maxy - miny) * 0.5f); return(new LabelPositionInfo(new Vector2D(minx + (maxx - minx) * 0.5f, miny + (maxy - miny) * 0.5f), d)); } } } else { // No triangulation was made. FAIL! General.Fail("No triangulation exists for sector " + s + " Triangulation is required to create label positions for a sector."); } // Nothing found... return(new LabelPositionInfo()); }
// This performs a fast test in object picking public override bool PickFastReject(Vector3D from, Vector3D to, Vector3D dir) { double distance2 = Line2D.GetDistanceToLineSq(from, to, vertex.Position, false); return(distance2 <= cageradius2); }
public float GetDistanceToLineSq(LuaVector2D p, bool bounded) { return(l2d.GetDistanceToLineSq(p.vec, bounded)); }
public float GetDistanceToLineSq(Vector2 p, bool bounded) { return(Line2D.GetDistanceToLineSq(v1, v2, p, bounded)); }