JCash / voronoi

A C implementation for creating 2D voronoi diagrams
MIT License
633 stars 94 forks source link

half edge neighbor is incorrect #37

Closed godpenguin7 closed 5 years ago

godpenguin7 commented 5 years ago

when i iterate through a site's halfedges and look at their neighbors, they do not correspond to actual neighbors. and even if i look at the half edge's corresponding edge, its two sites are not neighboring in the diagram. untitled

godpenguin7 commented 5 years ago
int i = rand() % myCells.size();

myCells[ i ].selected = true;

const jcv_site* site = &jcv_diagram_get_sites( &diagram )[ i ];

const jcv_graphedge* edge = site->edges;

while ( edge != nullptr )
{
    const jcv_site* neighbor;

    if ( edge->edge->sites[ 0 ] == site )
    neighbor = edge->edge->sites[ 1 ];
    else
    neighbor = edge->edge->sites[ 0 ];

    if ( neighbor != nullptr )
    {
        myCells[ neighbor->index ].selected = true;
    }

    edge = edge->next;
}
JCash commented 5 years ago

Hi!

The array is sorted with respect to the points, so i != site->index

Try “myCells[ site->index ].selected = true;” and see if that makes a difference

Sent from my iPhone

On 24 Dec 2018, at 06:30, godpenguin7 notifications@github.com wrote:

int i = rand() % myCells.size();

myCells[ i ].selected = true;

const jcv_site* site = &jcv_diagram_get_sites( &diagram )[ i ];

const jcv_graphedge* edge = site->edges;

while ( edge != nullptr ) { const jcv_site* neighbor;

if ( edge->edge->sites[ 0 ] == site ) neighbor = edge->edge->sites[ 1 ]; else neighbor = edge->edge->sites[ 0 ];

if ( neighbor != nullptr ) { myCells[ neighbor->index ].selected = true; }

edge = edge->next; }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

godpenguin7 commented 5 years ago

you were right totally my fault, using site->index fixed it. thanks a lot, i was dreading switching back to this other voronoi library because yours is much faster.