private Affine(AffinePlan[] creationPlans) { //----------------------- //start with identity matrix _elems = AffineMat.Iden;//copy isIdenHint = true; if (creationPlans == null) { return; } //----------------------- int j = creationPlans.Length; for (int i = 0; i < j; ++i) { AffinePlan plan = creationPlans[i]; switch (plan.cmd) { case AffineMatrixCommand.None: break; case AffineMatrixCommand.Rotate: isIdenHint = false; _elems.Rotate(plan.x); break; case AffineMatrixCommand.Scale: isIdenHint = false; _elems.Scale(plan.x, plan.y); break; case AffineMatrixCommand.Translate: isIdenHint = false; _elems.Translate(plan.x, plan.y); break; case AffineMatrixCommand.Skew: isIdenHint = false; _elems.Skew(plan.x, plan.y); break; case AffineMatrixCommand.Invert: isIdenHint = false; _elems.Invert(); break; default: throw new NotSupportedException(); } } }
private Affine(Affine copyFrom, AffinePlan creationPlan) { _elems = copyFrom._elems; //----------------------- switch (creationPlan.cmd) { default: { throw new NotSupportedException(); } case AffineMatrixCommand.None: _isIdenHint = copyFrom._isIdenHint; break; case AffineMatrixCommand.Rotate: _isIdenHint = false; _elems.Rotate(creationPlan.x); break; case AffineMatrixCommand.Scale: _isIdenHint = false; _elems.Scale(creationPlan.x, creationPlan.y); break; case AffineMatrixCommand.Skew: _isIdenHint = false; _elems.Skew(creationPlan.x, creationPlan.y); break; case AffineMatrixCommand.Translate: _isIdenHint = false; _elems.Translate(creationPlan.x, creationPlan.y); break; case AffineMatrixCommand.Invert: _isIdenHint = false; _elems.Invert(); break; } }
void BuildAff(ref AffinePlan plan) { switch (plan.cmd) { case AffineMatrixCommand.None: break; case AffineMatrixCommand.Rotate: _isIdenHint = false; _elems.Rotate(plan.x); break; case AffineMatrixCommand.Scale: _isIdenHint = false; _elems.Scale(plan.x, plan.y); break; case AffineMatrixCommand.Translate: _isIdenHint = false; _elems.Translate(plan.x, plan.y); break; case AffineMatrixCommand.Skew: _isIdenHint = false; _elems.Skew(plan.x, plan.y); break; case AffineMatrixCommand.Invert: _isIdenHint = false; _elems.Invert(); break; default: throw new NotSupportedException(); } }
//--------------------------------------------------------------------- public void DrawArc( float fromX, float fromY, float endX, float endY, float xaxisRotationAngleDec, float rx, float ry, SvgArcSize arcSize, SvgArcSweep arcSweep) { //------------------ //SVG Elliptical arc ... //from Apache Batik //----------------- CenterFormArc centerFormArc = new CenterFormArc(); ComputeArc2(fromX, fromY, rx, ry, AggMath.deg2rad(xaxisRotationAngleDec), arcSize == SvgArcSize.Large, arcSweep == SvgArcSweep.Negative, endX, endY, ref centerFormArc); // using (VectorToolBox.Borrow(out Arc arcTool)) using (VxsTemp.Borrow(out var v1, out var v2, out var v3)) { arcTool.Init(centerFormArc.cx, centerFormArc.cy, rx, ry, centerFormArc.radStartAngle, (centerFormArc.radStartAngle + centerFormArc.radSweepDiff)); bool stopLoop = false; foreach (VertexData vertexData in arcTool.GetVertexIter()) { switch (vertexData.command) { case VertexCmd.NoMore: stopLoop = true; break; default: v1.AddVertex(vertexData.x, vertexData.y, vertexData.command); //yield return vertexData; break; } //------------------------------ if (stopLoop) { break; } } double scaleRatio = 1; if (centerFormArc.scaleUp) { int vxs_count = v1.Count; double px0, py0, px_last, py_last; v1.GetVertex(0, out px0, out py0); v1.GetVertex(vxs_count - 1, out px_last, out py_last); double distance1 = Math.Sqrt((px_last - px0) * (px_last - px0) + (py_last - py0) * (py_last - py0)); double distance2 = Math.Sqrt((endX - fromX) * (endX - fromX) + (endY - fromY) * (endY - fromY)); if (distance1 < distance2) { scaleRatio = distance2 / distance1; } else { } } if (xaxisRotationAngleDec != 0) { //also rotate if (centerFormArc.scaleUp) { //var mat = Affine.NewMatix( // new AffinePlan(AffineMatrixCommand.Translate, -centerFormArc.cx, -centerFormArc.cy), // new AffinePlan(AffineMatrixCommand.Scale, scaleRatio, scaleRatio), // new AffinePlan(AffineMatrixCommand.Rotate, DegToRad(xaxisRotationAngleDec)), // new AffinePlan(AffineMatrixCommand.Translate, centerFormArc.cx, centerFormArc.cy)); //mat1.TransformToVxs(v1, v2); //v1 = v2; AffineMat mat = AffineMat.Iden; mat.Translate(-centerFormArc.cx, -centerFormArc.cy); mat.Scale(scaleRatio); mat.RotateDeg(xaxisRotationAngleDec); mat.Translate(centerFormArc.cx, centerFormArc.cy); VertexStoreTransformExtensions.TransformToVxs(ref mat, v1, v2); v1 = v2; } else { //not scale //var mat = Affine.NewMatix( // AffinePlan.Translate(-centerFormArc.cx, -centerFormArc.cy), // AffinePlan.RotateDeg(xaxisRotationAngleDec), // AffinePlan.Translate(centerFormArc.cx, centerFormArc.cy)); //mat.TransformToVxs(v1, v2); //v1 = v2; AffineMat mat = AffineMat.Iden; mat.Translate(-centerFormArc.cx, -centerFormArc.cy); mat.RotateDeg(xaxisRotationAngleDec); mat.Translate(centerFormArc.cx, centerFormArc.cy); VertexStoreTransformExtensions.TransformToVxs(ref mat, v1, v2); v1 = v2; } } else { //no rotate if (centerFormArc.scaleUp) { //var mat = Affine.NewMatix( // new AffinePlan(AffineMatrixCommand.Translate, -centerFormArc.cx, -centerFormArc.cy), // new AffinePlan(AffineMatrixCommand.Scale, scaleRatio, scaleRatio), // new AffinePlan(AffineMatrixCommand.Translate, centerFormArc.cx, centerFormArc.cy)); //mat.TransformToVxs(v1, v2); //v1 = v2; AffineMat mat = AffineMat.Iden; mat.Translate(-centerFormArc.cx, -centerFormArc.cy); mat.RotateDeg(scaleRatio); mat.Translate(centerFormArc.cx, centerFormArc.cy); // VertexStoreTransformExtensions.TransformToVxs(ref mat, v1, v2); v1 = v2; } } //_stroke.Width = this.StrokeWidth; //_stroke.MakeVxs(v1, v3); //_pcx.DrawGfxPath(_pcx.StrokeColor, _pathRenderVxBuilder.CreatePathRenderVx(v3)); } }