heitzmann / gdstk

Gdstk (GDSII Tool Kit) is a C++/Python library for creation and manipulation of GDSII and OASIS files.
https://heitzmann.github.io/gdstk/
Boost Software License 1.0
324 stars 78 forks source link

oasis.cpp / oasis_write_repetition function - typo? #227

Closed philstopford closed 6 months ago

philstopford commented 6 months ago

I'm picking through this code to learn more about OASIS and the below in the repetition writing code looks wrong to my eye:


        case RepetitionType::Explicit:
            if (repetition.offsets.count > 0) {
                oasis_putc(10, out);
                oasis_write_unsigned_integer(out, repetition.offsets.count - 1);
                Vec2* v0 = repetition.offsets.items;
                Vec2* v1 = v0 + 1;
                oasis_write_gdelta(out, (int64_t)llround(v0->x * scaling),
                                   (int64_t)llround(v0->y * scaling));
                for (uint64_t i = repetition.coords.count - 1; i > 0; --i, ++v0, ++v1) {
                    oasis_write_gdelta(out, (int64_t)llround((v1->x - v0->x) * scaling),
                                       (int64_t)llround((v1->y - v0->y) * scaling));
                }
            }
            break;

We're writing repetition.offsets, but this loop seems to be based on repetition.coords.count. Is this a misunderstanding on my side, or a typo?

heitzmann commented 6 months ago

That's correct. coords and offsets are part of an union in the repetition structure. Explicit types use the offset member, not coords.