WPF PathGeometry - Are Borders Wrong?

I have a pretty simple PathGeometry:

M567764.539,5956314.087L567815.077,5956179.775L567821.625,5956182.314L567773.425,5956311.248L567858.513,5956349.923L567950.858,5956392.466L567949.039,5956399.843L567942.252,5956396.685L567873.018,5956364.467L567799.816,5956330.421L567771.226,5956317.186L567764.539,5956314.087 

Now, when I request the PathGeometry.Bounds attribute for this data, I get the following estimates:

 567764.5625,5956180 567950.875,5956400 

Expected Grades:

 567764.539,5956179.775 567950.858,5956399.843 

My main problem: borders are less than geometry, so parts of the geometry can be outside the borders.

I create a PathGeometry and show the borders as follows:

 PathGeometry geo = PathGeometry.CreateFromGeometry(Geometry.Parse("M567764.539,5956314.087L567815.077,5956179.775L567821.625,5956182.314L567773.425,5956311.248L567858.513,5956349.923L567950.858,5956392.466L567949.039,5956399.843L567942.252,5956396.685L567873.018,5956364.467L567799.816,5956330.421L567771.226,5956317.186L567764.539,5956314.087")); System.Diagnostics.Trace.WriteLine(geo.Bounds); 

What am I doing wrong?
And, more importantly, how do I get the correct bounds for PathGeometry?

+4
source share
2 answers

At some point, I would think that WPF should convert to a single point for rendering, and I wonder if the Bounds value is based on the result. In this case, you probably see an accuracy limitation based on the large quantities that you use. I noticed that your Y values ​​were 10 times bigger than X, and coincidentally the error was also 10 times bigger than the error in X.

If you can subtract the minimum X and Y values ​​before creating PathGeometry, I think you will get better numbers. Assuming you are showing PathGeometry, you can put it on the canvas and apply Canvas.Left / Top to your values ​​to get the correct screen offset. To get the correct borders, you then added top / left offsets to the result of your borders.

Just a reminder that there are several suggestions in this answer. I did not look at the internal operation of Bounds, but the relative error seems to indicate conversion to and from float.

+2
source

I think you see the inaccuracy due to the fact that PathGeometry numbers are made up of large floating point numbers.

I'm not sure that you can get the necessary accuracy.

You may have to compare the boundaries using an acceptable tolerance, for example:

 bool isMatch = (Math.Abs(MyPath.Bounds.X - ExpectedBounds.X) < TOLERANCE); 

where you can set TOLERANCE to 0.25 or something like that.

0
source

Source: https://habr.com/ru/post/1379125/


All Articles