Added
Link Here
|
1 |
From f0355a6341aceee93ce4d4d70cd9ec3a44081c38 Mon Sep 17 00:00:00 2001 |
2 |
From: Rafael Siejakowski <rs@rs-math.net> |
3 |
Date: Sun, 20 Aug 2023 18:15:19 +0200 |
4 |
Subject: [PATCH] Fix build on FreeBSD: rename two helper functions |
5 |
|
6 |
The functions roundup() and rounddown() are renamed to round_up() and |
7 |
round_down(), respectively. This prevents a name clash with the macros |
8 |
roundup and rounddown defined in sys/param.h which for some reason gets |
9 |
pulled in on FreeBSD. |
10 |
|
11 |
Fixes https://gitlab.com/inkscape/inbox/-/issues/9062 |
12 |
--- |
13 |
src/display/drawing-pattern.cpp | 14 +++++++------- |
14 |
src/helper/geom.h | 4 ++-- |
15 |
src/helper/mathfns.h | 6 +++--- |
16 |
src/ui/widget/canvas/pixelstreamer.cpp | 2 +- |
17 |
src/util/pool.cpp | 6 +++--- |
18 |
5 files changed, 16 insertions(+), 16 deletions(-) |
19 |
|
20 |
diff --git a/src/display/drawing-pattern.cpp b/src/display/drawing-pattern.cpp |
21 |
index 6b30c968ded..34df2f873b1 100644 |
22 |
--- src/display/drawing-pattern.cpp |
23 |
+++ src/display/drawing-pattern.cpp |
24 |
@@ -89,7 +89,7 @@ cairo_pattern_t *DrawingPattern::renderPattern(RenderContext &rc, Geom::IntRect |
25 |
if (rect.dimensions()[i] >= _pattern_resolution[i]) { |
26 |
rect[i] = {0, _pattern_resolution[i]}; |
27 |
} else { |
28 |
- rect[i] -= Util::rounddown(rect[i].min(), _pattern_resolution[i]); |
29 |
+ rect[i] -= Util::round_down(rect[i].min(), _pattern_resolution[i]); |
30 |
} |
31 |
} |
32 |
return rect; |
33 |
@@ -101,7 +101,7 @@ cairo_pattern_t *DrawingPattern::renderPattern(RenderContext &rc, Geom::IntRect |
34 |
int const period = _pattern_resolution[i]; |
35 |
if (a[i].extent() >= period) return true; |
36 |
if (b[i].extent() > a[i].extent()) return false; |
37 |
- return Util::rounddown(b[i].min() - a[i].min(), period) >= b[i].max() - a[i].max(); |
38 |
+ return Util::round_down(b[i].min() - a[i].min(), period) >= b[i].max() - a[i].max(); |
39 |
}; |
40 |
return check(0) && check(1); |
41 |
}; |
42 |
@@ -112,7 +112,7 @@ cairo_pattern_t *DrawingPattern::renderPattern(RenderContext &rc, Geom::IntRect |
43 |
int const period = _pattern_resolution[i]; |
44 |
if (a[i].extent() >= period) return true; |
45 |
if (b[i].extent() >= period) return true; |
46 |
- return Util::rounddown(b[i].max() - a[i].min(), period) >= b[i].min() - a[i].max(); |
47 |
+ return Util::round_down(b[i].max() - a[i].min(), period) >= b[i].min() - a[i].max(); |
48 |
}; |
49 |
return check(0) && check(1); |
50 |
}; |
51 |
@@ -121,8 +121,8 @@ cairo_pattern_t *DrawingPattern::renderPattern(RenderContext &rc, Geom::IntRect |
52 |
auto overlapping_translates = [&, this] (Geom::IntRect const &a, Geom::IntRect const &b) { |
53 |
Geom::IntPoint min, max; |
54 |
for (int i = 0; i < 2; i++) { |
55 |
- min[i] = Util::roundup (b[i].min() - a[i].max() + 1, _pattern_resolution[i]); |
56 |
- max[i] = Util::rounddown(b[i].max() - a[i].min() - 1, _pattern_resolution[i]); |
57 |
+ min[i] = Util::round_up (b[i].min() - a[i].max() + 1, _pattern_resolution[i]); |
58 |
+ max[i] = Util::round_down(b[i].max() - a[i].min() - 1, _pattern_resolution[i]); |
59 |
} |
60 |
return std::make_pair(min, max); |
61 |
}; |
62 |
@@ -165,7 +165,7 @@ cairo_pattern_t *DrawingPattern::renderPattern(RenderContext &rc, Geom::IntRect |
63 |
|
64 |
for (auto it = surfaces.begin(); it != surfaces.end(); ) { |
65 |
if (wrapped_touches(expanded, it->rect)) { |
66 |
- expanded.unionWith(it->rect + rounddown(expanded.max() - it->rect.min(), _pattern_resolution)); |
67 |
+ expanded.unionWith(it->rect + round_down(expanded.max() - it->rect.min(), _pattern_resolution)); |
68 |
merged.emplace_back(std::move(*it)); |
69 |
*it = std::move(surfaces.back()); |
70 |
surfaces.pop_back(); |
71 |
@@ -259,7 +259,7 @@ cairo_pattern_t *DrawingPattern::renderPattern(RenderContext &rc, Geom::IntRect |
72 |
|
73 |
// Create and return pattern. |
74 |
auto cp = cairo_pattern_create_for_surface(surface->surface->cobj()); |
75 |
- auto const shift = surface->rect.min() + rounddown(area_orig.min() - surface->rect.min(), _pattern_resolution); |
76 |
+ auto const shift = surface->rect.min() + round_down(area_orig.min() - surface->rect.min(), _pattern_resolution); |
77 |
ink_cairo_pattern_set_matrix(cp, pattern_to_tile * Geom::Translate(-shift)); |
78 |
cairo_pattern_set_extend(cp, CAIRO_EXTEND_REPEAT); |
79 |
if (rc.antialiasing_override && rc.antialiasing_override.value() == Antialiasing::None) { |
80 |
diff --git a/src/helper/geom.h b/src/helper/geom.h |
81 |
index 59542e7d44f..e8b1d1f46ee 100644 |
82 |
--- src/helper/geom.h |
83 |
+++ src/helper/geom.h |
84 |
@@ -54,10 +54,10 @@ inline Geom::Coord triangle_area(Geom::Point const &p1, Geom::Point const &p2, G |
85 |
return p1[X] * p2[Y] + p1[Y] * p3[X] + p2[X] * p3[Y] - p2[Y] * p3[X] - p1[Y] * p2[X] - p1[X] * p3[Y]; |
86 |
} |
87 |
|
88 |
-inline auto rounddown(Geom::IntPoint const &a, Geom::IntPoint const &b) |
89 |
+inline auto round_down(Geom::IntPoint const &a, Geom::IntPoint const &b) |
90 |
{ |
91 |
using namespace Inkscape::Util; |
92 |
- return Geom::IntPoint(rounddown(a.x(), b.x()), rounddown(a.y(), b.y())); |
93 |
+ return Geom::IntPoint(round_down(a.x(), b.x()), round_down(a.y(), b.y())); |
94 |
} |
95 |
|
96 |
inline auto expandedBy(Geom::IntRect rect, int amount) |
97 |
diff --git a/src/helper/mathfns.h b/src/helper/mathfns.h |
98 |
index 6f466fb2c33..730b6ba2153 100644 |
99 |
--- src/helper/mathfns.h |
100 |
+++ src/helper/mathfns.h |
101 |
@@ -79,16 +79,16 @@ T constexpr safemod(T a, T b) |
102 |
|
103 |
/// Returns \a a rounded down to the nearest multiple of \a b, assuming b >= 1. |
104 |
template <typename T, typename std::enable_if<std::is_integral<T>::value, bool>::type = true> |
105 |
-T constexpr rounddown(T a, T b) |
106 |
+T constexpr round_down(T a, T b) |
107 |
{ |
108 |
return a - safemod(a, b); |
109 |
} |
110 |
|
111 |
/// Returns \a a rounded up to the nearest multiple of \a b, assuming b >= 1. |
112 |
template <typename T, typename std::enable_if<std::is_integral<T>::value, bool>::type = true> |
113 |
-T constexpr roundup(T a, T b) |
114 |
+T constexpr round_up(T a, T b) |
115 |
{ |
116 |
- return rounddown(a - 1, b) + b; |
117 |
+ return round_down(a - 1, b) + b; |
118 |
} |
119 |
|
120 |
/** |
121 |
diff --git a/src/ui/widget/canvas/pixelstreamer.cpp b/src/ui/widget/canvas/pixelstreamer.cpp |
122 |
index 74d557b37b1..ddafee96bac 100644 |
123 |
--- src/ui/widget/canvas/pixelstreamer.cpp |
124 |
+++ src/ui/widget/canvas/pixelstreamer.cpp |
125 |
@@ -99,7 +99,7 @@ public: |
126 |
// Calculate image properties required by cairo. |
127 |
int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, dimensions.x()); |
128 |
int size = stride * dimensions.y(); |
129 |
- int sizeup = Util::roundup(size, 64); |
130 |
+ int sizeup = Util::round_up(size, 64); |
131 |
assert(sizeup < bufsize); |
132 |
|
133 |
// Attempt to advance buffers in states 3 or 4 towards 5, if allowed. |
134 |
diff --git a/src/util/pool.cpp b/src/util/pool.cpp |
135 |
index 455366b9f1b..89fe77ae023 100644 |
136 |
--- src/util/pool.cpp |
137 |
+++ src/util/pool.cpp |
138 |
@@ -8,7 +8,7 @@ |
139 |
namespace Inkscape::Util { |
140 |
|
141 |
// Round up x to the next multiple of m. |
142 |
-static std::byte *roundup(std::byte *x, std::size_t m) |
143 |
+static std::byte *round_up(std::byte *x, std::size_t m) |
144 |
{ |
145 |
auto y = reinterpret_cast<uintptr_t>(x); |
146 |
y = ((y - 1) / m + 1) * m; |
147 |
@@ -17,7 +17,7 @@ static std::byte *roundup(std::byte *x, std::size_t m) |
148 |
|
149 |
std::byte *Pool::allocate(std::size_t size, std::size_t alignment) |
150 |
{ |
151 |
- auto a = roundup(cur, alignment); |
152 |
+ auto a = round_up(cur, alignment); |
153 |
auto b = a + size; |
154 |
|
155 |
if (b <= end) { |
156 |
@@ -33,7 +33,7 @@ std::byte *Pool::allocate(std::size_t size, std::size_t alignment) |
157 |
resetblock(); |
158 |
nextsize = cursize * 3 / 2; |
159 |
|
160 |
- a = roundup(cur, alignment); |
161 |
+ a = round_up(cur, alignment); |
162 |
b = a + size; |
163 |
|
164 |
assert(b <= end); |
165 |
-- |
166 |
GitLab |
167 |
|