diff --git a/copying.md b/copying.md index cf5ff6fed7..b0961cbae0 100644 --- a/copying.md +++ b/copying.md @@ -175,6 +175,7 @@ _the openage authors_ are: | Deniz Kökden | denizkoekden | koekdendeniz à gmail dawt com | | Sergey Bronnikov | ligurio | estetus à gmail dawt com | | Nicolas Inostroza | JotaJazz | 181486793+jotajazz à users dawt noreply dawt github dawt com | +| Rene Turcios | CloudCorpRecords | 95189389+cloudcorprecords à users dawt noreply dawt github dawt com | If you're a first-time committer, add yourself to the above list. This is not just for legal reasons, but also to keep an overview of all those nicknames. diff --git a/libopenage/curve/keyframe_container.h b/libopenage/curve/keyframe_container.h index 8434942058..34f0d4c06d 100644 --- a/libopenage/curve/keyframe_container.h +++ b/libopenage/curve/keyframe_container.h @@ -399,14 +399,14 @@ KeyframeContainer::last_before(const time::time_t &time, const elem_ptr end = this->container.size(); if (at != end and this->container.at(at).time() < time) { - // walk to the right until the time is larget than the searched - while (at != end and this->container.at(at).time() <= time) { + // walk to the right until the time is at least the searched one + while (at != end and this->container.at(at).time() < time) { ++at; } - // go one back, because we want the last element that is <= time + // go one back, because we want the last element that is < time --at; } - else { // idx == end or idx->time > time + else { // idx == end or idx->time >= time // walk to the left until the element time is smaller than the searched time while (at > 0 and (at == end or this->container.at(at).time() >= time)) { --at; diff --git a/libopenage/curve/tests/curve_types.cpp b/libopenage/curve/tests/curve_types.cpp index 935aa7141d..ccf0d81836 100644 --- a/libopenage/curve/tests/curve_types.cpp +++ b/libopenage/curve/tests/curve_types.cpp @@ -84,6 +84,37 @@ void curve_types() { TESTEQUALS(c.get(c.last(10, ie)).val(), 2); TESTEQUALS(c.get(c.last(47, ie)).val(), 2); + // last_before() must not depend on the hint + TESTEQUALS(c.get(c.last_before(0, ib)).time(), time::TIME_MIN); + TESTEQUALS(c.get(c.last_before(1, ib)).time(), 0); + TESTEQUALS(c.get(c.last_before(5, ib)).time(), 1); + TESTEQUALS(c.get(c.last_before(10, ib)).time(), 1); + TESTEQUALS(c.get(c.last_before(47, ib)).time(), 10); + + TESTEQUALS(c.get(c.last_before(0, p0)).time(), time::TIME_MIN); + TESTEQUALS(c.get(c.last_before(1, p0)).time(), 0); + TESTEQUALS(c.get(c.last_before(5, p0)).time(), 1); + TESTEQUALS(c.get(c.last_before(10, p0)).time(), 1); + TESTEQUALS(c.get(c.last_before(47, p0)).time(), 10); + + TESTEQUALS(c.get(c.last_before(0, p1)).time(), time::TIME_MIN); + TESTEQUALS(c.get(c.last_before(1, p1)).time(), 0); + TESTEQUALS(c.get(c.last_before(5, p1)).time(), 1); + TESTEQUALS(c.get(c.last_before(10, p1)).time(), 1); + TESTEQUALS(c.get(c.last_before(47, p1)).time(), 10); + + TESTEQUALS(c.get(c.last_before(0, p2)).time(), time::TIME_MIN); + TESTEQUALS(c.get(c.last_before(1, p2)).time(), 0); + TESTEQUALS(c.get(c.last_before(5, p2)).time(), 1); + TESTEQUALS(c.get(c.last_before(10, p2)).time(), 1); + TESTEQUALS(c.get(c.last_before(47, p2)).time(), 10); + + TESTEQUALS(c.get(c.last_before(0, ie)).time(), time::TIME_MIN); + TESTEQUALS(c.get(c.last_before(1, ie)).time(), 0); + TESTEQUALS(c.get(c.last_before(5, ie)).time(), 1); + TESTEQUALS(c.get(c.last_before(10, ie)).time(), 1); + TESTEQUALS(c.get(c.last_before(47, ie)).time(), 10); + // Now test the basic erase() function // Delete the 1-element, new values should be [-inf:0, 0:0, 10:2] c.erase(c.last(1)); @@ -165,6 +196,12 @@ void curve_types() { TESTEQUALS(it->val(), 25); } + // the last of several keyframes before the time, from both sides + TESTEQUALS(c.get(c.last_before(1, 1)).val(), 12); + TESTEQUALS(c.get(c.last_before(1, c.size())).val(), 12); + TESTEQUALS(c.get(c.last_before(2, 1)).val(), 15); + TESTEQUALS(c.get(c.last_before(2, c.size())).val(), 15); + // TODO: test c.insert_overwrite and c.insert_after KeyframeContainer c2; diff --git a/openage/util/ordered_set.py b/openage/util/ordered_set.py index 8b012cf799..bff8e3888d 100644 --- a/openage/util/ordered_set.py +++ b/openage/util/ordered_set.py @@ -84,12 +84,16 @@ def intersection_update(self, other): """ Only keep elements that are both in self and other. """ - keys_self = set(self.ordered_set.keys()) - keys_other = set(other.keys()) - intersection = keys_self & keys_other - - for elem in self: - if elem not in intersection: + match other: + case OrderedSet(): + other_set = set(other.ordered_set.keys()) + case dict(): + other_set = set(other.keys()) + case _: + other_set = set(other) + + for elem in list(self.ordered_set.keys()): + if elem not in other_set: self.discard(elem) def union(self, other):