void _addArcCommands( float cx, float cy, float r, float a0, float a1, PathWinding dir, bool forceMoveTo, Matrix3 transform = null) { // Clamp angles float da = a1 - a0; if (dir == PathWinding.clockwise) { if (Mathf.Abs(da) >= Mathf.PI * 2) { da = Mathf.PI * 2; } else { while (da < 0.0f) { da += Mathf.PI * 2; } if (da <= 1e-5) { return; } } } else { if (Mathf.Abs(da) >= Mathf.PI * 2) { da = -Mathf.PI * 2; } else { while (da > 0.0f) { da -= Mathf.PI * 2; } if (da >= -1e-5) { return; } } } // Split arc into max 90 degree segments. int ndivs = Mathf.Max(1, Mathf.Min((int)(Mathf.Abs(da) / (Mathf.PI * 0.5f) + 0.5f), 5)); float hda = (da / ndivs) / 2.0f; float kappa = Mathf.Abs(4.0f / 3.0f * (1.0f - Mathf.Cos(hda)) / Mathf.Sin(hda)); if (dir == PathWinding.counterClockwise) { kappa = -kappa; } PathCommand move = (forceMoveTo || this._commands.Count == 0) ? PathCommand.moveTo : PathCommand.lineTo; float px = 0, py = 0, ptanx = 0, ptany = 0; for (int i = 0; i <= ndivs; i++) { float a = a0 + da * (i / (float)ndivs); float dx = Mathf.Cos(a); float dy = Mathf.Sin(a); float x = cx + dx * r; float y = cy + dy * r; float tanx = -dy * r * kappa; float tany = dx * r * kappa; if (i == 0) { float x1 = x, y1 = y; if (transform != null) { transform.mapXY(x1, y1, out x1, out y1); } if (move == PathCommand.moveTo) { this._appendMoveTo(x1, y1); } else { this._appendLineTo(x1, y1); } } else { float c1x = px + ptanx; float c1y = py + ptany; float c2x = x - tanx; float c2y = y - tany; float x1 = x; float y1 = y; if (transform != null) { transform.mapXY(c1x, c1y, out c1x, out c1y); transform.mapXY(c2x, c2y, out c2x, out c2y); transform.mapXY(x1, y1, out x1, out y1); } this._appendBezierTo(c1x, c1y, c2x, c2y, x1, y1); } px = x; py = y; ptanx = tanx; ptany = tany; } }
public void winding(PathWinding dir) { this._appendWinding((float)dir); }