# A unexpected behaviour of RelationGraph

\$Version


"10.4.1 for Microsoft Windows (64-bit) (April 11, 2016)"

I want to match the based point of VoronoiMesh(pts in code) with its polygon(poly in code).This is my code

SeedRandom[2016526]
pts = RandomReal[{-1, 1}, {15, 2}];
mesh = VoronoiMesh[pts];
Show[%, Graphics[{Orange, Point[pts]}]]
poly = MeshPrimitives[mesh, 2];


When using the documentation of RelationGraph's first method:

RelationGraph[RegionMember[#2, #1] &, Join[pts, poly]]


We get a wrong result and a error information like

In this case,I can understand its error information but its wrong result.Then we try its second method in documentation.

RelationGraph[RegionMember[#2, #1] &, pts, poly]


We get some error information and the right result.Confuse me about it error informations like following

But I think I'm using this function in a right way.How to understand these phenomena?And when I use Echo to look this code's process

But as the documentation

I think shouldn't appear the elements of pts to be the parameter of RegionMember at the same time.This is a bug or I miss something?And how to adjust this code?

• Have you seen this? – J. M.'s torpor May 26 '16 at 4:12
• @J.M. Thanks for your link.But this post is that I suspect a bug in RelationGraph :) – yode May 26 '16 at 11:29
• Yes, I only linked to it because there are easier ways to match points to their corresponding Voronoi cells. – J. M.'s torpor May 26 '16 at 11:33

Two argument form:

RelationGraph[f, {v1, v2, ...}] gives the graph with vertices vi and edges from vi to vj whenever f[vi, vj] is True.

What's not stated is that there is a check that f[v1, v1] returns explicitly True or False. You can use TrueQ to ensure this, so for example this gives the correct result:

RelationGraph[TrueQ @ RegionMember[#2, #1] &, Join[pts, poly]]


Of course there are still warnings when RegionMember[point, polygon] is called.

Three argument form:

RelationGraph[f, {v1, v2, ...}, {w1, w2, ...}] gives the graph with vertices vi, wj and edges from vi to wj whenever f[vi, wj] is True.

If you check the internal code (for example with GeneralUtilitiesPrintDefinitions[RelationGraph]) it is clear that the criterion is tested in both directions, f[vi, wj] and f[wj, vi]. So again there are warnings when RegionMember[point, polygon] is called. It's not clear if this is a bug or incomplete documentation.

Workaround:

In either case you can get the correct result without warnings by using a function that only calls RegionMember if the arguments are the right way round, and returns False otherwise.

rm[q_List, p_Polygon] := RegionMember[p, q]
rm[__] = False;

RelationGraph[rm, pts, poly]
`

• Do you agree this is a bug?If you think so,I will add a bug title for the question. – yode Apr 2 '17 at 11:41
• @yode, I think it's more likely the intended behaviour, but not properly documented. – Simon Woods Apr 2 '17 at 11:44
• But I think this sentence portray the behavior completely – yode Apr 2 '17 at 11:48