Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edges Always 0 #7

Open
cjburkey01 opened this issue May 12, 2018 · 5 comments
Open

Edges Always 0 #7

cjburkey01 opened this issue May 12, 2018 · 5 comments

Comments

@cjburkey01
Copy link

cjburkey01 commented May 12, 2018

I know this repository is somewhat not maintained anymore, but whenever I use the library, the edges are always 0, no matter what I do. The points are not zero, I have checked that. The strange thing is if I do something like site.NearestEdge(), it is not zero, but every edge in site.Edges and voronoi.Edges is at (0, 0), always. (When I say the edges are zero, I mean that their vertices are both (0, 0), and that only the NearestEdge() has non zero vertices, but only when printed using the ToString() method).

Update: I actually think the vertex position is always (0, 0); when the ToString() method was used, it showed the site coords, which are not at (0, 0). The indices of the vertices are not 0, and neither is null.

Update 2: Yup, the LeftVertex and RightVertex are always shown as [Vector2f]0,0 no matter what. Now that I've pinpointed what exactly I'm complaining about, I shouldn't have to update this another fifteen times 👍

Haha, I lied. Update 3: The regions in Voronoi.Regions() have the correct vertices, those can be rendered fine. I could manually build up a list of edges, which is what I may have to do anyway.

Final update, I think: Disabling smoothing doesn't change anything (except the relaxation doesn't happen anymore, big surprise)

My solution to this issue is to build my own edge list:

public struct Duple<T, K> {
	public T a;
	public K b;
	public Duple(T a, K b) {
		this.a = a;
		this.b = b;
	}
}

// -- SNIP -- //

public readonly List<Duple<Vector2f, Vector2f>> edges = new List<Duple<Vector2f, Vector2f>>();

// -- SNIP -- //

List<Vector2f> systems = GetSystems();	// Random points
Voronoi = new Voronoi(systems, bounds, systemSmoothing);
edges.Clear();
foreach (List<Vector2f> region in Voronoi.Regions()) {
	for (int i = 1; i < region.Count; i++) {
		edges.Add(new Duple<Vector2f, Vector2f>(region[i - 1], region[i]));
	}
}
@Dozed12
Copy link

Dozed12 commented May 13, 2019

Having the same problem you described, using the regions outputs the vertices just fine but the edges have coordinates (0,0). Unfortunately I also need to associate the edges coordinates and the sites they connect so can't build the list on my own.

@tingtom
Copy link

tingtom commented Jan 10, 2020

Looks like the vertices are added to a list in Voronoi.cs and then disposed of at the end causing them to zero out. See the last lines of the FortunesAlgorithm function.

@k-vekos
Copy link

k-vekos commented Mar 14, 2020

I'm also having this issue and can't rebuild the edges list from the region vertices...

@csm-stough
Copy link

csm-stough commented Dec 24, 2022

Thank you so much @k-vekos, I was pulling my hair out trying to figure out why all Vertices were (0, 0) :D

@SapphireStar
Copy link

Looks like the vertices are added to a list in Voronoi.cs and then disposed of at the end causing them to zero out. See the last lines of the FortunesAlgorithm function.
Thank you @tingtom! I removed the dispose method in FortunesAlgorithm function, and it actually works, you saved my project :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants