BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Close Relation of Fill Color to HitTest and Spatial Search

Started by JuneTheSecond, September 10, 2009, 05:18:05 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.



There is a close relation among Fill Color and HitTest method and SpatialSearch method.
Both HitTest and SpatialSearch method analyze the shape, and decide where is a given point in relation to the shape, inside, outside, or on the boundary, etc.

The base of the decision, I seem, may be the fill color.
Inside of the shape is the filled part of the shape.
If a rectangle is filled with any color of any fill pattern, the filled place is inside.
If you make a complicated shape that partly not filled with color, for example, a shape like a shining star drawn with line tool, there may be at least a place where is not filled with color and it is not inside of the shape there, but outside of the shape.

There are two ways to remove the fill color of a shape.
One of them is to set the cell "FillPatern" to 0 or with menu Format / Fill / No Pattern.
Another way is to set cell "Geometry.NoFill" to TRUE.

The value of the cell "FillPattern" never affects the HitTest method nor SpatialSearch method, but the value TRUE of "Geometry.NoFill" strongly affects them.
Every place in the shape is outside, and every line of the shape is boundary no matter how the shape is complicated.

Attached sample of Visio drawing with VBA macro demonstrates such phenomena.
Right-click on each shape runs HitTest Method, and right-click menus on the page runs SpatialSearch method for the boundary or for contained in (inside).

You need to move the red marker on any place on any shapes, especially on the boundary of the shape or inside of the shape but not filled with color.

You need to remove fill-color with "Geometry.NoFill" set to TRUE in order to get right results when the center of the red maker is on the boundary of a shape. Or you will sometimes get wrong results.

I hope you enjoy much with the example shapes. :) :) ;) ;) :D
Best Regards,

Junichi Yoda


Most excellent JuneTheSecond!

When I saw the title, and even, as I started to read, I kept wondering what this was all about.  But, your examples were excellent, and they dispelled some old myth that I apparently had -- namely, to fill a shape, it had to closed and contiguous.  Clearly that's not true!!!  Now I'm scratching my head trying to figure out how I came to believe that.   ???  So, as long as a shape has both non-zero width and height selection box, then, by setting the Geometry#.NoFill entry to false (# being a number, usually 1), then that shape will be filled.

After all these years, that's like a major revelation!!!   :o
Visio 2019 Pro



Thank you wapperdude.
Now, you made me more clear about fill-color to the open shape.
And thank you for you kindly to read my long Japanese-English.

And I shall modify my sample drawing because of errors.
1. Error of the comments in the message box.
2. Lack of center lines on the red marker.
3. The accuracy in the HitTest method and SpatialSearch are not same.
Best Regards,

Junichi Yoda



I have to explain more about the relation among fill-colors, HitTest and Spacial Search.
But I think the attached figure and sample drawing explain better than my poor English.
Best Regards,

Junichi Yoda

Visio Guy

Another side effect of "opening up" a filled shape by setting GeometryN.Nofill = True is that arrowheads will appear.

Compare and contrast the rectangle and the line in the image below:

For articles, tips and free content, see the Visio Guy Website at
Get my Visio Book! Using Microsoft Visio 2010



Thank you Chris.
I shall take care enough to avoide side effect of arrow heads for the health of Visio shapes. :) :) :)
Best Regards,

Junichi Yoda



I wish to explain more about the side effect of "Geomerty1.NoFill" when HitTest or SpacialSearch detect the boundary of shape.
If the shape is normally filled with color, and if the center of the red maker is just on the boundary of the shape, HitTest and SpacialSearch answer "Here is inside." It is not correct.
But if the fill color is removed by "Geomerty1.NoFill = True", they give correct answer "Hers is boundary". (Image5.jpg)

I've examined the argument "Accuracy" of these methods, changing the values.
If the "Acuracy" is not zero, for example 0.03 inch, and the shape is normally filled, then the line of decision offsets to the outside of the shape. If the acuracy is zero, and the shape is normally filled, then the line of decision for the boundary dissapears, and the methods cannot find the boundary.
But if the fill color is removed by "Geomerty1.NoFill = True", they give correct answer "Hers is boundary", though the metods answer "Everywhere in the shape is outside".

I think "Geomerty1.NoFill = True" is a magic bullet with severe side effects. :) :) :)
Best Regards,

Junichi Yoda


Before you guys auger in too much on this, understand there is a subtle anomally with visio regarding values of numbers.

Specifically.   0.000000000000000000000000000000000000001 is viewed differently from an execution standpoint than 0
(even though I got to believe there is some rounding of this number to 0 in the executables...would be pretty intense to actually work with 1 ** 10-20  mm. for visual data)

This anomally showed up in setatref for me sometime back.   Took a while to understand but, in essence, setatref views 0.00000000000000000000000000000000001 differently than 0 for such things as an offset in the reference.

I suspect this has to do with the number system in visio rather than setatref functions themselves.

What I did to get around this was to make sure any offset = 0 really was offset = 0000000001.  Visually, it gave me the behavior I wanted and execution wise made setatref work as desired.



Lot of thanks, vojo. :) :)
HitTest found the bounary at the offset of 0.000001 mm, even if the "Accuracy" =0. :) :) :)
And even more close to the boundary of 0.0000001 mm.
Best Regards,

Junichi Yoda



I found correct offset is 0.0000000254MM with a macro. :) :) :)
That is 0.0000000254MM = 0.000000001 inches = 1E-9 inches
It is independent from the Accuracy of HitTest. ;) ;) ;)
The Maco is below.

Sub FindBorderWithHitTest()
    Dim shp As Visio.Shape
    Dim shp2 As Visio.Shape
    Dim Iret As Integer
    Dim myPinY As Double
    Dim I As Long
    Set shp2 = ActivePage.Shapes.ItemFromID(2)
    Set shp = ActivePage.Shapes.ItemFromID(3)
    shp2.Cells("piny").FormulaU = "200.0 mm"
    For I = 1 To 1000
        shp2.Cells("piny").FormulaU = "200.0 mm+" & I * 0.0000000001 & "mm"
        Iret = shp.HitTest(shp2.Cells("pinx"), shp2.Cells("piny"), myAccuracy)
        If Iret = visHitOnBoundary Then
            MsgBox "The center of red marker is just on the boundary of   " & shp.Name
            Debug.Print "I = " & I
            Exit For
        End If
End Sub

Image below is the snap shot at this moment.
Best Regards,

Junichi Yoda



This is not main theme, but sub product.
I've found the guide lines are neither horizontal nor vertical in microscopic order.
It is a matter of microscopic order.
Practically you can regard them as correctly horizontal and vertical. :) :) :)
Best Regards,

Junichi Yoda



A kind of tool to detect x and y coordinates of a point in micorscopic order.
Best Regards,

Junichi Yoda



As guide lines are not neither horizontal nor Vertical in microscopic order,
then I removed guide lines and tried again the "HitTest" to detect the border line.
Each line of the rectangle is correctly horizontal or vertical even in microscopic order.
The offset to the top line is the same 0.0000000254 mm. (Image12.jpg)
I've found the offset to right line is not the same, but 0.000000000186 mm.(Image13.jpg)
Bottom and left does not shifted. :) :)
Best Regards,

Junichi Yoda



This is the matter of "Text Fileds" in the above pointing tool.
If you wish to copy the text on the shape of pointing tool,
you cannot copy text and paste it correctly to the Visio page nor on text pad.
You may see this problem in the text fileds in any shapes.
Then I added shape data (custom property), and added a formula
"=SHAPETEXT(TheText)" to display the shape text in the shape data dialog.
Here you can copy the text in the shape data dialog by keying "Ctrl +C". :) :) :)
Best Regards,

Junichi Yoda


Best Regards,

Junichi Yoda

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 403 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1304KB.
Tokens: post-login.
Cache hits: 13: 0.00118s for 26,767 bytes (show)
Cache misses: 2: (show)
Queries used: 15.

[Show Queries]