Refactoring

This commit is contained in:
Isaac 2024-05-18 19:30:38 +04:00
parent 04b69499a6
commit 1ee81d91d2
2 changed files with 14 additions and 14 deletions

View File

@ -15,10 +15,10 @@ enum class ColorFormatDenominator {
}; };
struct Color { struct Color {
double r; float r;
double g; float g;
double b; float b;
double a; float a;
bool operator==(Color const &rhs) const { bool operator==(Color const &rhs) const {
if (r != rhs.r) { if (r != rhs.r) {
@ -40,7 +40,7 @@ struct Color {
return !(*this == rhs); return !(*this == rhs);
} }
explicit Color(double r_, double g_, double b_, double a_, ColorFormatDenominator denominator = ColorFormatDenominator::One); explicit Color(float r_, float g_, float b_, float a_, ColorFormatDenominator denominator = ColorFormatDenominator::One);
explicit Color(lottiejson11::Json const &jsonAny) noexcept(false); explicit Color(lottiejson11::Json const &jsonAny) noexcept(false);
lottiejson11::Json toJson() const; lottiejson11::Json toJson() const;

View File

@ -6,8 +6,8 @@
namespace lottie { namespace lottie {
Color::Color(double r_, double g_, double b_, double a_, ColorFormatDenominator denominator) { Color::Color(float r_, float g_, float b_, float a_, ColorFormatDenominator denominator) {
double denominatorValue = 1.0; float denominatorValue = 1.0;
switch (denominator) { switch (denominator) {
case ColorFormatDenominator::One: { case ColorFormatDenominator::One: {
denominatorValue = 1.0; denominatorValue = 1.0;
@ -43,7 +43,7 @@ Color::Color(lottiejson11::Json const &jsonAny) noexcept(false) :
size_t index = 0; size_t index = 0;
double r1 = 0.0; float r1 = 0.0;
if (index < jsonAny.array_items().size()) { if (index < jsonAny.array_items().size()) {
if (!jsonAny.array_items()[index].is_number()) { if (!jsonAny.array_items()[index].is_number()) {
throw LottieParsingException(); throw LottieParsingException();
@ -52,7 +52,7 @@ Color::Color(lottiejson11::Json const &jsonAny) noexcept(false) :
index++; index++;
} }
double g1 = 0.0; float g1 = 0.0;
if (index < jsonAny.array_items().size()) { if (index < jsonAny.array_items().size()) {
if (!jsonAny.array_items()[index].is_number()) { if (!jsonAny.array_items()[index].is_number()) {
throw LottieParsingException(); throw LottieParsingException();
@ -61,7 +61,7 @@ Color::Color(lottiejson11::Json const &jsonAny) noexcept(false) :
index++; index++;
} }
double b1 = 0.0; float b1 = 0.0;
if (index < jsonAny.array_items().size()) { if (index < jsonAny.array_items().size()) {
if (!jsonAny.array_items()[index].is_number()) { if (!jsonAny.array_items()[index].is_number()) {
throw LottieParsingException(); throw LottieParsingException();
@ -70,7 +70,7 @@ Color::Color(lottiejson11::Json const &jsonAny) noexcept(false) :
index++; index++;
} }
double a1 = 0.0; float a1 = 0.0;
if (index < jsonAny.array_items().size()) { if (index < jsonAny.array_items().size()) {
if (!jsonAny.array_items()[index].is_number()) { if (!jsonAny.array_items()[index].is_number()) {
throw LottieParsingException(); throw LottieParsingException();
@ -118,9 +118,9 @@ Color Color::fromString(std::string const &string) {
converter >> std::hex >> rgbValue; converter >> std::hex >> rgbValue;
return Color( return Color(
((double)((rgbValue & 0xFF0000) >> 16)) / 255.0, ((float)((rgbValue & 0xFF0000) >> 16)) / 255.0,
((double)((rgbValue & 0x00FF00) >> 8)) / 255.0, ((float)((rgbValue & 0x00FF00) >> 8)) / 255.0,
((double)(rgbValue & 0x0000FF)) / 255.0, ((float)(rgbValue & 0x0000FF)) / 255.0,
1.0 1.0
); );
} }