Restructure openscad-0001 (was in wrong dir, Java test) into proper openscad-0001/ with TICKET.md and Python test. New openscad-0002 patches PolySetBuilder::endPolygon + appendPolySet std::find on colors_ vector -> unordered_map; Color4f already has std::hash. New openscad-0003 patches OctoPrint::requestApiKey and getJsonData to stop logging API responses verbatim (app_token + api responses exposed under --debug). MOADs 0002/0003/0005 CLEAN.
60 lines
2.1 KiB
Diff
60 lines
2.1 KiB
Diff
--- a/src/geometry/PolySetBuilder.h
|
|
+++ b/src/geometry/PolySetBuilder.h
|
|
@@ -3,6 +3,7 @@
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <vector>
|
|
+#include <unordered_map>
|
|
|
|
#include "geometry/Geometry.h"
|
|
#include "geometry/GeometryUtils.h"
|
|
@@ -48,6 +49,7 @@ private:
|
|
PolygonIndices indices_;
|
|
std::vector<int32_t> color_indices_;
|
|
std::vector<Color4f> colors_;
|
|
+ std::unordered_map<Color4f, size_t> color_index_;
|
|
int convexity_{1};
|
|
int dim_;
|
|
boost::tribool convex_;
|
|
--- a/src/geometry/PolySetBuilder.cc
|
|
+++ b/src/geometry/PolySetBuilder.cc
|
|
@@ -161,13 +161,14 @@ void PolySetBuilder::endPolygon(const Color4f& color)
|
|
if (color.isValid()) {
|
|
if (color_indices_.empty() && indices_.size() > 1) {
|
|
color_indices_.resize(indices_.size() - 1, -1);
|
|
}
|
|
- auto it = std::find(colors_.begin(), colors_.end(), color);
|
|
- if (it == colors_.end()) {
|
|
- color_indices_.push_back(colors_.size());
|
|
+ auto it = color_index_.find(color);
|
|
+ if (it == color_index_.end()) {
|
|
+ size_t idx = colors_.size();
|
|
+ color_index_[color] = idx;
|
|
+ color_indices_.push_back(idx);
|
|
colors_.push_back(color);
|
|
} else {
|
|
- color_indices_.push_back(it - colors_.begin());
|
|
+ color_indices_.push_back(it->second);
|
|
}
|
|
}
|
|
}
|
|
@@ -185,12 +186,14 @@ void PolySetBuilder::appendPolySet(const PolySet& ps)
|
|
std::vector<uint32_t> color_map(nColors);
|
|
for (size_t i = 0; i < nColors; i++) {
|
|
const auto& color = ps.colors[i];
|
|
- // Find index of color in colors_, or add it if it doesn't exist
|
|
- auto it = std::find(colors_.begin(), colors_.end(), color);
|
|
- if (it == colors_.end()) {
|
|
- color_map[i] = colors_.size();
|
|
+ // Find index of color in color_index_, or add it if it doesn't exist
|
|
+ auto it = color_index_.find(color);
|
|
+ if (it == color_index_.end()) {
|
|
+ size_t idx = colors_.size();
|
|
+ color_map[i] = idx;
|
|
+ color_index_[color] = idx;
|
|
colors_.push_back(color);
|
|
} else {
|
|
- color_map[i] = it - colors_.begin();
|
|
+ color_map[i] = it->second;
|
|
}
|
|
}
|