Skip to content

Commit f859520

Browse files
committed
Merge remote-tracking branch 'origin/main' into clang-tidy-fixes
# Conflicts: # src/base/geom/circle.cpp # src/base/geom/circle.h # src/base/geom/rect.cpp # src/base/geom/triangle.cpp
2 parents 4e6948c + 5b9bc88 commit f859520

File tree

23 files changed

+251
-252
lines changed

23 files changed

+251
-252
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Fixed
6+
7+
- Area charts with data series started with zero: tooltip fixed.
8+
59
## [0.12.0] - 2024-07-29
610

711
### Fixed

src/base/geom/circle.cpp

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,6 @@
1515
namespace Geom
1616
{
1717

18-
Circle::Circle(const Rect &rect, FromRect fromRect) :
19-
center(rect.pos + rect.size / 2.0)
20-
{
21-
switch (fromRect) {
22-
case FromRect::inscribed:
23-
radius = rect.size.minSize() / 2.0;
24-
break;
25-
case FromRect::sameWidth: radius = rect.size.x / 2.0; break;
26-
case FromRect::sameHeight: radius = rect.size.y / 2.0; break;
27-
case FromRect::outscribed:
28-
radius = rect.size.diagonal() / 2.0;
29-
break;
30-
default: throw std::logic_error("invalid circle parameter");
31-
}
32-
}
33-
3418
Circle::Circle(const Circle &c0,
3519
const Circle &c1,
3620
double radius,
@@ -52,30 +36,16 @@ bool Circle::concentric(const Circle &c) const
5236
return center == c.center;
5337
}
5438

55-
bool Circle::colateral(const Circle &c, double tolerance) const
56-
{
57-
return Math::AddTolerance(centerDistance(c), tolerance)
58-
== (radius + c.radius);
59-
}
60-
6139
double Circle::area() const
6240
{
6341
return std::numbers::pi * radius * radius;
6442
}
6543

66-
bool Circle::overlaps(const Circle &c, double tolerance) const
44+
bool Circle::overlaps(const Circle &c) const
6745
{
6846
auto d = c.center - center;
6947
auto sumRadius = radius + c.radius;
70-
return Math::AddTolerance(d.sqrAbs(), tolerance)
71-
< sumRadius * sumRadius;
72-
}
73-
74-
double Circle::overlapFactor(const Circle &c) const
75-
{
76-
auto d = centerDistance(c);
77-
auto r = radius + c.radius;
78-
return d == 0 ? 0 : r / d;
48+
return Math::AddTolerance(d.sqrAbs()) < sumRadius * sumRadius;
7949
}
8050

8151
Rect Circle::boundary() const
@@ -89,6 +59,13 @@ bool Circle::contains(const Point &point) const
8959
return (point - center).sqrAbs() <= radius * radius;
9060
}
9161

62+
double Circle::distance(const Point &point) const
63+
{
64+
return std::max(0.0,
65+
(point - center).abs() - radius,
66+
Math::Floating::less);
67+
}
68+
9269
double Circle::centerDistance(const Circle &c) const
9370
{
9471
return (center - c.center).abs();

src/base/geom/circle.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ namespace Geom
1313
class Circle
1414
{
1515
public:
16-
enum class FromRect : std::uint8_t {
17-
inscribed,
18-
sameWidth,
19-
sameHeight,
20-
outscribed
21-
};
22-
2316
Point center;
2417
double radius;
2518

@@ -30,8 +23,6 @@ class Circle
3023
radius(radius)
3124
{}
3225

33-
Circle(const Rect &rect, FromRect fromRect);
34-
3526
Circle(const Circle &c0,
3627
const Circle &c1,
3728
double radius,
@@ -48,13 +39,10 @@ class Circle
4839
}
4940

5041
[[nodiscard]] double area() const;
51-
[[nodiscard]] bool overlaps(const Circle &c,
52-
double tolerance) const;
53-
[[nodiscard]] double overlapFactor(const Circle &c) const;
54-
[[nodiscard]] bool colateral(const Circle &c,
55-
double tolerance) const;
42+
[[nodiscard]] bool overlaps(const Circle &c) const;
5643
[[nodiscard]] Rect boundary() const;
5744
[[nodiscard]] bool contains(const Point &point) const;
45+
[[nodiscard]] double distance(const Point &point) const;
5846
[[nodiscard]] double distance(const Circle &c) const;
5947
[[nodiscard]] Solutions<Point, 2> intersection(
6048
const Circle &c) const;

src/base/geom/line.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct Line
1919

2020
[[nodiscard]] bool isPoint() const { return begin == end; }
2121

22-
[[nodiscard]] Geom::Line extend(double length) const
22+
[[nodiscard]] Line extend(double length) const
2323
{
2424
auto p = end - begin;
2525
auto d = p.abs();
@@ -28,28 +28,28 @@ struct Line
2828
return {begin, begin + (p * m)};
2929
}
3030

31-
Geom::Line operator*(double value) const
31+
Line operator*(double value) const
3232
{
3333
return {begin * value, end * value};
3434
}
3535

36-
Geom::Line operator+(const Geom::Line &other) const
36+
Line operator+(const Line &other) const
3737
{
3838
return {begin + other.begin, end + other.end};
3939
}
4040

41-
void shift(const Geom::Point &offset)
41+
void shift(const Point &offset)
4242
{
4343
begin = begin + offset;
4444
end = end + offset;
4545
}
4646

47-
[[nodiscard]] Geom::Point at(double t) const
47+
[[nodiscard]] Point at(double t) const
4848
{
4949
return begin + (end - begin) * t;
5050
}
5151

52-
[[nodiscard]] Geom::Line segment(double t0, double t1) const
52+
[[nodiscard]] Line segment(double t0, double t1) const
5353
{
5454
return {at(t0), at(t1)};
5555
}
@@ -61,7 +61,9 @@ struct Line
6161

6262
[[nodiscard]] double distance(const Point &point) const
6363
{
64-
auto projection = ((point - begin).dot(getDirection()))
64+
if (isPoint()) return (point - begin).abs();
65+
66+
auto projection = (point - begin).dot(getDirection())
6567
/ (length() * length());
6668

6769
projection =

src/base/geom/point.h

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,56 +19,56 @@ struct Point
1919
double x{0.0};
2020
double y{0.0};
2121

22-
static Point Invalid() { return {NAN, NAN}; }
22+
[[nodiscard]] static Point Invalid() { return {NAN, NAN}; }
2323

24-
static Point Max()
24+
[[nodiscard]] static Point Max()
2525
{
2626
return {std::numeric_limits<double>::max(),
2727
std::numeric_limits<double>::max()};
2828
}
2929

30-
static Point Min()
30+
[[nodiscard]] static Point Min()
3131
{
3232
return {std::numeric_limits<double>::lowest(),
3333
std::numeric_limits<double>::lowest()};
3434
}
3535

36-
static Point Ident(bool horizontal)
36+
[[nodiscard]] static Point Ident(bool horizontal)
3737
{
3838
return {horizontal ? 1.0 : 0.0, horizontal ? 0.0 : 1.0};
3939
}
4040

41-
static Point Polar(double radius, double angle)
41+
[[nodiscard]] static Point Polar(double radius, double angle)
4242
{
4343
return {radius * cos(angle), radius * sin(angle)};
4444
}
4545

46-
static Point X(double x) { return {x, 0}; }
46+
[[nodiscard]] static Point X(double x) { return {x, 0}; }
4747

48-
static Point Y(double y) { return {0, y}; }
48+
[[nodiscard]] static Point Y(double y) { return {0, y}; }
4949

50-
Point operator*(double factor) const
50+
[[nodiscard]] Point operator*(double factor) const
5151
{
5252
return {x * factor, y * factor};
5353
}
5454

55-
Point operator/(double divisor) const
55+
[[nodiscard]] Point operator/(double divisor) const
5656
{
5757
if (Math::Floating::is_zero(divisor)) return Invalid();
5858
return {x / divisor, y / divisor};
5959
}
6060

61-
Point operator+(const Point &other) const
61+
[[nodiscard]] Point operator+(const Point &other) const
6262
{
6363
return {x + other.x, y + other.y};
6464
}
6565

66-
Point operator-(const Point &other) const
66+
[[nodiscard]] Point operator-(const Point &other) const
6767
{
6868
return {x - other.x, y - other.y};
6969
}
7070

71-
Point operator*(const Point &other) const
71+
[[nodiscard]] Point operator*(const Point &other) const
7272
{
7373
return {x * other.x, y * other.y};
7474
}
@@ -78,18 +78,65 @@ struct Point
7878
return x * other.x + y * other.y;
7979
}
8080

81-
Point operator/(const Point &other) const
81+
[[nodiscard]] Point operator/(const Point &other) const
8282
{
8383
using Math::Floating::is_zero;
8484
if (is_zero(other.x) || is_zero(other.y)) return Invalid();
8585
return {x / other.x, y / other.y};
8686
}
8787

88-
double operator^(const Point &p) const
88+
[[nodiscard]] double operator^(const Point &p) const
8989
{
9090
return x * p.y - y * p.x;
9191
}
9292

93+
Point &operator+=(const Point &other)
94+
{
95+
x += other.x;
96+
y += other.y;
97+
return *this;
98+
}
99+
100+
Point &operator-=(const Point &other)
101+
{
102+
x -= other.x;
103+
y -= other.y;
104+
return *this;
105+
}
106+
107+
Point &operator*=(double factor)
108+
{
109+
x *= factor;
110+
y *= factor;
111+
return *this;
112+
}
113+
114+
Point &operator/=(double divisor)
115+
{
116+
if (Math::Floating::is_zero(divisor))
117+
return *this = Invalid();
118+
x /= divisor;
119+
y /= divisor;
120+
return *this;
121+
}
122+
123+
Point &operator*=(const Point &other)
124+
{
125+
x *= other.x;
126+
y *= other.y;
127+
return *this;
128+
}
129+
130+
Point &operator/=(const Point &other)
131+
{
132+
using Math::Floating::is_zero;
133+
if (is_zero(other.x) || is_zero(other.y))
134+
return *this = Invalid();
135+
x /= other.x;
136+
y /= other.y;
137+
return *this;
138+
}
139+
93140
[[nodiscard]] Point flip() const { return {y, x}; }
94141

95142
[[nodiscard]] Point flipX() const { return {-x, y}; }
@@ -215,7 +262,7 @@ struct Size : Point
215262
std::min(s1.y, s2.y, less)};
216263
}
217264

218-
[[nodiscard]] bool isSquare(double toleranceFactor = 0.0) const
265+
[[nodiscard]] bool isSquare(double toleranceFactor) const
219266
{
220267
using Math::Floating::is_zero;
221268
if (is_zero(y)) return false;

src/base/geom/quadrilateral.cpp

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,12 @@
99
namespace Geom
1010
{
1111

12-
ConvexQuad::ConvexQuad(const Rect &rect)
13-
{
14-
points[0] = rect.pos;
15-
points[1] = rect.pos + Point{rect.size.x, 0.0};
16-
points[2] = rect.pos + rect.size;
17-
points[3] = rect.pos + Point{0.0, rect.size.y};
18-
}
19-
20-
Rect ConvexQuad::boundary() const { return Rect::Boundary(points); }
21-
22-
ConvexQuad ConvexQuad::Square(Point p0, Point p2)
23-
{
24-
auto center = (p0 + p2) / 2;
25-
auto halfDiagonal = (p2 - p0) / 2;
26-
auto p1 = center + halfDiagonal.normal(false);
27-
auto p3 = center + halfDiagonal.normal(true);
28-
return ConvexQuad({p0, p1, p2, p3});
29-
}
30-
3112
ConvexQuad ConvexQuad::Isosceles(Point base0Middle,
3213
Point base1Middle,
3314
double base0Length,
3415
double base1Length)
3516
{
36-
auto dir = base1Middle == base0Middle
37-
? Point{0, 1}
38-
: (base1Middle - base0Middle).normalized();
17+
auto dir = (base1Middle - base0Middle).normalized();
3918

4019
return ConvexQuad(
4120
{base0Middle + dir.normal(false) * (base0Length / 2),
@@ -44,20 +23,12 @@ ConvexQuad ConvexQuad::Isosceles(Point base0Middle,
4423
base1Middle + dir.normal(false) * (base1Length / 2)});
4524
}
4625

47-
bool ConvexQuad::contains(const Point &p, double tolerance) const
48-
{
49-
auto boundaryArea = Triangle{{points[0], points[1], p}}.area()
50-
+ Triangle{{points[1], points[2], p}}.area()
51-
+ Triangle{{points[2], points[3], p}}.area()
52-
+ Triangle{{points[3], points[0], p}}.area();
53-
54-
return Math::AddTolerance(boundaryArea, tolerance) <= area();
55-
}
56-
57-
double ConvexQuad::area() const
26+
double ConvexQuad::distance(const Point &point) const
5827
{
59-
return Triangle{{points[0], points[1], points[2]}}.area()
60-
+ Triangle{{points[2], points[3], points[0]}}.area();
28+
return std::min(
29+
Triangle{{points[0], points[1], points[2]}}.distance(point),
30+
Triangle{{points[2], points[3], points[0]}}.distance(point),
31+
Math::Floating::less);
6132
}
6233

6334
}

0 commit comments

Comments
 (0)