Type this info a console app (or open event and replace print by system.debuglog or whatever) and run it.
Var OrigRect As New Rect(0, 0, 200, 200)
Var smallerRect As New Rect(0, 0, 100, 100)
smallerRect.Center = OrigRect.Center
print smallerRect.Left.ToString + "/" + smallerRect.top.ToString
Would you agree that the result according to the docs should be 50/50?
They stay at 0/0 with 2021r1.1. A known bug?
No, I don’t think it’s a bug since the Rects are position-relative to themselves. They have no (apparent) parent window/canvas/etc so Left and Top are remaining relative to the Rect itself. The line
smallerRect.Center = OrigRect.Center
merely positions them but does not define any other relationships between them.
Because that’s exactly what it does. You can think of it as a 100 cm square piece of paper on top of a 200 cm square piece of paper. Positioning the smaller one so its center is aligned with the center of the larger one doesn’t change the fact that its Left edge has no relation to the Left edge of the larger one (except maybe visually).
If you are needing the relative positions, then you need to define something they are both relative to. For example, drawing them into a Canvas will give then both positional relevance to the Canvas and using the Rect.Center to align them will allow you to get the relationship of their Left edges relative to the Canvas. But without a common reference, they are just two objects floating in cyberspace that happen to be the same shape.
Thanks for your answer, Dale, but I don’t get your point.
The docs say “Changing the center value will move the rect”.
How does a rect move? By changing its origin.
When I take your example: When I align a smaller piece’s of paper center point to that of a bigger ones, of course I expect the smaller one to move. Otherwise Center would just be a read-only property. From the documentation it is not, so why can it be set without changing the origin?
EDIT: Of course I do agree you have to have a reference system, so it would rather make sense to have a method like Rect.Center(toRect as Rect). But basically that reference system is derived from setting the center coordinates.