Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions copying.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions libopenage/curve/keyframe_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,14 +399,14 @@ KeyframeContainer<T>::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;
Expand Down
37 changes: 37 additions & 0 deletions libopenage/curve/tests/curve_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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<int> c2;
Expand Down
16 changes: 10 additions & 6 deletions openage/util/ordered_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading