Skip to content

Commit

Permalink
wow it actually kinda works
Browse files Browse the repository at this point in the history
  • Loading branch information
Tynan Richards committed Aug 8, 2024
1 parent fffdd8d commit 77f77cc
Show file tree
Hide file tree
Showing 4 changed files with 1,600 additions and 114 deletions.
92 changes: 92 additions & 0 deletions desktop_version/src/solver/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ namespace Geometry {
max = SDL_min(max, other.max);
return regularize();
}
IntInterval& IntInterval::difference(const IntInterval& other) {
if (!is_bottom()) {
if (other.contains(min)) {
min = saturatingAdd(other.max, 1);
}
if (other.contains(max)) {
max = saturatingSub(other.min, 1);
}
}
return regularize();
}

bool IntInterval::contains(int val) const {
return val >= min && val <= max;
Expand All @@ -29,6 +40,34 @@ namespace Geometry {
return other.min >= min && other.max <= max;
}

IntInterval IntInterval::pos_div(const IntInterval& a, const IntInterval& b) {
IntInterval t = IntInterval::positive();

IntInterval pos_a = IntInterval::positive();
IntInterval neg_a = IntInterval::negative();

IntInterval pos_b = IntInterval::positive();
IntInterval neg_b = IntInterval::negative();

pos_a.intersect(a);
neg_a.intersect(a);
neg_a.negate();

pos_b.intersect(b);
neg_b.intersect(b);
neg_b.negate();

IntInterval pos_quotient = IntInterval::positive();
pos_quotient.addUpperBound(saturatingDiv(pos_a.max, pos_b.min));
pos_quotient.addLowerBound(saturatingDiv(pos_a.min, pos_b.max));

IntInterval neg_quotient = IntInterval::positive();
neg_quotient.addUpperBound(saturatingDiv(neg_a.max, neg_b.min));
neg_quotient.addLowerBound(saturatingDiv(neg_a.min, neg_b.max));

return IntInterval::join(pos_quotient, neg_quotient);
}

Region Region::join(const Region& a, const Region& b) {
IntInterval x_interval = IntInterval::join(a.x, b.x);
IntInterval y_interval = IntInterval::join(a.y, b.y);
Expand All @@ -39,6 +78,17 @@ namespace Geometry {
IntInterval y_interval = IntInterval::intersect(a.y, b.y);
return Region(x_interval, y_interval);
}
Region& Region::difference(const Region& other) {
if (!is_bottom()) {
if (other.y.contains(y)) {
x.difference(other.x);
}
if (other.x.contains(x)) {
y.difference(other.y);
}
}
return regularize();
}

bool Region::contains(const Region& other) const {
return x.contains(other.x) && y.contains(other.y);
Expand All @@ -61,4 +111,46 @@ namespace Geometry {
return regularize();
}


FloatInterval FloatInterval::join(const FloatInterval& a, const FloatInterval& b) {
if (b.is_bottom()) {
return FloatInterval(a);
} else if (a.is_bottom()) {
return FloatInterval(b);
}

int min = SDL_min(a.min, b.min);
int max = SDL_max(a.max, b.max);
return FloatInterval(min, max);
}
FloatInterval FloatInterval::intersect(const FloatInterval& a, const FloatInterval& b) {
if (a.is_bottom() || b.is_bottom()) {
return FloatInterval::bottom();
}

int min = SDL_max(a.min, b.min);
int max = SDL_min(a.max, b.max);
return FloatInterval(min, max);
}
FloatInterval& FloatInterval::join(const FloatInterval& other) {
if (!other.is_bottom()) {
if (is_bottom()) {
min = other.min;
max = other.max;
} else {
min = SDL_min(min, other.min);
max = SDL_max(max, other.max);
}
}
return regularize();
}
FloatInterval& FloatInterval::intersect(const FloatInterval& other) {
if (is_bottom() || other.is_bottom()) {
make_bottom();
} else {
min = SDL_max(min, other.min);
max = SDL_min(max, other.max);
}
return regularize();
}
}
Loading

0 comments on commit 77f77cc

Please sign in to comment.