Skip to content

Commit ae1ba34

Browse files
committed
Cleanup connection construction
1 parent b7ad7e8 commit ae1ba34

File tree

1 file changed

+18
-31
lines changed

1 file changed

+18
-31
lines changed

osu.Framework/Graphics/Lines/Path_DrawNode.cs

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -116,26 +116,31 @@ private void addConnectionBetween(DrawableSegment segment, DrawableSegment prevS
116116
if (thetaDiff == 0f)
117117
return;
118118

119+
// more than 90 degrees - add end cap to the previous segment
120+
if (Math.Abs(thetaDiff) > Math.PI * 0.5)
121+
{
122+
addEndCap(prevSegment);
123+
return;
124+
}
125+
119126
Vector2 origin = segment.Guide.StartPoint;
120127
Line end = thetaDiff > 0f ? new Line(segment.BottomLeft, segment.TopLeft) : new Line(segment.TopLeft, segment.BottomLeft);
121128
Line start = thetaDiff > 0f ? new Line(prevSegment.TopRight, prevSegment.BottomRight) : new Line(prevSegment.BottomRight, prevSegment.TopRight);
122129

123-
if (Math.Abs(thetaDiff) < Math.PI / max_res) // small angle, 1 triangle
124-
{
125-
drawTriangle(new Triangle(start.EndPoint, Vector2.Lerp(start.StartPoint, end.EndPoint, 0.5f), end.StartPoint), origin);
126-
}
127-
else if (Math.Abs(thetaDiff) < Math.PI * 0.5) // less than 90 degrees, 2 triangles
128-
{
129-
Vector2 middle1 = Vector2.Lerp(start.EndPoint, end.StartPoint, 0.5f);
130-
Vector2 v3 = Vector2.Lerp(origin, middle1, radius / (float)Math.Cos(Math.Abs(thetaDiff) * 0.5) / Vector2.Distance(origin, middle1));
130+
// position of a vertex which is located slightly below segments intersection
131+
Vector2 innerVertex = Vector2.Lerp(start.StartPoint, end.EndPoint, 0.5f);
131132

132-
Vector2 middle2 = Vector2.Lerp(start.StartPoint, end.EndPoint, 0.5f);
133-
drawQuad(new Quad(start.EndPoint, v3, middle2, end.StartPoint), origin);
134-
}
135-
else // more than 90 degrees - cap
133+
// at this small angle curvature of the connection isn't noticeable, we can get away with a single triangle
134+
if (Math.Abs(thetaDiff) < Math.PI / max_res)
136135
{
137-
addEndCap(prevSegment);
136+
drawTriangle(new Triangle(start.EndPoint, innerVertex, end.StartPoint), origin);
137+
return;
138138
}
139+
140+
// 2 triangles for the remaining cases
141+
Vector2 middle1 = Vector2.Lerp(start.EndPoint, end.StartPoint, 0.5f);
142+
Vector2 outerVertex = Vector2.Lerp(origin, middle1, radius / (float)Math.Cos(Math.Abs(thetaDiff) * 0.5) / Vector2.Distance(origin, middle1));
143+
drawQuad(new Quad(start.EndPoint, outerVertex, innerVertex, end.StartPoint), origin);
139144
}
140145

141146
private void drawTriangle(Triangle triangle, Vector2 origin)
@@ -227,24 +232,6 @@ private void drawQuad(Quad quad, Quad relativePos)
227232

228233
private void updateVertexBuffer()
229234
{
230-
// Explanation of the terms "left" and "right":
231-
// "Left" and "right" are used here in terms of a typical (Cartesian) coordinate system.
232-
// So "left" corresponds to positive angles (anti-clockwise), and "right" corresponds
233-
// to negative angles (clockwise).
234-
//
235-
// Note that this is not the same as the actually used coordinate system, in which the
236-
// y-axis is flipped. In this system, "left" corresponds to negative angles (clockwise)
237-
// and "right" corresponds to positive angles (anti-clockwise).
238-
//
239-
// Using a Cartesian system makes the calculations more consistent with typical math,
240-
// such as in angle<->coordinate conversions and ortho vectors. For example, the x-unit
241-
// vector (1, 0) has the orthogonal y-unit vector (0, 1). This would be "left" in the
242-
// Cartesian system. But in the actual system, it's "right" and clockwise. Where
243-
// this becomes confusing is during debugging, because OpenGL uses a Cartesian system.
244-
// So to make debugging a bit easier (i.e. w/ RenderDoc or Nsight), this code uses terms
245-
// that make sense in the realm of OpenGL, rather than terms which are technically
246-
// accurate in the actually used "flipped" system.
247-
248235
Debug.Assert(segments.Count > 0);
249236

250237
Line? segmentToDraw = null;

0 commit comments

Comments
 (0)