Bug in Shape.DistanceFrom ??

T

Tsung-Yuan Liu

I tried to use the DistanceFrom property of the Shape object in Visio to
compute the distances between two shapes.
However, I found that for two shapes A and B, the values for
A.DistanceFrom(B, 0)
and
B.DistanceFrom(A, 0)
are sometimes different.

I opened a new Flowchart (Metric) drawing,
placed two "Process"es next to each other horizontally.
resized one so that they are of different sizes,
and making sure that the top and bottom sides of the two rectangles are not
on a straight line.
Then I tried the code:
Debug.Print
ActiveWindow.Page.Shapes.ItemFromID(1).DistanceFrom(ActiveWindow.Page.Shapes.ItemFromID(2), 0)
Debug.Print
ActiveWindow.Page.Shapes.ItemFromID(2).DistanceFrom(ActiveWindow.Page.Shapes.ItemFromID(1), 0)
and found that they output different values.

Is this normal?
 
J

JuneTheSecond

No, I cold not found difference.
If you turn one shape, then the difference appears.
I don't know why, because I don't know what the DistanceFrom method measures.
 
J

John Marshall, MVP

DistanceFromPoint goes to the nearest edge, but I am not sure of the logic
for DistanceFrom. It appears that it is the closest edge, but there is no
indication of the starting point. There is a difference going from B to A
rather than A to B for some shapes, so it may be related to the PinX and
PinY. Hopefully one of the MS team will see this message and comment.

John... Visio MVP

Need stencils or ideas? http://www.mvps.org/visio/3rdparty.htm
Need VBA examples? http://www.mvps.org/visio/VBA.htm
Common Visio Questions http://www.mvps.org/visio/common_questions.htm
Visio Wishlist http://www.mvps.org/visio/wish_list.htm
 
J

JuneTheSecond

I am not sure, but I assume that the smaller value may be the right distance.
 
T

Tsung-Yuan Liu

I am guessing that A.DistanceFrom(B )
returns the closest distance between the vertices of A to the edges in B,
resulting in different distances between A to B and B to A.

Perhaps the implementation of DistanceFrom just runs a loop over the
vertices and compute DistanceFromPoint for each one...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top