| 1 | Add a build system for the C++ library and fix missing standard library
|
| 2 | includes. Upstream does not provide a build system for its C++
|
| 3 | implementation.
|
| 4 |
|
| 5 | diff --git a/Makefile b/Makefile
|
| 6 | new file mode 100644
|
| 7 | index 0000000..325bf0b
|
| 8 | |
| 9 | |
| 10 | @@ -0,0 +1,23 @@
|
| 11 | +CXXFLAGS += -std=c++17 -fPIC
|
| 12 | +CPPFLAGS += -I. $(shell pkg-config --cflags absl_flat_hash_map absl_strings gmock_main)
|
| 13 | +ABSL_LIBS = $(shell pkg-config --libs absl_flat_hash_map absl_strings)
|
| 14 | +TEST_LIBS = $(shell pkg-config --libs gmock_main)
|
| 15 | +SOURCES = $(filter-out %_test.cc,$(wildcard cpp/*/*.cc))
|
| 16 | +OBJECTS = $(SOURCES:.cc=.o)
|
| 17 | +TEST_OBJECTS = $(patsubst %.cc,%.o,$(wildcard cpp/*/*_test.cc))
|
| 18 | +LIBRARY = libmaterial-color-utilities.so
|
| 19 | +
|
| 20 | +all: $(LIBRARY)
|
| 21 | +
|
| 22 | +$(LIBRARY): $(OBJECTS)
|
| 23 | + $(CXX) -shared $(LDFLAGS) -Wl,-soname,$@ -o $@ $^ $(ABSL_LIBS)
|
| 24 | +
|
| 25 | +material-color-utilities-tests: $(TEST_OBJECTS) $(LIBRARY)
|
| 26 | + $(CXX) $(LDFLAGS) -o $@ $(TEST_OBJECTS) -L. -lmaterial-color-utilities $(TEST_LIBS)
|
| 27 | +
|
| 28 | +check: material-color-utilities-tests
|
| 29 | + LD_LIBRARY_PATH=. ./material-color-utilities-tests
|
| 30 | +
|
| 31 | +install: $(LIBRARY)
|
| 32 | + install -Dm755 $(LIBRARY) $(PREFIX)/lib/$(LIBRARY)
|
| 33 | + find cpp -name '*.h' -exec install -Dm644 {} $(PREFIX)/include/{} \;
|
| 34 | diff --git a/cpp/temperature/temperature_cache.cc b/cpp/temperature/temperature_cache.cc
|
| 35 | index 4fec3a2..8af11e6 100644
|
| 36 | |
| 37 | |
| 38 | @@ -17,6 +17,7 @@
|
| 39 | #include "cpp/temperature/temperature_cache.h"
|
| 40 |
|
| 41 | #include <algorithm>
|
| 42 | +#include <cmath>
|
| 43 | #include <map>
|
| 44 | #include <vector>
|
| 45 |
|
| 46 | @@ -60,7 +61,7 @@ Hct TemperatureCache::GetComplement() {
|
| 47 | Hct possible_answer = GetHctsByHue().at((int)round(hue));
|
| 48 | double relative_temp =
|
| 49 | (GetTempsByHct().at(possible_answer) - coldest_temp) / range;
|
| 50 | - double error = abs(complement_relative_temp - relative_temp);
|
| 51 | + double error = std::abs(complement_relative_temp - relative_temp);
|
| 52 | if (error < smallest_error) {
|
| 53 | smallest_error = error;
|
| 54 | answer = possible_answer;
|
| 55 | @@ -89,7 +90,7 @@ std::vector<Hct> TemperatureCache::GetAnalogousColors(int count,
|
| 56 | int hue = SanitizeDegreesInt(start_hue + i);
|
| 57 | Hct hct = GetHctsByHue().at(hue);
|
| 58 | double temp = GetRelativeTemperature(hct);
|
| 59 | - double temp_delta = abs(temp - last_temp);
|
| 60 | + double temp_delta = std::abs(temp - last_temp);
|
| 61 | last_temp = temp;
|
| 62 | absolute_total_temp_delta += temp_delta;
|
| 63 | }
|
| 64 | @@ -102,7 +103,7 @@ std::vector<Hct> TemperatureCache::GetAnalogousColors(int count,
|
| 65 | int hue = SanitizeDegreesInt(start_hue + hue_addend);
|
| 66 | Hct hct = GetHctsByHue().at(hue);
|
| 67 | double temp = GetRelativeTemperature(hct);
|
| 68 | - double temp_delta = abs(temp - last_temp);
|
| 69 | + double temp_delta = std::abs(temp - last_temp);
|
| 70 | total_temp_delta += temp_delta;
|
| 71 |
|
| 72 | double desired_total_temp_delta_for_index = (all_colors.size() * temp_step);
|
| 73 | diff --git a/cpp/temperature/temperature_cache.h b/cpp/temperature/temperature_cache.h
|
| 74 | index 17e7c17..492f6e5 100644
|
| 75 | |
| 76 | |
| 77 | @@ -18,6 +18,7 @@
|
| 78 | #define CPP_TEMPERATURE_TEMPERATURE_CACHE_H_
|
| 79 |
|
| 80 | #include <map>
|
| 81 | +#include <optional>
|
| 82 | #include <vector>
|
| 83 |
|
| 84 | #include "cpp/cam/hct.h"
|