Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axis refactor v10 - Remove bool horizontal's, refactor DrawInterlacing #611

Merged
merged 7 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/base/geom/orientation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef BASE_GEOM_ORIENTATION_H
#define BASE_GEOM_ORIENTATION_H

namespace Geom
{

enum class Orientation : bool { horizontal, vertical };

constexpr bool isHorizontal(Orientation orientation)
{
return orientation == Orientation::horizontal;
}

constexpr Orientation operator!(Orientation orientation)
{
return isHorizontal(orientation) ? Orientation::vertical
: Orientation::horizontal;
}

}

#endif
35 changes: 20 additions & 15 deletions src/base/geom/point.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "base/math/floating.h"
#include "base/math/tolerance.h"

#include "orientation.h"

namespace Geom
{

Expand All @@ -33,9 +35,17 @@ struct Point
std::numeric_limits<double>::lowest()};
}

[[nodiscard]] static Point Ident(bool horizontal)
[[nodiscard]] static Point Ident(Orientation orientation)
{
return {horizontal ? 1.0 : 0.0, horizontal ? 0.0 : 1.0};
return {static_cast<double>(isHorizontal(orientation)),
static_cast<double>(!isHorizontal(orientation))};
}

[[nodiscard]] static Point
Coord(Orientation orientation, double value, double other = 0.0)
{
return {isHorizontal(orientation) ? value : other,
isHorizontal(orientation) ? other : value};
}

[[nodiscard]] static Point Polar(double radius, double angle)
Expand Down Expand Up @@ -153,17 +163,9 @@ struct Point

[[nodiscard]] Point yComp() const { return {0, y}; }

[[nodiscard]] Point comp(bool horizontal) const
[[nodiscard]] Point comp(Orientation orientation) const
{
return horizontal ? xComp() : yComp();
}

double &operator[](size_t index)
{
if (index == 0) return x;
if (index == 1) return y;
throw std::logic_error(
"internal error: point coordinate index out of bounds");
return isHorizontal(orientation) ? xComp() : yComp();
}

[[nodiscard]] double abs() const
Expand Down Expand Up @@ -217,12 +219,15 @@ struct Point
[[nodiscard]] Point normalized() const;
[[nodiscard]] Point normal(bool clockwise) const;

[[nodiscard]] double getCoord(bool horizontal) const
[[nodiscard]] double getCoord(Orientation orientation) const
{
return horizontal ? x : y;
return isHorizontal(orientation) ? x : y;
}

double &getCoord(bool horizontal) { return horizontal ? x : y; }
double &getCoord(Orientation orientation)
{
return isHorizontal(orientation) ? x : y;
}

[[nodiscard]] Point leftNormal() const { return Point{y, -x}; }

Expand Down
2 changes: 0 additions & 2 deletions src/base/math/normalizednumber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include <algorithm>
#include <cmath>

#include "floating.h"

namespace Math
{

Expand Down
30 changes: 15 additions & 15 deletions src/chart/animator/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
#include "base/anim/easingfunc.h"
#include "base/anim/element.h"
#include "base/anim/group.h"
#include "base/geom/orientation.h"
#include "chart/generator/plot.h"
#include "chart/options/channel.h"
#include "chart/options/orientation.h"
#include "chart/options/shapetype.h"

#include "morph.h"
Expand Down Expand Up @@ -317,7 +317,7 @@ void Planner::calcNeeded()
return source.prevMainMarker
!= target.prevMainMarker;
})
|| srcOpt->isHorizontal() != trgOpt->isHorizontal());
|| srcOpt->getOrientation() != trgOpt->getOrientation());
}

bool Planner::anyMarker(
Expand Down Expand Up @@ -378,7 +378,7 @@ bool Planner::verticalBeforeHorizontal() const
const auto &srcOpt = source->getOptions();
const auto &trgOpt = target->getOptions();

if (srcOpt->isHorizontal() != trgOpt->isHorizontal()
if (srcOpt->getOrientation() != trgOpt->getOrientation()
|| !srcOpt->getChannels().anyAxisSet()
|| !trgOpt->getChannels().anyAxisSet()) {
if (srcOpt->getChannels().anyAxisSet())
Expand Down Expand Up @@ -408,12 +408,12 @@ bool Planner::needVertical() const
!= target->axises.at(Gen::LegendId::size)
|| (source->markerConnectionOrientation
!= target->markerConnectionOrientation
&& (source->markerConnectionOrientation.value_or(
Gen::Orientation::horizontal)
== Gen::Orientation::vertical
|| target->markerConnectionOrientation.value_or(
Gen::Orientation::horizontal)
== Gen::Orientation::vertical))
&& (!isHorizontal(
source->markerConnectionOrientation.value_or(
Geom::Orientation::horizontal))
|| !isHorizontal(
target->markerConnectionOrientation.value_or(
Geom::Orientation::horizontal))))
|| source->axises.label != target->axises.label
|| anyMarker(+[](const Gen::Marker &source,
const Gen::Marker &target) -> bool
Expand All @@ -436,12 +436,12 @@ bool Planner::needHorizontal() const
|| source->keepAspectRatio != target->keepAspectRatio
|| (source->markerConnectionOrientation
!= target->markerConnectionOrientation
&& ((source->markerConnectionOrientation.value_or(
Gen::Orientation::vertical)
== Gen::Orientation::horizontal)
|| (target->markerConnectionOrientation.value_or(
Gen::Orientation::vertical)
== Gen::Orientation::horizontal)))
&& (isHorizontal(
source->markerConnectionOrientation.value_or(
Geom::Orientation::vertical))
|| isHorizontal(
target->markerConnectionOrientation.value_or(
Geom::Orientation::vertical))))
|| anyMarker(+[](const Gen::Marker &source,
const Gen::Marker &target) -> bool
{
Expand Down
2 changes: 1 addition & 1 deletion src/chart/generator/axis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <cmath>
#include <cstdint>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <optional>
#include <set>
#include <string>
Expand Down
10 changes: 6 additions & 4 deletions src/chart/generator/marker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <utility>

#include "base/conv/auto_json.h"
#include "base/geom/orientation.h"
#include "base/geom/point.h"
#include "base/geom/rect.h"
#include "base/math/range.h"
Expand Down Expand Up @@ -209,15 +210,16 @@ void Marker::fromRectangle(const Geom::Rect &rect)
size = rect.size;
}

Math::Range<> Marker::getSizeBy(bool horizontal) const
Math::Range<> Marker::getSizeBy(AxisId axisId) const
{
return horizontal ? toRectangle().hSize() : toRectangle().vSize();
return isHorizontal(+axisId) ? toRectangle().hSize()
: toRectangle().vSize();
}

void Marker::setSizeBy(bool horizontal, const Math::Range<> range)
void Marker::setSizeBy(AxisId axisId, const Math::Range<> range)
{
auto rect = toRectangle();
if (horizontal)
if (isHorizontal(+axisId))
rect.setHSize(range);
else
rect.setVSize(range);
Expand Down
4 changes: 2 additions & 2 deletions src/chart/generator/marker.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ class Marker
[[nodiscard]] Geom::Rect toRectangle() const;
void fromRectangle(const Geom::Rect &rect);

[[nodiscard]] Math::Range<> getSizeBy(bool horizontal) const;
void setSizeBy(bool horizontal, Math::Range<> range);
[[nodiscard]] Math::Range<> getSizeBy(AxisId axisId) const;
void setSizeBy(AxisId axisId, Math::Range<> range);

Conv::JSONObj &&appendToJSON(Conv::JSONObj &&jsonObj) const;

Expand Down
2 changes: 1 addition & 1 deletion src/chart/generator/plot.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Plot
Axises axises;
Guides guides;
Math::FuzzyBool keepAspectRatio;
std::optional<Orientation> markerConnectionOrientation;
std::optional<Geom::Orientation> markerConnectionOrientation;

Plot(const Plot &other) = default;
Plot(PlotOptionsPtr opts, Styles::Chart style);
Expand Down
Loading