Author Topic: Close Relation of Fill Color to HitTest and Spatial Search  (Read 15367 times)

0 Members and 1 Guest are viewing this topic.

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Close Relation of Fill Color to HitTest and Spatial Search
« on: September 10, 2009, 12:18:05 AM »
Hi,

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
« Last Edit: September 10, 2009, 07:34:01 AM by JuneTheSecond »
Best Regards,

Junichi Yoda
http://june.minibird.jp/

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3746
  • Ideas Visio-lized into solutions
Re: Close Relation of Fill Color to HitTest and Spatial Search
« Reply #1 on: September 10, 2009, 08:52:02 PM »
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

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Close Relation of Fill Color to HitTest and Spatial Search
« Reply #2 on: September 11, 2009, 12:01:08 AM »
Hi,

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.
« Last Edit: September 11, 2009, 01:20:11 AM by JuneTheSecond »
Best Regards,

Junichi Yoda
http://june.minibird.jp/

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Close Relation of Fill Color to HitTest and Spatial Search
« Reply #3 on: September 11, 2009, 04:21:43 AM »
Hi,

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.
« Last Edit: September 11, 2009, 04:30:56 AM by JuneTheSecond »
Best Regards,

Junichi Yoda
http://june.minibird.jp/

Visio Guy

  • Administrator
  • Hero Member
  • *****
  • Posts: 1707
  • Smart Graphics for Visual People...n' Stuff
    • Visio Guy
Re: Close Relation of Fill Color to HitTest and Spatial Search
« Reply #4 on: September 11, 2009, 10:10:54 AM »
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:

« Last Edit: September 11, 2009, 10:12:46 AM by Visio Guy »
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Close Relation of Fill Color to HitTest and Spatial Search
« Reply #5 on: September 12, 2009, 05:52:13 AM »
Hi,

Thank you Chris.
I shall take care enough to avoide side effect of arrow heads for the health of Visio shapes. :) :) :)
« Last Edit: September 12, 2009, 06:16:36 AM by JuneTheSecond »
Best Regards,

Junichi Yoda
http://june.minibird.jp/

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Close Relation of Fill Color to HitTest and Spatial Search
« Reply #6 on: September 12, 2009, 06:17:30 AM »
Hi,

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. :) :) :)
« Last Edit: September 12, 2009, 07:49:08 AM by JuneTheSecond »
Best Regards,

Junichi Yoda
http://june.minibird.jp/

vojo

  • Hero Member
  • *****
  • Posts: 1419
Re: Close Relation of Fill Color to HitTest and Spatial Search
« Reply #7 on: September 12, 2009, 03:32:30 PM »
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.

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Close Relation of Fill Color to HitTest and Spatial Search
« Reply #8 on: September 12, 2009, 09:52:19 PM »
Hi,

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.
« Last Edit: September 13, 2009, 06:32:36 AM by JuneTheSecond »
Best Regards,

Junichi Yoda
http://june.minibird.jp/

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Close Relation of Fill Color to HitTest and Spatial Search
« Reply #9 on: September 13, 2009, 06:42:38 AM »
Hi,

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.

Code
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
     Next
End Sub


Image below is the snap shot at this moment.
« Last Edit: September 13, 2009, 07:34:38 AM by JuneTheSecond »
Best Regards,

Junichi Yoda
http://june.minibird.jp/

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Close Relation of Fill Color to HitTest and Spatial Search
« Reply #10 on: September 16, 2009, 01:14:45 AM »
Hi,

This is not main theme, but sub product.
I've found the guide lines are neither horizontal nor vertical in microscopic order.
(Image10.jpg)
It is a matter of microscopic order.
Practically you can regard them as correctly horizontal and vertical. :) :) :)
« Last Edit: September 16, 2009, 01:26:39 AM by JuneTheSecond »
Best Regards,

Junichi Yoda
http://june.minibird.jp/

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Close Relation of Fill Color to HitTest and Spatial Search
« Reply #11 on: September 17, 2009, 12:21:14 AM »
Hi,

A kind of tool to detect x and y coordinates of a point in micorscopic order.
« Last Edit: September 17, 2009, 12:24:39 AM by JuneTheSecond »
Best Regards,

Junichi Yoda
http://june.minibird.jp/

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Close Relation of Fill Color to HitTest and Spatial Search
« Reply #12 on: September 20, 2009, 01:08:30 PM »
Hi,

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. :) :)
« Last Edit: September 20, 2009, 01:29:29 PM by JuneTheSecond »
Best Regards,

Junichi Yoda
http://june.minibird.jp/

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Close Relation of Fill Color to HitTest and Spatial Search
« Reply #13 on: September 21, 2009, 05:43:58 AM »
Hi,

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.
(Image14.jpg)
Here you can copy the text in the shape data dialog by keying "Ctrl +C". :) :) :)
« Last Edit: September 22, 2009, 02:48:18 AM by JuneTheSecond »
Best Regards,

Junichi Yoda
http://june.minibird.jp/

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Close Relation of Fill Color to HitTest and Spatial Search
« Reply #14 on: September 22, 2009, 06:36:09 AM »
HI,

Above drawing is replaced. :) :) :)
Best Regards,

Junichi Yoda
http://june.minibird.jp/