diff --git a/src/base/type/uniquelist.h b/src/base/type/uniquelist.h index 3a25597d7..767aa4e49 100644 --- a/src/base/type/uniquelist.h +++ b/src/base/type/uniquelist.h @@ -237,7 +237,7 @@ template class UniqueList struct CommonIterateVal { const T &value; - const std::size_t *othIx; + const std::size_t *otherIx; }; struct common_iterator diff --git a/src/chart/generator/buckets.h b/src/chart/generator/buckets.h index 9d380ce4f..f63b21fb5 100644 --- a/src/chart/generator/buckets.h +++ b/src/chart/generator/buckets.h @@ -44,9 +44,10 @@ struct Buckets }); } - [[nodiscard]] bool operator!=(const const_iterator &oth) const + [[nodiscard]] bool operator!=( + const const_iterator &other) const { - return data.data() != oth.data.data(); + return data.data() != other.data.data(); } const_iterator &operator++(); diff --git a/src/chart/rendering/drawinterlacing.cpp b/src/chart/rendering/drawinterlacing.cpp index 3c8e7fcdf..e8f9312db 100644 --- a/src/chart/rendering/drawinterlacing.cpp +++ b/src/chart/rendering/drawinterlacing.cpp @@ -35,38 +35,9 @@ void DrawInterlacing::drawGeometries(Gen::AxisId axisIndex) const || guides.interlacings == false) return; - std::map othWeights{{0.0, 0.0}, {1.0, 0.0}}; - - const auto &othGuides = parent.plot->guides.at(!axisIndex); - const auto &othAxisStyle = - parent.rootStyle.plot.getAxis(!axisIndex); - if (!othAxisStyle.interlacing.color->isTransparent() - && othGuides.interlacings != false) - for (const auto &othInterval : - parent.getIntervals(!axisIndex)) { - if (Math::Floating::is_zero(othInterval.isSecond)) - continue; - auto min = std::max(othInterval.range.getMin(), 0.0); - auto max = std::min(othInterval.range.getMax(), 1.0); - auto mprev = std::prev(othWeights.upper_bound(min)); - auto mnext = othWeights.lower_bound(max); - - if (mprev->first < min) - mprev = - othWeights.try_emplace(mprev, min, mprev->second); - if (mnext->first > max) - mnext = othWeights.try_emplace(mnext, - max, - std::prev(mnext)->second); - - while (mprev != mnext) - mprev++->second += - Math::FuzzyBool::And(othInterval.weight, - othInterval.isSecond, - othGuides.interlacings); - } - - auto orientation = !Gen::orientation(axisIndex); + auto otherWeights = getInterlacingWeights(!axisIndex); + auto &&otherInterlacingColor = + *parent.rootStyle.plot.getAxis(!axisIndex).interlacing.color; parent.painter.setPolygonToCircleFactor(0); parent.painter.setPolygonStraightFactor(0); @@ -81,13 +52,15 @@ void DrawInterlacing::drawGeometries(Gen::AxisId axisIndex) const Math::Floating::less) - clippedBottom; - auto rect = [&](const double &from, const double &to) + auto rect = [&, orientation = orientation(axisIndex)]( + const double &from, + const double &to) { return Geom::Rect{ - Geom::Point::Coord(orientation, from, clippedBottom), + Geom::Point::Coord(orientation, clippedBottom, from), {Geom::Size::Coord(orientation, - to - from, - clippedSize)}}; + clippedSize, + to - from)}}; }; auto weight = Math::FuzzyBool::And(interval.weight, @@ -95,9 +68,9 @@ void DrawInterlacing::drawGeometries(Gen::AxisId axisIndex) const guides.interlacings); auto interlacingColor = *axisStyle.interlacing.color * weight; - for (auto first = othWeights.begin(), + for (auto first = otherWeights.begin(), next = std::next(first), - last = othWeights.end(); + last = otherWeights.end(); next != last; ++next, ++first) { if (Math::Floating::is_zero(first->second)) @@ -105,36 +78,13 @@ void DrawInterlacing::drawGeometries(Gen::AxisId axisIndex) const interlacingColor, rect(first->first, next->first)); else if (axisIndex == Gen::AxisId::y) { - auto color = - interlacingColor - + *othAxisStyle.interlacing.color * first->second; - - color.alpha = - 1 - - (1 - - axisStyle.interlacing.color->alpha - * weight) - * (1 - - othAxisStyle.interlacing.color->alpha - * first->second); - - if (weight + first->second > 1.0) - color = Math::Niebloid::interpolate( - color - * std::max({std::abs(axisStyle.interlacing - .color->red - - color.red), - std::abs( - axisStyle.interlacing.color->green - - color.green), - std::abs( - axisStyle.interlacing.color->blue - - color.blue)}), - color, - 2.0 - (weight + first->second)); drawInterlacing(first->second > weight ? !axisIndex : axisIndex, - color, + getCrossingInterlacingColor( + *axisStyle.interlacing.color, + weight, + otherInterlacingColor, + first->second), rect(first->first, next->first)); } } @@ -313,4 +263,61 @@ void DrawInterlacing::drawSticks(double tickLength, canvas.restore(); } +std::map DrawInterlacing::getInterlacingWeights( + Gen::AxisId axisIndex) const +{ + std::map weights{{0.0, 0.0}, {1.0, 0.0}}; + + auto &&guides = parent.plot->guides.at(axisIndex); + auto &&axisStyle = parent.rootStyle.plot.getAxis(axisIndex); + if (axisStyle.interlacing.color->isTransparent() + || guides.interlacings == false) + return weights; + + for (auto &&interval : parent.getIntervals(axisIndex)) { + if (Math::Floating::is_zero(interval.isSecond)) continue; + auto min = std::max(interval.range.getMin(), 0.0); + auto max = std::min(interval.range.getMax(), 1.0); + auto mprev = std::prev(weights.upper_bound(min)); + auto mnext = weights.lower_bound(max); + + if (mprev->first < min) + mprev = weights.try_emplace(mprev, min, mprev->second); + if (mnext->first > max) + mnext = weights.try_emplace(mnext, + max, + std::prev(mnext)->second); + + while (mprev != mnext) + mprev++->second += + Math::FuzzyBool::And(interval.weight, + interval.isSecond, + guides.interlacings); + } + return weights; +} + +Gfx::Color DrawInterlacing::getCrossingInterlacingColor( + const Gfx::Color &mainColor, + double mainWeight, + const Gfx::Color &otherColor, + double otherWeight) +{ + auto color = mainColor * mainWeight + otherColor * otherWeight; + + color.alpha = 1 + - (1 - mainColor.alpha * mainWeight) + * (1 - otherColor.alpha * otherWeight); + + if (mainWeight + otherWeight > 1.0) + color = Math::Niebloid::interpolate(color, + color + * std::max({std::abs(mainColor.red - otherColor.red), + std::abs(mainColor.green - otherColor.green), + std::abs(mainColor.blue - otherColor.blue)}), + mainWeight + otherWeight - 1.0); + + return color; +} + } \ No newline at end of file diff --git a/src/chart/rendering/drawinterlacing.h b/src/chart/rendering/drawinterlacing.h index c2285eb7b..f27c10d73 100644 --- a/src/chart/rendering/drawinterlacing.h +++ b/src/chart/rendering/drawinterlacing.h @@ -31,6 +31,15 @@ class DrawInterlacing const Gfx::Color &tickColor, Gen::AxisId axisIndex, const Geom::Point &tickPos) const; + + [[nodiscard]] std::map getInterlacingWeights( + Gen::AxisId axisIndex) const; + + [[nodiscard]] static Gfx::Color getCrossingInterlacingColor( + const Gfx::Color &mainColor, + double mainWeight, + const Gfx::Color &otherColor, + double otherWeight); }; } diff --git a/src/dataframe/impl/dataframe.cpp b/src/dataframe/impl/dataframe.cpp index 118678262..feece15d4 100644 --- a/src/dataframe/impl/dataframe.cpp +++ b/src/dataframe/impl/dataframe.cpp @@ -347,7 +347,7 @@ void dataframe::add_series_by_other(std::string_view, const std::function &, std::span>) & { - if (as_if()) error(error_type::unimplemented, "by oth"); + if (as_if()) error(error_type::unimplemented, "by other"); } void dataframe::remove_series( diff --git a/src/dataframe/interface.h b/src/dataframe/interface.h index 0b72f2a71..c2b868cc9 100644 --- a/src/dataframe/interface.h +++ b/src/dataframe/interface.h @@ -58,14 +58,14 @@ struct custom_aggregator id_type (*create)(); double (*add)(id_type &, cell_reference const &); - auto operator<=>(const custom_aggregator &oth) const + auto operator<=>(const custom_aggregator &other) const { - return name <=> oth.name; + return name <=> other.name; } - auto operator==(const custom_aggregator &oth) const + auto operator==(const custom_aggregator &other) const { - return name == oth.name; + return name == other.name; } }; diff --git a/src/dataframe/old/datatable.cpp b/src/dataframe/old/datatable.cpp index e8ad3a6e5..33ab6d87e 100644 --- a/src/dataframe/old/datatable.cpp +++ b/src/dataframe/old/datatable.cpp @@ -56,9 +56,9 @@ void DataTable::pushRow(const std::span &cells) std::string DataTable::getInfos() const { return df.as_string(); } -bool DataCube::iterator_t::operator!=(const iterator_t &oth) const +bool DataCube::iterator_t::operator!=(const iterator_t &other) const { - return parent != oth.parent; + return parent != other.parent; } void DataCube::iterator_t::operator++() { parent->incr(*this); } diff --git a/src/dataframe/old/datatable.h b/src/dataframe/old/datatable.h index b535b6439..72aff2b0c 100644 --- a/src/dataframe/old/datatable.h +++ b/src/dataframe/old/datatable.h @@ -125,7 +125,7 @@ class DataCube const DataCube *parent{}; MultiIndex index; - [[nodiscard]] bool operator!=(const iterator_t &oth) const; + [[nodiscard]] bool operator!=(const iterator_t &other) const; void operator++(); diff --git a/test/e2e/tests/style_tests.json b/test/e2e/tests/style_tests.json index 915530d72..cb820c8db 100644 --- a/test/e2e/tests/style_tests.json +++ b/test/e2e/tests/style_tests.json @@ -305,7 +305,7 @@ "refs": ["5a62ac8"] }, "plot/interlacing": { - "refs": ["82e891d"] + "refs": ["f14b366"] }, "plot/paddingBottom/animated_150-350": { "refs": ["e618e56"]