Skip to content

Commit

Permalink
squash many windows warnings [possibly introducing bugs along the way].
Browse files Browse the repository at this point in the history
  • Loading branch information
ixchow committed Oct 28, 2023
1 parent 5d4d01e commit ff61f3a
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 150 deletions.
51 changes: 26 additions & 25 deletions EmbeddedPlanarMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ struct EmbeddedPlanarMap {
IntegerEmbeddedVertex v = IntegerEmbeddedVertex::simplify(v_);

auto &verts = simplex_vertices[v.simplex];
auto &edges = simplex_edges[v.simplex];
auto &sedges = simplex_edges[v.simplex];

for (auto i : verts) {
if (vertices[i] == v) return i;
Expand All @@ -245,14 +245,14 @@ struct EmbeddedPlanarMap {
vertices.emplace_back(v);
verts.emplace_back(idx);

uint32_t old_size = edges.size();
uint32_t old_size = sedges.size();

for (uint32_t e = 0; e < old_size; ++e) {
if (point_in_segment(v, vertices[edges[e].first], vertices[edges[e].second])) {
auto second_half = edges[e];
if (point_in_segment(v, vertices[sedges[e].first], vertices[sedges[e].second])) {
auto second_half = sedges[e];
second_half.first = idx;
edges[e].second = idx;
edges.emplace_back(second_half);
sedges[e].second = idx;
sedges.emplace_back(second_half);
}
}
return idx;
Expand Down Expand Up @@ -285,39 +285,39 @@ struct EmbeddedPlanarMap {
}

//split edge (and add new vertex) if there is an intersection:
auto &edges = simplex_edges[common];
for (uint32_t e = 0; e < edges.size(); ++e) {
auto &sedges = simplex_edges[common];
for (uint32_t e = 0; e < sedges.size(); ++e) {

//if it matches the edge, over-write value & done!
if (edges[e].first == ai && edges[e].second == bi) {
combine_values(&edges[e].value, value);
if (sedges[e].first == ai && sedges[e].second == bi) {
combine_values(&sedges[e].value, value);
return;
}
if (edges[e].first == bi && edges[e].second == ai) {
if (sedges[e].first == bi && sedges[e].second == ai) {
VALUE temp = value;
reverse_value(&temp);
combine_values(&edges[e].value, temp);
combine_values(&sedges[e].value, temp);
return;
}

glm::ivec2 a2 = glm::ivec2(vertices[edges[e].first].weights_on(common));
glm::ivec2 b2 = glm::ivec2(vertices[edges[e].second].weights_on(common));
glm::ivec2 a2 = glm::ivec2(vertices[sedges[e].first].weights_on(common));
glm::ivec2 b2 = glm::ivec2(vertices[sedges[e].second].weights_on(common));

//if endpoints are interior to an existing edge, split existing edge:
if (point_in_segment(a, a2, b2)) {
assert(false); //THIS SHOULD NEVER HAPPEN (should have been avoided by vertex insertion?)
auto second_half = edges[e];
auto second_half = sedges[e];
second_half.first = ai;
edges.emplace_back(second_half);
edges[e].second = ai;
sedges.emplace_back(second_half);
sedges[e].second = ai;
b2 = a;
}
if (point_in_segment(b, a2, b2)) {
assert(false); //THIS SHOULD NEVER HAPPEN (should have been avoided by vertex insertion?)
auto second_half = edges[e];
auto second_half = sedges[e];
second_half.first = bi;
edges.emplace_back(second_half);
edges[e].second = bi;
sedges.emplace_back(second_half);
sedges[e].second = bi;
b2 = b;
}

Expand All @@ -327,10 +327,10 @@ struct EmbeddedPlanarMap {
pt.z = WEIGHT_SUM - pt.x - pt.y;
uint32_t pti = add_vertex(IntegerEmbeddedVertex(common, pt));

float ai2 = edges[e].first;
float bi2 = edges[e].second;
VALUE value2 = edges[e].value;
edges.erase(edges.begin() + e);
float ai2 = sedges[e].first;
float bi2 = sedges[e].second;
VALUE value2 = sedges[e].value;
sedges.erase(sedges.begin() + e);

VALUE value2_first, value2_second;
split_value(value2, &value2_first, &value2_second);
Expand All @@ -348,7 +348,7 @@ struct EmbeddedPlanarMap {
}

//if got to this point, no intersections:
edges.emplace_back(ai, bi, value);
sedges.emplace_back(ai, bi, value);
}
void add_edge(const ak::EmbeddedVertex &a, const ak::EmbeddedVertex &b, VALUE const &value) {
uint32_t ai = add_vertex(a);
Expand Down Expand Up @@ -546,6 +546,7 @@ struct EmbeddedPlanarMap {
quad = 3;
} else {
assert(false);
quad = 0; //"potentially unused local variable" warning on cl.exe
}

//std::cout << " " << ri->first << " -> " << ri->second << " quad " << quad << " y/x " << d.y << "/" << d.x << std::endl; //DEBUG
Expand Down
9 changes: 7 additions & 2 deletions Maekfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ if (maek.OS === "windows") {
`/wd4297`, //unfortunately SDLmain is nothrow
`/wd4100`, //unreferenced formal parameter
`/wd4201`, //nameless struct/union
`/wd4611` //interaction between setjmp and C++ object destruction
`/wd4611`, //interaction between setjmp and C++ object destruction
`/wd4127`, //"consider using if constexpr"
`/wd4244`, //integer width change -- NOTE: should consider fixing these
`/wd4267`, //integer width change (size_t -> uint32_t) -- NOTE: should probably actually fix these
);
maek.options.LINKLibs.push(
`/LIBPATH:${NEST_LIBS}/SDL2/lib`, `SDL2main.lib`, `SDL2.lib`, `OpenGL32.lib`, `Shell32.lib`,
Expand Down Expand Up @@ -152,7 +155,9 @@ const interpolate_values_CPPFlags = [...maek.options.CPPFlags];
if (maek.OS === "macos") {
interpolate_values_CPPFlags.push('-I/usr/local/include/eigen3');
} else if (maek.OS === "windows") {
interpolate_values_CPPFlags.push('/Ieigen', '/D_SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING');
interpolate_values_CPPFlags.push('/Ieigen', '/D_SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING',
`/wd4459` //local definition hides global
);
} else {
interpolate_values_CPPFlags.push('-I/usr/include/eigen3');
}
Expand Down
12 changes: 6 additions & 6 deletions Shape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ struct Shape {
auto &back = *back_;

//figure out how many items go on the back and how many on the front:
uint32_t width = data.size()
uint32_t width = uint32_t(data.size())
+ ((nibbles & BackLeft) ? 1 : 0)
+ ((nibbles & FrontLeft) ? 1 : 0)
+ ((nibbles & BackRight) ? 1 : 0)
Expand Down Expand Up @@ -257,11 +257,11 @@ struct Shape {
} else if (count % 2 == 0) {
ret.reserve(5 * count);
for (uint32_t i = 0; i < count; ++i) {
ret.emplace_back(i, 0);
ret.emplace_back(i, BackLeft | BackRight);
ret.emplace_back(i, BackLeft | FrontRight);
ret.emplace_back(i, FrontLeft | BackRight);
ret.emplace_back(i, FrontLeft | FrontRight);
ret.emplace_back(i, uint8_t(0));
ret.emplace_back(i, uint8_t(BackLeft | BackRight));
ret.emplace_back(i, uint8_t(BackLeft | FrontRight));
ret.emplace_back(i, uint8_t(FrontLeft | BackRight));
ret.emplace_back(i, uint8_t(FrontLeft | FrontRight));
}
assert(ret.size() == count * 5);
} else {
Expand Down
33 changes: 17 additions & 16 deletions ak-link_chains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ void ak::link_chains(
old_back += pad(std::to_string(segments[0]->stitches.size()));
old_front += pad("");
for (uint32_t i = 1; i < segments.size()/2; ++i) {
uint32_t io = segments.size()-i;
uint32_t io = uint32_t(segments.size())-i;
assert(segments[i]->next == segments[io]->next);
old_back += pad(std::to_string(segments[i]->stitches.size()));
old_front += pad(std::to_string(segments[io]->stitches.size()));
Expand All @@ -686,10 +686,10 @@ void ak::link_chains(
}

//now push extra stitches from the center outward:
uint32_t m = (segments.size()/2)/2; //so a b c b -> m = 1 ; a b c d e d c b -> m = 2;
assert(0 < m && m < segments.size()/2);
uint32_t m = (uint32_t(segments.size())/2)/2; //so a b c b -> m = 1 ; a b c d e d c b -> m = 2;
assert(0 < m && m < uint32_t(segments.size())/2);
{ //push from the middle segment outward (alternating sides):
uint32_t mo = segments.size()-m;
uint32_t mo = uint32_t(segments.size())-m;
assert(segments.size()/2 < mo && mo < segments.size());
uint32_t mo_p = mo-1; assert(mo_p < segments.size());
uint32_t mo_n = (mo+1 < segments.size() ? mo+1 : 0); assert(mo_n < segments.size());
Expand Down Expand Up @@ -717,7 +717,7 @@ void ak::link_chains(
}
//push from left-side segments leftward:
for (uint32_t l = m-1; l > 0; --l) {
uint32_t lo = segments.size()-l;
uint32_t lo = uint32_t(segments.size())-l;
uint32_t lo_n = (lo+1 < segments.size() ? lo+1 : 0); assert(lo_n < segments.size());
assert(segments[lo]->next == segments[l]->next);
while (segments[l]->stitches.size() > segments[lo]->stitches.size()) {
Expand All @@ -731,7 +731,7 @@ void ak::link_chains(
}
//push from right-side segments leftward:
for (uint32_t r = m+1; r < segments.size()/2; ++r) {
uint32_t ro = segments.size()-r;
uint32_t ro = uint32_t(segments.size())-r;
uint32_t ro_p = ro-1; assert(ro_p < segments.size());
assert(segments[ro]->next == segments[r]->next);
while (segments[r]->stitches.size() > segments[ro]->stitches.size()) {
Expand All @@ -746,7 +746,7 @@ void ak::link_chains(

//check for balance:
for (uint32_t i = 1; i < segments.size()/2; ++i) {
uint32_t io = segments.size()-i;
uint32_t io = uint32_t(segments.size())-i;
assert(segments[i]->stitches.size() == segments[io]->stitches.size());
}

Expand All @@ -756,7 +756,7 @@ void ak::link_chains(
new_back += pad(std::to_string(segments[0]->stitches.size()));
new_front += pad("");
for (uint32_t i = 1; i < segments.size()/2; ++i) {
uint32_t io = segments.size()-i;
uint32_t io = uint32_t(segments.size())-i;
assert(segments[i]->next == segments[io]->next);
new_back += pad(std::to_string(segments[i]->stitches.size()));
new_front += pad(std::to_string(segments[io]->stitches.size()));
Expand Down Expand Up @@ -1108,7 +1108,7 @@ void ak::link_chains(
old_back += pad(std::to_string(segments[0]->stitches));
old_front += pad("");
for (uint32_t i = 1; i < segments.size()/2; ++i) {
uint32_t io = segments.size()-i;
uint32_t io = uint32_t(segments.size())-i;
assert(segments[i]->active == segments[io]->active);
old_back += pad(std::to_string(segments[i]->stitches));
old_front += pad(std::to_string(segments[io]->stitches));
Expand All @@ -1121,7 +1121,7 @@ void ak::link_chains(
uint32_t sum = 0;
uint32_t sumo = 0;
for (uint32_t i = 1; i < segments.size()/2; ++i) {
uint32_t io = segments.size()-i;
uint32_t io = uint32_t(segments.size())-i;
assert(segments[i]->active == segments[io]->active);
uint32_t total = segments[i]->stitches + segments[io]->stitches;
segments[i]->stitches = total / 2;
Expand All @@ -1136,7 +1136,7 @@ void ak::link_chains(
//REMEMBER: as per Appendix A, this algorithm isn't perfect (can fail in very large merge/split chains).

//Now delete the existing stitches for this chain and re-allocate!
uint32_t old_count = next_stitches[ni].size();
uint32_t old_count = uint32_t(next_stitches[ni].size());

next_stitches[ni].clear();
for (auto seg : segments) {
Expand Down Expand Up @@ -1164,7 +1164,7 @@ void ak::link_chains(
new_back += pad(std::to_string(segments[0]->stitches));
new_front += pad("");
for (uint32_t i = 1; i < segments.size()/2; ++i) {
uint32_t io = segments.size()-i;
uint32_t io = uint32_t(segments.size())-i;
assert(segments[i]->active == segments[io]->active);
new_back += pad(std::to_string(segments[i]->stitches));
new_front += pad(std::to_string(segments[io]->stitches));
Expand Down Expand Up @@ -1591,7 +1591,7 @@ bool fill_unassigned(std::vector< uint32_t > &closest, std::vector< float > cons
if (closest[seed] != -1U) continue;
uint32_t first = seed;
while ((first > 0 || is_loop) && closest[first > 0 ? first - 1 : closest.size()-1] == -1U) {
first = (first > 0 ? first - 1 : closest.size()-1);
first = (first > 0 ? first - 1 : uint32_t(closest.size())-1);
}
uint32_t last = seed;
while ((last + 1 < closest.size() || is_loop) && closest[last + 1 < closest.size() ? last + 1 : 0] == -1U) {
Expand Down Expand Up @@ -1650,7 +1650,7 @@ void flatten(std::vector< uint32_t > &closest, std::vector< float > const &weigh
bit_symbols.emplace_back(ret.first->second, sw.second);
}
assert(bit_symbols.size() == symbols.size());
bits = symbol_bit.size();
bits = uint32_t(symbol_bit.size());
}

struct State {
Expand Down Expand Up @@ -1732,13 +1732,14 @@ void flatten(std::vector< uint32_t > &closest, std::vector< float > const &weigh
auto const max = state.max;
auto const current = state.current;
assert(state.padding == 0);
assert(bit_symbols.size() < 256);

//*_next_symbol is the symbol that is advanced over when moving min/max,
// leading to some asymmetry in indexing:
// a(bc)d -> (abc)d <-- min_next_symbol is 'a' (at index of min_next)
// a(bc)d -> a(bcd) <-- max_next_symbol is 'd' (at index of max)

auto min_next = (min == 0 ? bit_symbols.size() - 1 : min - 1);
auto min_next = (min == 0 ? uint8_t(bit_symbols.size()) - 1 : min - 1);
auto min_next_symbol = bit_symbols[min_next];
auto max_next = (max + 1U < bit_symbols.size() ? max + 1 : 0);
auto max_next_symbol = bit_symbols[max];
Expand Down Expand Up @@ -1972,7 +1973,7 @@ void flatten(std::vector< uint32_t > &closest, std::vector< float > const &weigh
if (!relabel[seed]) continue;
uint32_t first = seed;
while (relabel[first > 0 ? first - 1 : closest.size()-1]) {
first = (first > 0 ? first - 1 : closest.size()-1);
first = (first > 0 ? first - 1 : uint32_t(closest.size())-1);
}
uint32_t last = seed;
while (relabel[last + 1 < closest.size() ? last + 1 : 0]) {
Expand Down
16 changes: 8 additions & 8 deletions ak-optimal_link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ void ak::optimal_link(
State s;
s.source_idx = 0;
s.target_idx = t;
s.source_remain = source.size();
s.target_remain = target.size();
s.source_remain = uint32_t(source.size());
s.target_remain = uint32_t(target.size());
visit(s.pack(), 0.0f, Action());

s.source_idx = 1;
Expand All @@ -77,8 +77,8 @@ void ak::optimal_link(
State s;
s.source_idx = 0;
s.target_idx = 0;
s.source_remain = source.size();
s.target_remain = target.size();
s.source_remain = uint32_t(source.size());
s.target_remain = uint32_t(target.size());
visit(s.pack(), 0.0f, Action());
}

Expand Down Expand Up @@ -166,20 +166,20 @@ void ak::optimal_link(
Action action = f->second.second;
if (action.take_source == 0 && action.take_target == 0) break;
if (action.take_source == 1) {
at.source_idx = (at.source_idx + source.size() - 1) % source.size();
at.source_idx = (at.source_idx + uint32_t(source.size()) - 1) % uint32_t(source.size());
at.source_remain += 1;
while (action.take_target > 0) {
--action.take_target;
at.target_idx = (at.target_idx + target.size() - 1) % target.size();
at.target_idx = (at.target_idx + uint32_t(target.size()) - 1) % uint32_t(target.size());
at.target_remain += 1;
links.emplace_back(at.source_idx, at.target_idx);
}
} else if (action.take_target == 1) {
at.target_idx = (at.target_idx + target.size() - 1) % target.size();
at.target_idx = (at.target_idx + uint32_t(target.size()) - 1) % uint32_t(target.size());
at.target_remain += 1;
while (action.take_source > 0) {
--action.take_source;
at.source_idx = (at.source_idx + source.size() - 1) % source.size();
at.source_idx = (at.source_idx + uint32_t(source.size()) - 1) % uint32_t(source.size());
at.source_remain += 1;
links.emplace_back(at.source_idx, at.target_idx);
}
Expand Down
Loading

0 comments on commit ff61f3a

Please sign in to comment.