Actually v_gen2 can be written differently to retain the same API as
v_generator:
def v_gen2(v):
for ch in v.children:
yield ch
yield from v_gen2(ch)
On Monday, August 14, 2023 at 7:48:11 AM UTC+2 vitalije wrote:
> Happy birthday to you Edward. But putting birthday aside, I can't resist
> to comment on some parts of your post.
>
>
> On Sunday, August 13, 2023 at 11:31:16 AM UTC+2 Edward K. Ream wrote:
>
> Today is my 74th birthday. This Engineering Notebook post is my birthday
> present to myself.
>
> - We can't use VNode generators because they don't yield VNodes in outline
> order.
>
>
>
> I really don't know where did you get this idea from? Have you test it?
> For me they always give me the nodes in the outline order. Maybe we don't
> use the same generator? Here is mine:
>
> def v_generator(v):
> yield v
> for ch in v.children:
> yield from v_generator(ch)
>
> a = ('hidden-root-vnode-gnx',) + tuple(p.gnx for p in c.all_positions())
> b = tuple(v.gnx for v in v_generator(c.hiddenRootNode))
>
> assert a == b
>
> # of coarse you can avoid yielding root vnode with
> # a slightly different generator
>
> def v_gen2(vs):
> for ch in vs:
> yield ch
> yield from v_gen2(ch.children)
>
> # and it can be used like this
>
> a = tuple(p.gnx for p in c.all_positions())
> b = tuple(v.gnx for v in v_gen2(c.hiddenRootNode.children))
> assert a == b
> g.es('ok')
>
> The parents attribute is never used in this generators so it is completely
> free to be modified by the scripts. The information about outline order is
> fully contained in the v.children attributes. The v.parents attribute is
> necessary only if you want to continue traversal in outline order from any
> given point.
>
> Vitalije
>
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/leo-editor/c31ce713-2ee4-432d-8ef1-09184f156e78n%40googlegroups.com.