Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect bounds of transformed SVG group #946

Open
lukastrm opened this issue Jan 24, 2022 · 1 comment
Open

Incorrect bounds of transformed SVG group #946

lukastrm opened this issue Jan 24, 2022 · 1 comment
Labels

Comments

@lukastrm
Copy link

Description

SvgGroup.Bounds does not return the correct bounds if transformations have been applied to the SVG group.
The reason for this is that SvgGroup.Bounds first determines the correct bounds of all child elements and then applies its transformations to these bounds (via SvgElement.TransformedBounds(RectangleF bounds) instead of first applying its transformations to the child elements and determining the bounds afterwards. As a result the returned bounds are the bounds of a transformed rectangle but not the bounds of the contained elements.

Example data

In this example we see a circle in an SVG group. The SVG group has a rotation of 45 degrees around the center of the circle. The group bounds should be tight around the circle but instead the bounding rectangle of the circle is rotated 45 degrees and then the group bounds refer to that, thus making it larger than it acutally should be.

bounds

public void WrongBounds() {
    var svgCircle = new SvgCircle {
        CenterX = 200, CenterY = 200, Radius = 100, Fill = new SvgColourServer(Color.Gray)
    };

    var svgGroup = new SvgGroup {
        Children = {svgCircle}, Transforms = new SvgTransformCollection {new SvgRotate(45, 200, 200)}
    };

    var bounds = svgGroup.Bounds;

    var boundsSvgRectangle = new SvgRectangle {
        X = bounds.X,
        Y = bounds.Y,
        Width = bounds.Width,
        Height = bounds.Height,
        Stroke = new SvgColourServer(Color.Red),
        Fill = new SvgColourServer(Color.Transparent)
    };

    var document = new SvgDocument();
    document.Children.Add(svgGroup);
    document.Children.Add(boundsSvgRectangle);
    // ...
}

Used Versions

.NET 5.0
SVG.NET 3.4.0

@DmitrijOkeanij
Copy link

DmitrijOkeanij commented Jan 11, 2024

Please fix this bug.
In my project i have many math operations on SVG, and many fails because bounds calculates incorrectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants