Refactoring, optimizations
This commit is contained in:
@ -139,26 +139,12 @@ namespace TransportGame.Unity
|
||||
uv.Add(v2);
|
||||
};
|
||||
|
||||
// Add current node
|
||||
// Add the node
|
||||
addV(node.Position, 0);
|
||||
vindex += 1;
|
||||
|
||||
// Sort adjacent segments in trigonometric order
|
||||
var segs = node.ArticulationSegments.OrderBy(segment =>
|
||||
{
|
||||
Vector2 dir = DirectionFrom(segment, node);
|
||||
|
||||
if (dir.X >= 0 && dir.Y >= 0) // First quadrant:
|
||||
return dir.Y; // Y coordinate grows from 0 to 1
|
||||
|
||||
else if (dir.X <= 0 && dir.Y >= 0) // Second quadrant:
|
||||
return 1 + Math.Abs(dir.X); // X goes from 0 to -1
|
||||
|
||||
else if (dir.X <= 0 && dir.Y <= 0) // Third quadrant:
|
||||
return 2 + Math.Abs(dir.Y); // Y goes from 0 to -1
|
||||
|
||||
else return 3 + dir.X; // Fourth quadrant: X grows from 0 to 1
|
||||
}).ToArray();
|
||||
var segs = node.ArticulationSegments.OrderBy(segment => DirectionFrom(segment, node), Vector2.TrigonomicComparer).ToArray();
|
||||
|
||||
Vector2[] sideCrns = new Vector2[segs.Length];
|
||||
Vector2[] strCrns = new Vector2[segs.Length];
|
||||
@ -166,7 +152,7 @@ namespace TransportGame.Unity
|
||||
// Holds intersection points for perpendicular on segment that goes through sidewalk corners
|
||||
// 0, 1, 2, 3 - 0 sidewalk, 1 street, 2 street, 3 sidewalk (in trigonometric order). (when first segment)
|
||||
// 4, 5, 6, 7 - the same (when second segment)
|
||||
Vector2[,] p = new Vector2[8, segs.Length];
|
||||
Vector2[,] p = new Vector2[8, segs.Length];
|
||||
|
||||
// Process each pair of segments
|
||||
for (int i = 0; i < segs.Length; ++i)
|
||||
|
Reference in New Issue
Block a user