public void TestConstructor2() { ISvgMatrix m = new SvgMatrix(1, 2, 3, 4, 5, 6); Assert.AreEqual(1, m.A); Assert.AreEqual(2, m.B); Assert.AreEqual(3, m.C); Assert.AreEqual(4, m.D); Assert.AreEqual(5, m.E); Assert.AreEqual(6, m.F); }
public void TestConstructor() { ISvgMatrix m = new SvgMatrix(); Assert.AreEqual(1, m.A); Assert.AreEqual(0, m.B); Assert.AreEqual(0, m.C); Assert.AreEqual(1, m.D); Assert.AreEqual(0, m.E); Assert.AreEqual(0, m.F); }
public void TestFlipY() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgMatrix m2 = m1.FlipY(); Assert.AreEqual(1, m2.A); Assert.AreEqual(2, m2.B); Assert.AreEqual(-3, m2.C); Assert.AreEqual(-4, m2.D); Assert.AreEqual(5, m2.E); Assert.AreEqual(6, m2.F); }
public void TestInverse() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgMatrix m2 = m1.Inverse(); Assert.AreEqual(-2, m2.A); Assert.AreEqual(1, m2.B); Assert.AreEqual(1.5, m2.C); Assert.AreEqual(-0.5, m2.D); Assert.AreEqual(1, m2.E); Assert.AreEqual(-2, m2.F); }
public ISvgMatrix Multiply(ISvgMatrix secondMatrix) { if (secondMatrix == null) { secondMatrix = new SvgMatrix(); } SvgMatrix matrix = (SvgMatrix)secondMatrix; return(new SvgMatrix( this.a * matrix.a + this.c * matrix.b, this.b * matrix.a + this.d * matrix.b, this.a * matrix.c + this.c * matrix.d, this.b * matrix.c + this.d * matrix.d, this.a * matrix.e + this.c * matrix.f + this.e, this.b * matrix.e + this.d * matrix.f + this.f )); }
/// <summary> /// For each given element, the accumulation of all transformations that have been defined /// on the given element and all of its ancestors up to and including the element that /// established the current viewport (usually, the 'svg' element which is the most /// immediate ancestor to the given element) is called the current transformation matrix /// or CTM. /// </summary> /// <returns>A matrix representing the mapping of current user coordinates to viewport /// coordinates.</returns> public ISvgMatrix GetCTM() { ISvgMatrix matrix = new SvgMatrix(); ISvgTransformList svgTList; ISvgMatrix vCTM; // if (this is SvgSvgElement) if (string.Equals(this.Name, "svg", StringComparison.Ordinal)) { vCTM = ((SvgSvgElement)this).ViewBoxTransform; matrix = vCTM; } else if (this.Transform != null) { svgTList = this.Transform.AnimVal; matrix = svgTList.Consolidate().Matrix; } ISvgElement nVE = this.NearestViewportElement; if (nVE != null) { SvgTransformableElement par = ParentNode as SvgTransformableElement; while (par != null && par != nVE) { svgTList = par.Transform.AnimVal; matrix = svgTList.Consolidate().Matrix.Multiply(matrix); par = par.ParentNode as SvgTransformableElement; } // if (par == nVE && nVE is SvgSvgElement) if (par == nVE && string.Equals(nVE.Name, "svg", StringComparison.Ordinal)) { vCTM = ((SvgSvgElement)nVE).ViewBoxTransform; matrix = vCTM.Multiply(matrix); } } return(matrix); }
/// <summary> /// For each given element, the accumulation of all transformations that have been defined /// on the given element and all of its ancestors up to and including the element that /// established the current viewport (usually, the 'svg' element which is the most /// immediate ancestor to the given element) is called the current transformation matrix /// or CTM. /// </summary> /// <returns>A matrix representing the mapping of current user coordinates to viewport /// coordinates.</returns> public ISvgMatrix GetCTM() { ISvgMatrix matrix = new SvgMatrix(); ISvgTransformList svgTList; ISvgMatrix vCTM; if (this is SvgSvgElement) { vCTM = (this as SvgSvgElement).ViewBoxTransform; matrix = vCTM; } else if (this.Transform != null) { svgTList = this.Transform.AnimVal; matrix = svgTList.Consolidate().Matrix; } ISvgElement nVE = this.NearestViewportElement; if (nVE != null) { SvgTransformableElement par = ParentNode as SvgTransformableElement; while (par != null && par != nVE) { svgTList = par.Transform.AnimVal; matrix = svgTList.Consolidate().Matrix.Multiply(matrix); par = par.ParentNode as SvgTransformableElement; } if (par == nVE && nVE is SvgSvgElement) { vCTM = (nVE as SvgSvgElement).ViewBoxTransform; matrix = vCTM.Multiply(matrix); } } return(matrix); }
public RectangleF GetBRect(float margin) { if (this is ISharpGDIPath) { ISharpGDIPath gdiPathElm = (ISharpGDIPath)this; GraphicsPath gp = gdiPathElm.GetGraphicsPath(); SvgMatrix svgMatrix = (SvgMatrix)this.GetScreenCTM(); RectangleF bounds = gp.GetBounds(svgMatrix.ToMatrix()); bounds = RectangleF.Inflate(bounds, margin, margin); return(bounds); } else if (this is ISvgUseElement) { SvgUseElement use = (SvgUseElement)this; SvgTransformableElement refEl = use.ReferencedElement as SvgTransformableElement; if (refEl == null) { return(RectangleF.Empty); } XmlElement refElParent = (XmlElement)refEl.ParentNode; OwnerDocument.Static = true; use.CopyToReferencedElement(refEl); this.AppendChild(refEl); RectangleF bbox = refEl.GetBRect(margin); this.RemoveChild(refEl); use.RestoreReferencedElement(refEl); refElParent.AppendChild(refEl); OwnerDocument.Static = false; return(bbox); } else { RectangleF union = RectangleF.Empty; SvgTransformableElement transformChild; foreach (XmlNode childNode in ChildNodes) { if (childNode is SvgDefsElement) { continue; } if (childNode is ISvgTransformable) { transformChild = (SvgTransformableElement)childNode; RectangleF bbox = transformChild.GetBRect(margin); if (bbox != RectangleF.Empty) { if (union == RectangleF.Empty) { union = bbox; } else { union = RectangleF.Union(union, bbox); } } } } return(union); } }
public void TestRotateFromVectorZeroY() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 6, 0, 0); ISvgMatrix m2 = m1.RotateFromVector(1, 0); }
public void TestTranslate() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgMatrix m2 = m1.Translate(10,20); Assert.AreEqual(1, m2.A); Assert.AreEqual(2, m2.B); Assert.AreEqual(3, m2.C); Assert.AreEqual(4, m2.D); Assert.AreEqual(75, m2.E); Assert.AreEqual(106, m2.F); }
/// <summary> /// For each given element, the accumulation of all transformations that have been defined /// on the given element and all of its ancestors up to and including the element that /// established the current viewport (usually, the 'svg' element which is the most /// immediate ancestor to the given element) is called the current transformation matrix /// or CTM. /// </summary> /// <returns>A matrix representing the mapping of current user coordinates to viewport /// coordinates.</returns> public ISvgMatrix GetCTM() { ISvgMatrix matrix = new SvgMatrix(); ISvgTransformList svgTList; ISvgMatrix vCTM; if (this is SvgSvgElement) { vCTM = (this as SvgSvgElement).ViewBoxTransform; matrix = vCTM; } else if (this.Transform != null) { svgTList = this.Transform.AnimVal; matrix = svgTList.Consolidate().Matrix; } ISvgElement nVE = this.NearestViewportElement; if(nVE != null) { SvgTransformableElement par = ParentNode as SvgTransformableElement; while(par != null && par != nVE) { svgTList = par.Transform.AnimVal; matrix = svgTList.Consolidate().Matrix.Multiply(matrix); par = par.ParentNode as SvgTransformableElement; } if (par == nVE && nVE is SvgSvgElement) { vCTM = (nVE as SvgSvgElement).ViewBoxTransform; matrix = vCTM.Multiply(matrix); } } return matrix; }
public void TestSkewX() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgMatrix m2 = m1.SkewX(30); Assert.AreEqual(1, m2.A); Assert.AreEqual(2, m2.B); Assert.AreEqual(3.57735026918963f, m2.C); Assert.AreEqual(5.15470053837925f, m2.D); Assert.AreEqual(5, m2.E); Assert.AreEqual(6, m2.F); }
public void TestSkewY() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgMatrix m2 = m1.SkewY(30); Assert.AreEqual(2.73205080756888f, m2.A); Assert.AreEqual(4.3094010767585f, m2.B); Assert.AreEqual(3, m2.C); Assert.AreEqual(4, m2.D); Assert.AreEqual(5, m2.E); Assert.AreEqual(6, m2.F); }
public ISvgMatrix GetScreenCTM() { ISvgMatrix matrix = new SvgMatrix(); ISvgTransformList svgTList; ISvgMatrix vCTM; if (this is SvgSvgElement) { vCTM = (this as SvgSvgElement).ViewBoxTransform; matrix = vCTM; } else if (this.Transform != null) { svgTList = this.Transform.AnimVal; matrix = svgTList.Consolidate().Matrix; } SvgTransformableElement par = ParentNode as SvgTransformableElement; while(par != null) { // TODO: other elements can establish viewports, not just <svg>! if (par is SvgSvgElement) { vCTM = (par as SvgSvgElement).ViewBoxTransform; matrix = vCTM.Multiply(matrix); } else { svgTList = par.Transform.AnimVal; matrix = svgTList.Consolidate().Matrix.Multiply(matrix); } par = par.ParentNode as SvgTransformableElement; } // Now scale out the pixels //ISvgSvgElement root = OwnerDocument.RootElement; //float innerWidth = this.OwnerDocument.Window.InnerWidth; //float innerHeight = this.OwnerDocument.Window.InnerHeight; //if (innerWidth != 0 && innerHeight != 0) //{ // float screenRatW = (float)root.Width.AnimVal.Value / innerWidth; // float screenRatH = (float)root.Height.AnimVal.Value / innerHeight; // matrix.ScaleNonUniform(screenRatW, screenRatH); //} return matrix; }
public void TestNoInverse() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 6, 0, 0); ISvgMatrix m2 = m1.Inverse(); }
public void TestMultiply2() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgMatrix m2 = new SvgMatrix(7, 8, 9, 10, 11, 12); SvgMatrix m3 = (SvgMatrix) m1 * (SvgMatrix) m2; Assert.AreEqual(31, m3.A); Assert.AreEqual(46, m3.B); Assert.AreEqual(39, m3.C); Assert.AreEqual(58, m3.D); Assert.AreEqual(52, m3.E); Assert.AreEqual(76, m3.F); }
public void TestRotate() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgMatrix m2 = m1.Rotate(30); Assert.AreEqual(2.36602540378444f, m2.A); Assert.AreEqual(3.73205080756888f, m2.B); Assert.AreEqual(2.09807621135332f, m2.C); Assert.AreEqual(2.46410161513775f, m2.D); Assert.AreEqual(5, m2.E); Assert.AreEqual(6, m2.F); }
public void TestRotateFromVector() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgMatrix m2 = m1.RotateFromVector(1.73205080756888f, 1); Assert.AreEqual(2.36602540378444f, m2.A); Assert.AreEqual(3.73205080756888f, m2.B); Assert.AreEqual(2.09807621135332f, m2.C); //D property incorrect when using doubles, probably due to rounding //Assert.AreEqual(2.46410161513775, m2.D); Assert.AreEqual(2.46410161513776f, m2.D); Assert.AreEqual(5, m2.E); Assert.AreEqual(6, m2.F); }
public void TestScale() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgMatrix m2 = m1.Scale(10); Assert.AreEqual(10, m2.A); Assert.AreEqual(20, m2.B); Assert.AreEqual(30, m2.C); Assert.AreEqual(40, m2.D); Assert.AreEqual(5, m2.E); Assert.AreEqual(6, m2.F); }
public void TestScaleNonUniform() { ISvgMatrix m1 = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgMatrix m2 = m1.ScaleNonUniform(10,20); Assert.AreEqual(10, m2.A); Assert.AreEqual(20, m2.B); Assert.AreEqual(60, m2.C); Assert.AreEqual(80, m2.D); Assert.AreEqual(5, m2.E); Assert.AreEqual(6, m2.F); }
public ISvgMatrix Multiply(ISvgMatrix secondMatrix) { if (secondMatrix == null) { secondMatrix = new SvgMatrix(); } SvgMatrix matrix = (SvgMatrix)secondMatrix; return new SvgMatrix( this.a * matrix.a + this.c * matrix.b, this.b * matrix.a + this.d * matrix.b, this.a * matrix.c + this.c * matrix.d, this.b * matrix.c + this.d * matrix.d, this.a * matrix.e + this.c * matrix.f + this.e, this.b * matrix.e + this.d * matrix.f + this.f ); }
public void TestMatrixTransformIdentity() { SvgMatrix m = new SvgMatrix(1, 2, 3, 4, 5, 6); ISvgPoint p2 = p.MatrixTransform(m); Assert.AreEqual(10, p.X); Assert.AreEqual(20, p.Y); Assert.AreEqual(75, p2.X); Assert.AreEqual(106, p2.Y); }