private void DrawCurveSections(Graphics g, Pen pen, EditCurve curve, double t0, double t1, double step) { Vector2[] p = new Vector2[2] { new Vector2(), new Vector2() }; int pIdx = 0; p[pIdx] = curveView.ToPixelCoordinate((float)t0, curve.Evaluate((float)t0)); for (double t = t0; t < t1;) { double nextT = t + step; t = nextT; pIdx = (pIdx + 1) & 1; p[pIdx] = curveView.ToPixelCoordinate((float)t, curve.Evaluate((float)t)); DrawLine(g, pen, p[0], p[1]); t = nextT; } }
private void DrawCurveSections(Graphics g, Pen pen, EditCurve curve, double t0, double t1, double step) { Vector2[] p = new Vector2[2] { new Vector2(), new Vector2() }; int pIdx = 0; p[pIdx] = curveView.ToPixelCoordinate((float)t0, curve.Evaluate((float)t0)); for (double t = t0; t < t1; ) { double nextT = t + step; t = nextT; pIdx = (pIdx + 1) & 1; p[pIdx] = curveView.ToPixelCoordinate((float)t, curve.Evaluate((float)t)); DrawLine(g, pen, p[0], p[1]); t = nextT; } }
/// <summary> /// Draw actual part of curve. /// </summary> /// <param name="g"></param> /// <param name="pen"></param> /// <param name="curve"></param> /// <param name="t0"></param> /// <param name="t1"></param> /// <param name="step"></param> private void DrawCurve(Graphics g, Pen pen, EditCurve curve, double t0, double t1, double step) { Vector2[] p = new Vector2[2] { new Vector2(), new Vector2() }; // Search key and next key that includes t0 position. int keyIndex = 0; EditCurveKey key = null, nextKey = null; for (; keyIndex < curve.Keys.Count; ++keyIndex) { key = nextKey; nextKey = curve.Keys[keyIndex]; if (nextKey.Position > t0) break; } int pIdx = 0; p[pIdx] = curveView.ToPixelCoordinate((float)t0, curve.Evaluate((float)t0)); for (double t = t0; t < t1;) { double nextT = t1 + step; if (nextKey != null) nextT = Math.Min(t1, nextKey.Position); // Draw current key and next key section. if (key.Continuity == CurveContinuity.Smooth) { while (t < nextT) { // If this line crosses next key position, draw line from // current position to next key position. t = ( t < nextT && t + step > nextT )? nextT: t + step; pIdx = (pIdx + 1) & 1; p[pIdx] = curveView.ToPixelCoordinate( (float)t, curve.Evaluate((float)t)); DrawLine(g, pen, p[0], p[1]); } } else { // Step case, // Draw, horizontal line. pIdx = (pIdx + 1) & 1; p[pIdx] = curveView.ToPixelCoordinate(nextKey.Position, key.Value); DrawLine(g, pen, p[0], p[1]); // Draw vertical line. pIdx = (pIdx + 1) & 1; p[pIdx] = curveView.ToPixelCoordinate( nextKey.Position, nextKey.Value); DrawLine(g, pen, p[0], p[1]); t = nextT; } // Advance to next key. key = nextKey; nextKey = (++keyIndex < curve.Keys.Count) ? curve.Keys[keyIndex] : null; } }
/// <summary> /// Draw actual part of curve. /// </summary> /// <param name="g"></param> /// <param name="pen"></param> /// <param name="curve"></param> /// <param name="t0"></param> /// <param name="t1"></param> /// <param name="step"></param> private void DrawCurve(Graphics g, Pen pen, EditCurve curve, double t0, double t1, double step) { Vector2[] p = new Vector2[2] { new Vector2(), new Vector2() }; // Search key and next key that includes t0 position. int keyIndex = 0; EditCurveKey key = null, nextKey = null; for (; keyIndex < curve.Keys.Count; ++keyIndex) { key = nextKey; nextKey = curve.Keys[keyIndex]; if (nextKey.Position > t0) { break; } } int pIdx = 0; p[pIdx] = curveView.ToPixelCoordinate((float)t0, curve.Evaluate((float)t0)); for (double t = t0; t < t1;) { double nextT = t1 + step; if (nextKey != null) { nextT = Math.Min(t1, nextKey.Position); } // Draw current key and next key section. if (key.Continuity == CurveContinuity.Smooth) { while (t < nextT) { // If this line crosses next key position, draw line from // current position to next key position. t = (t <nextT && t + step> nextT)? nextT: t + step; pIdx = (pIdx + 1) & 1; p[pIdx] = curveView.ToPixelCoordinate( (float)t, curve.Evaluate((float)t)); DrawLine(g, pen, p[0], p[1]); } } else { // Step case, // Draw, horizontal line. pIdx = (pIdx + 1) & 1; p[pIdx] = curveView.ToPixelCoordinate(nextKey.Position, key.Value); DrawLine(g, pen, p[0], p[1]); // Draw vertical line. pIdx = (pIdx + 1) & 1; p[pIdx] = curveView.ToPixelCoordinate( nextKey.Position, nextKey.Value); DrawLine(g, pen, p[0], p[1]); t = nextT; } // Advance to next key. key = nextKey; nextKey = (++keyIndex < curve.Keys.Count) ? curve.Keys[keyIndex] : null; } }