public SvgRectF GetBounds() { var elemWidth = this.Width; var elemHeight = this.Height; var isWidthInPerc = elemWidth.BaseVal.UnitType == SvgLengthType.Percentage; var isHeightInPerc = elemHeight.BaseVal.UnitType == SvgLengthType.Percentage; SvgRectF bounds = new SvgRectF(); if (isWidthInPerc || isHeightInPerc) { var viewRect = this.ViewBox.BaseVal; if (viewRect.Width > 0 && viewRect.Height > 0) { bounds = new SvgRectF((float)viewRect.X, (float)viewRect.Y, (float)viewRect.Width, (float)viewRect.Height); } else { bounds = SvgRectF.Empty;//TODO: Recursively computer the bounds?; } } if (bounds.Width.Equals(0.0) && bounds.Height.Equals(0.0)) { return(SvgRectF.Empty); } double width, height; if (isWidthInPerc) { width = (bounds.Width + bounds.X) * elemWidth.BaseVal.ValueInSpecifiedUnits * 0.01; } else { width = elemWidth.BaseVal.Value; } if (isHeightInPerc) { height = (bounds.Height + bounds.Y) * elemHeight.BaseVal.ValueInSpecifiedUnits * 0.01; } else { height = elemHeight.BaseVal.Value; } bounds.Width = (float)width; bounds.Height = (float)height; return(bounds); }
private void MapRectToRect(SvgRectF rect, SvgPointF[] plgpts) { SvgPointF pt1 = new SvgPointF(plgpts[1].X - plgpts[0].X, plgpts[1].Y - plgpts[0].Y); SvgPointF pt2 = new SvgPointF(plgpts[2].X - plgpts[0].X, plgpts[2].Y - plgpts[0].Y); this.m11 = pt1.X / rect.Width; this.m12 = pt1.Y / rect.Width; this.m21 = pt2.X / rect.Height; this.m22 = pt2.Y / rect.Height; this.dx = plgpts[0].X - rect.X / rect.Width * pt1.X - rect.Y / rect.Height * pt2.X; this.dy = plgpts[0].Y - rect.X / rect.Width * pt1.Y - rect.Y / rect.Height * pt2.Y; }
/// <summary> /// Initializes a new instance of the <see cref="SvgTransformF"/> class /// to the geometric transform defined by the specified rectangle and /// array of points. /// </summary> /// <param name="rect"> /// A <see cref="SvgRectF"/> structure that represents the rectangle /// to be transformed. /// </param> /// <param name="plgpts"> /// An array of three <see cref="SvgPointF"/> structures that represents the /// points of a parallelogram to which the upper-left, upper-right, and /// lower-left corners of the rectangle is to be transformed. The /// lower-right corner of the parallelogram is implied by the first three /// corners. /// </param> /// <exception cref="ArgumentNullException"> /// If the <paramref name="plgpts"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentException"> /// If the length of the <paramref name="plgpts"/> array is not equal /// to 3. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// If the width or height of the <paramref name="rect"/> is zero. /// </exception> public SvgTransformF(SvgRectF rect, SvgPointF[] plgpts) { if (plgpts == null) { throw new ArgumentNullException("plgpts"); } if (plgpts.Length != 3) { throw new ArgumentException("plgpts"); } if ((rect.Width == 0) || (rect.Height == 0)) { throw new ArgumentOutOfRangeException("rect"); } MapRectToRect(rect, plgpts); }
/// <summary> /// Initializes a new instance of the <see cref="SvgTransformF"/> class /// to the geometric transform defined by the specified rectangle and /// array of points. /// </summary> /// <param name="rect"> /// A <see cref="SvgRectF"/> structure that represents the rectangle /// to be transformed. /// </param> /// <param name="plgpts"> /// An array of three <see cref="SvgPointF"/> structures that represents the /// points of a parallelogram to which the upper-left, upper-right, and /// lower-left corners of the rectangle is to be transformed. The /// lower-right corner of the parallelogram is implied by the first three /// corners. /// </param> /// <exception cref="ArgumentNullException"> /// If the <paramref name="plgpts"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentException"> /// If the length of the <paramref name="plgpts"/> array is not equal /// to 3. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// If the width or height of the <paramref name="rect"/> is zero. /// </exception> public SvgTransformF(SvgRectF rect, SvgPointF[] plgpts) { if (plgpts == null) { throw new ArgumentNullException(nameof(plgpts)); } if (plgpts.Length != 3) { throw new ArgumentException(nameof(plgpts)); } if (rect.Width.Equals(0) || rect.Height.Equals(0)) { throw new ArgumentOutOfRangeException(nameof(rect)); } MapRectToRect(rect, plgpts); }