# matchBodys_udf_1
# written by John Dannenhoffer

# make the Bodys
SKBEG     -3  0  0
   LINSEG -1  0  0
   LINSEG -2  1  0
   LINSEG -1  2  0
   LINSEG -3  2  0
   LINSEG -3  0  0
SKEND
SELECT    FACE
ATTRIBUTE _color $red
STORE     body 1

SKBEG     -1  0  0
   LINSEG  1  0  0
   LINSEG  1  2  0
   LINSEG -1  2  0
   LINSEG -1  0  0
SKEND
SELECT    FACE
ATTRIBUTE _color $green
STORE     body 2

SKBEG     1  0  0
   LINSEG 1  2  0
   LINSEG 3  1  0
   LINSEG 1  0  0
SKEND
SELECT    FACE
ATTRIBUTE _color $blue
STORE     body 3

# matches between Bodys 1 and 2
RESTORE   body  1
RESTORE   body  2
UDPRIM    matchBodys
ASSERT    @@nnodes      2               # number of matching Nodes
ASSERT    @@nedges      0               # number of matching Edges
ASSERT    @@nfaces      0               # number of matching Faces

SELECT    BODY          @nbody-1
GETATTR   matches       $_nodeMatches_
ASSERT    matches.size  2
ASSERT    matches[1]    2               # Node 2 of red Body matches Node 1 of green Body
ASSERT    matches[2]    4               # Node 4 of red Body matches Node 4 of green Body

SELECT    BODY          @nbody
GETATTR   matches       $_nodeMatches_
ASSERT    matches.size  2
ASSERT    matches[1]    1
ASSERT    matches[2]    4

# matches between Bodys 2 and 3
RESTORE   body  2
RESTORE   body  3
UDPRIM    matchBodys
ASSERT    @@nnodes      2               # number if matching Nodes
ASSERT    @@nedges      1               # number of matching Edges
ASSERT    @@nfaces      0               # number of matching Faces

SELECT    BODY          @nbody-1
GETATTR   matches       $_nodeMatches_
ASSERT    matches.size  2
ASSERT    matches[1]    2               # Node 2 of green Body matches Node 1 of blue Body
ASSERT    matches[2]    3               # Node 3 of green Body matches Node 3 of blue Body

SELECT    BODY          @nbody
GETATTR   matches       $_nodeMatches_
ASSERT    matches.size  2
ASSERT    matches[1]    1
ASSERT    matches[2]    3

SELECT    BODY          @nbody-1
GETATTR   matches       $_edgeMatches_
ASSERT    matches.size  1               # Edge 2 of green Body matches Edge 3 of blue Body
ASSERT    matches[1]    2

SELECT    BODY          @nbody
GETATTR   matches       $_edgeMatches_
ASSERT    matches.size  1
ASSERT    matches[1]    3

# clear stack and show Bodys
STORE     ...
RESTORE   body  1
RESTORE   body  2
RESTORE   body  3

END
