microsoft / Windows-appsample-marble-maze

A 3D DirectX game for the Universal Windows Platform.
MIT License
111 stars 65 forks source link

CheckSharesVertsOrCoplanar - an incorrect comment or a bug? #8

Open ata6502 opened 2 months ago

ata6502 commented 2 months ago

Hi, There is a CheckSharesVertsOrCoplanar method in the Triangle class (C++/Shared/Primitives.h) that claims to test if two triangles share an edge. After examination of the method, I have found that the method returns true even if the triangles share a single vertex, for example:

    // Triangle ABC.
    A = XMVectorSet(1.f, 1.f, 3.f, 0.f);
    B = XMVectorSet(6.f, 4.f, 2.f, 0.f); // B == F
    C = XMVectorSet(2.f, 5.f, 1.f, 0.f);

    // Triangle EFG.
    D = XMVectorSet(10.f, 2.f, 1.f, 0.f);
    E = XMVectorSet(8.f, 7.f, 3.f, 0.f);
    F = XMVectorSet(6.f, 4.f, 2.f, 0.f); // F == B

In spite of that the application is working fine. Could it be that the comment at the top of the method is incorrect (it reads "Tests this triangle against another one to see if it shares any edges") or is it a genuine bug?

ata6502 commented 2 months ago

I have verified that the CheckSharesVertsOrCoplanar method may incorrectly indicate that the input triangles share a vertex even if the triangles are disjoined i.e., they do not share any edges or vertices. For example:

    // ABC and DEF triangles are disjoined.

    // Triangle ABC.
    XMVECTOR A = XMVectorSet(1.f, 1.f, 1.f, 0.f);
    XMVECTOR B = XMVectorSet(2.f, 1.f, 1.f, 0.f);
    XMVECTOR C = XMVectorSet(1.f, 2.f, 1.f, 0.f);

    // Triangle DEF.
    XMVECTOR D = XMVectorSet(2.f, 2.f, 1.f, 0.f);
    XMVECTOR E = XMVectorSet(2.f, 3.f, 1.f, 0.f);
    XMVECTOR F = XMVectorSet(1.f, 3.f, 1.f, 0.f);

    // The method returns sharesEdgeOut = true

Also, the naming of the method and local variables is inconsistent: