Spread of Layers

vl

#1

Hey,
I’m trying to draw several different polygons by creating a layer and adding these layers to a spread, but it doesn’t work and all the polygons look the same and are drawn over one another. Looks like all the items in the spread point to the same reference of the polygon.
When I do it differently by first creating a spread of data and then drawing all the polygons with a ForEach it works fine.
What is the difference and how can I force the polygon to create a new instance every time a layer is added to the spread?

Polygons.vl (34.9 KB)


#2

Like this?
PolyImage
Try this:
Polygons-polyyyy-Polys%20Galore
If you look back at your patch, although you were creating loads of polygons, you were feeding all of them the same data - the very newest spread of vertices, not the list of them.

The polygon that you created ‘mutates’ with the new data, it doesn’t stay ‘static.’ So you needed a different set of data for it to refer to for each polygon you created. I think. Just guessing really.


#3

Thank you for your answer.

The result is correct and I already had the solution for it by drawing it within a for loop.

The question is only why the forEach region seems to create new instances of the polygon everytime executed and the if region does not.
And the question is if you can manually force the polygon to create a new instance like calling the create operation.

I stepped back to an older, more comparable version of my code for the screenshot, where you can see the two different approaches. The one on the left is not working as exspected and the one on the right works fine.

DrawingPolygons.vl (57.4 KB)


#4

Indeed, I realized that a bit late, though my answer, that the layer is referencing the value, is probably the correct answer.

The data input for the Polygon is ‘mutable,’ and therefore isn’t copied and held inside each polygon object. If it were, you’d get exactly what you’re expecting, but instead, the polygon copies a ‘reference’ to that data, like a hyperlink to that data.

The output ForEachLoop, with that single Spread of Vectors, is that data source. If the data at the source (like the content of a website) changes, you see something new. So all of your Polygon nodes are looking only at that reference pin, reading from it and applying it many times over.

This suggests that a layer is probably a class. A class describes an object but works by making these references to data its fed. Something like a record on the other hand actually keeps all of its data when its instantiated. Your vectors that make the polygon shape are more like (perhaps are) records.

I’m sure one of the vvvv team could give you a more succinct description.


#5

also, there is a reason why some links are dashed and others not. as you can see, dashed links only transfer a reference (address, hyperlink or whatever you want to call it) to something, not the data, as compared to solid links.


#6

Thanks for the explanations above.

As a workaround to create a new polygon every time the if region is true, you can create a new class with the process node polygon within and call the create function in the if region. Thanks to @tonfilm for the hint.

image