Skip to content

Commit 4a51d97

Browse files
committed
misc
1 parent a6dd886 commit 4a51d97

14 files changed

+86
-93
lines changed

include/threepp/math/Spherical.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
#ifndef THREEPP_SPHERICAL_HPP
44
#define THREEPP_SPHERICAL_HPP
55

6-
#include "threepp/math/Vector3.hpp"
7-
86
namespace threepp {
97

8+
class Vector3;
9+
1010
class Spherical {
1111

1212
public:

include/threepp/math/SphericalHarmonics3.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace threepp {
3535

3636
SphericalHarmonis3& lerp(const SphericalHarmonis3& sh, float alpha);
3737

38-
const std::vector<Vector3>& getCoefficients() const;
38+
[[nodiscard]] const std::vector<Vector3>& getCoefficients() const;
3939

4040
private:
4141
std::vector<Vector3> coefficients_;

include/threepp/math/Vector3.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -272,23 +272,23 @@ namespace threepp {
272272
return os;
273273
}
274274

275-
inline static Vector3 X() {
275+
static Vector3 X() {
276276
return {1, 0, 0};
277277
}
278278

279-
inline static Vector3 Y() {
279+
static Vector3 Y() {
280280
return {0, 1, 0};
281281
}
282282

283-
inline static Vector3 Z() {
283+
static Vector3 Z() {
284284
return {0, 0, 1};
285285
}
286286

287-
inline static Vector3 ZEROS() {
287+
static Vector3 ZEROS() {
288288
return {0, 0, 0};
289289
}
290290

291-
inline static Vector3 ONES() {
291+
static Vector3 ONES() {
292292
return {1, 1, 1};
293293
}
294294
};

include/threepp/math/float_view.hpp

+20-20
Original file line numberDiff line numberDiff line change
@@ -16,123 +16,123 @@ namespace threepp {
1616
float_view(float value = 0)
1717
: value_(value) {}
1818

19-
inline operator float() const {
19+
operator float() const {
2020

2121
return value_;
2222
}
2323

24-
inline float_view& operator=(float v) {
24+
float_view& operator=(float v) {
2525

2626
this->value_ = v;
2727
if (f_) f_.value()();
2828

2929
return *this;
3030
}
3131

32-
inline float operator*(float f) const {
32+
float operator*(float f) const {
3333

3434
return value_ * f;
3535
}
3636

37-
inline float operator*(const float_view& f) const {
37+
float operator*(const float_view& f) const {
3838

3939
return value_ * f.value_;
4040
}
4141

42-
inline float_view& operator*=(float f) {
42+
float_view& operator*=(float f) {
4343

4444
value_ *= f;
4545
if (f_) f_.value()();
4646

4747
return *this;
4848
}
4949

50-
inline float operator/(float f) const {
50+
float operator/(float f) const {
5151

5252
return value_ / f;
5353
}
5454

55-
inline float_view& operator/=(float f) {
55+
float_view& operator/=(float f) {
5656

5757
value_ /= f;
5858
if (f_) f_.value()();
5959

6060
return *this;
6161
}
6262

63-
inline float operator+(float f) const {
63+
float operator+(float f) const {
6464

6565
return value_ + f;
6666
}
6767

68-
inline float operator+(const float_view& f) const {
68+
float operator+(const float_view& f) const {
6969

7070
return value_ + f.value_;
7171
}
7272

73-
inline float_view& operator+=(float f) {
73+
float_view& operator+=(float f) {
7474

7575
value_ += f;
7676
if (f_) f_.value()();
7777

7878
return *this;
7979
}
8080

81-
inline float operator-(float f) const {
81+
float operator-(float f) const {
8282

8383
return value_ - f;
8484
}
8585

86-
inline float operator-(const float_view& f) const {
86+
float operator-(const float_view& f) const {
8787

8888
return value_ - f.value_;
8989
}
9090

91-
inline float_view& operator-=(float f) {
91+
float_view& operator-=(float f) {
9292

9393
value_ -= f;
9494
if (f_) f_.value()();
9595

9696
return *this;
9797
}
9898

99-
inline float_view& operator++() {
99+
float_view& operator++() {
100100

101101
value_++;
102102
if (f_) f_.value()();
103103

104104
return *this;
105105
}
106106

107-
inline float_view& operator--() {
107+
float_view& operator--() {
108108

109109
value_--;
110110
if (f_) f_.value()();
111111

112112
return *this;
113113
}
114114

115-
inline bool operator==(float other) const {
115+
bool operator==(float other) const {
116116

117117
return value_ == other;
118118
}
119119

120-
inline bool operator!=(float other) const {
120+
bool operator!=(float other) const {
121121

122122
return value_ != other;
123123
}
124124

125-
inline bool operator==(const float_view& other) const {
125+
bool operator==(const float_view& other) const {
126126

127127
return value_ == other.value_;
128128
}
129129

130-
inline bool operator!=(const float_view& other) const {
130+
bool operator!=(const float_view& other) const {
131131

132132
return value_ != other.value_;
133133
}
134134

135-
inline constexpr float_view& clamp(float min, float max) {
135+
constexpr float_view& clamp(float min, float max) {
136136

137137
value_ = std::max(min, std::min(max, value_));
138138

include/threepp/textures/Image.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#ifndef THREEPP_IMAGE_HPP
33
#define THREEPP_IMAGE_HPP
44

5-
#include <memory>
65
#include <utility>
76
#include <variant>
87
#include <vector>

include/threepp/utils/StringUtils.hpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ namespace threepp::utils {
2424
}
2525

2626
template<class ArrayLike>
27-
inline std::string join(const ArrayLike& v, char c = '\n') {
27+
std::string join(const ArrayLike& v, char c = '\n') {
28+
29+
if (v.empty()) return "";
2830

2931
auto p = v.cbegin();
3032
std::stringstream ss;
@@ -39,21 +41,21 @@ namespace threepp::utils {
3941
inline void replaceAll(std::string& text, const std::string& replaceFrom, const std::string& replaceTo) {
4042
std::string& result = text;
4143
size_t start_pos = 0;
42-
while (((start_pos = text.find(replaceFrom, start_pos)) != std::string::npos)) {
44+
while ((start_pos = text.find(replaceFrom, start_pos)) != std::string::npos) {
4345
result.replace(start_pos, replaceFrom.length(), replaceTo);
4446
start_pos += replaceTo.length();
4547
}
4648
}
4749

4850
inline std::string trimStart(std::string s) {
49-
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
51+
s.erase(s.begin(), std::ranges::find_if(s, [](unsigned char ch) {
5052
return !std::isspace(ch);
5153
}));
5254
return s;
5355
}
5456

5557
inline void trimStartInplace(std::string& s) {
56-
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
58+
s.erase(s.begin(), std::ranges::find_if(s, [](unsigned char ch) {
5759
return !std::isspace(ch);
5860
}));
5961
}
@@ -85,13 +87,13 @@ namespace threepp::utils {
8587
}
8688

8789
inline std::string toLower(std::string s) {
88-
std::transform(s.begin(), s.end(), s.begin(),
90+
std::ranges::transform(s, s.begin(),
8991
[](unsigned char c) { return std::tolower(c); });
9092
return s;
9193
}
9294

9395
inline void toLowerInplace(std::string& s) {
94-
std::transform(s.begin(), s.end(), s.begin(),
96+
std::ranges::transform(s, s.begin(),
9597
[](unsigned char c) { return std::tolower(c); });
9698
}
9799

src/threepp/core/EventDispatcher.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ bool EventDispatcher::hasEventListener(const std::string& type, const EventListe
1616
if (!listeners_.contains(type)) return false;
1717

1818
auto& listenerArray = listeners_.at(type);
19-
return std::find(listenerArray.begin(), listenerArray.end(), listener) != listenerArray.end();
19+
return std::ranges::find(listenerArray, listener) != listenerArray.end();
2020
}
2121

2222
void EventDispatcher::removeEventListener(const std::string& type, const EventListener* listener) {
@@ -26,8 +26,7 @@ void EventDispatcher::removeEventListener(const std::string& type, const EventLi
2626
auto& listenerArray = listeners_.at(type);
2727
if (listenerArray.empty()) return;
2828

29-
auto find = std::find(listenerArray.begin(), listenerArray.end(), listener);
30-
if (find != listenerArray.end()) {
29+
if (const auto find = std::ranges::find(listenerArray, listener); find != listenerArray.end()) {
3130
listenerArray.erase(find);
3231
}
3332
}

src/threepp/core/Object3D.cpp

+15-13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include "threepp/lights/Light.hpp"
1212

13+
#include <ranges>
14+
1315
using namespace threepp;
1416

1517
Object3D::Object3D()
@@ -221,26 +223,26 @@ void Object3D::add(Object3D& object) {
221223

222224
void Object3D::remove(Object3D& object) {
223225

224-
{// non-owning (all children should be represented here)
225-
auto find = std::find_if(children.begin(), children.end(), [&object](const auto& obj) {
226+
// non-owning (all children should be represented here)
227+
if (const auto find = std::ranges::find_if(children, [&object](const auto& obj) {
226228
return obj == &object;
227229
});
228-
if (find != children.end()) {
229-
Object3D* child = *find;
230-
children.erase(find);
230+
find != children.end()) {
231231

232-
child->parent = nullptr;
233-
child->dispatchEvent("remove", child);
234-
}
232+
Object3D* child = *find;
233+
children.erase(find);
234+
235+
child->parent = nullptr;
236+
child->dispatchEvent("remove", child);
235237
}
236-
{// owning
237-
auto find = std::find_if(children_.begin(), children_.end(), [&object](const auto& obj) {
238+
239+
// owning
240+
if (const auto find = std::ranges::find_if(children_, [&object](const auto& obj) {
238241
return obj.get() == &object;
239242
});
240-
if (find != children_.end()) {
243+
find != children_.end()) {
241244

242-
children_.erase(find);
243-
}
245+
children_.erase(find);
244246
}
245247
}
246248

src/threepp/input/PeripheralsEventSource.cpp

+5-9
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,34 @@ void PeripheralsEventSource::setIOCapture(IOCapture* capture) {
1010
}
1111

1212
void PeripheralsEventSource::addKeyListener(KeyListener& listener) {
13-
auto find = std::find(keyListeners_.begin(), keyListeners_.end(), &listener);
14-
if (find == keyListeners_.end()) {
13+
if (const auto find = std::ranges::find(keyListeners_, &listener); find == keyListeners_.end()) {
1514
keyListeners_.emplace_back(&listener);
1615
}
1716
}
1817

1918
bool PeripheralsEventSource::removeKeyListener(const KeyListener& listener) {
20-
auto find = std::find(keyListeners_.begin(), keyListeners_.end(), &listener);
21-
if (find != keyListeners_.end()) {
19+
if (const auto find = std::ranges::find(keyListeners_, &listener); find != keyListeners_.end()) {
2220
keyListeners_.erase(find);
2321
return true;
2422
}
2523
return false;
2624
}
2725

2826
void PeripheralsEventSource::addMouseListener(MouseListener& listener) {
29-
auto find = std::find(mouseListeners_.begin(), mouseListeners_.end(), &listener);
30-
if (find == mouseListeners_.end()) {
27+
if (const auto find = std::ranges::find(mouseListeners_, &listener); find == mouseListeners_.end()) {
3128
mouseListeners_.emplace_back(&listener);
3229
}
3330
}
3431

3532
bool PeripheralsEventSource::removeMouseListener(const MouseListener& listener) {
36-
auto find = std::find(mouseListeners_.begin(), mouseListeners_.end(), &listener);
37-
if (find != mouseListeners_.end()) {
33+
if (const auto find = std::ranges::find(mouseListeners_, &listener); find != mouseListeners_.end()) {
3834
mouseListeners_.erase(find);
3935
return true;
4036
}
4137
return false;
4238
}
4339

44-
void PeripheralsEventSource::onMousePressedEvent(int button, const Vector2& pos, PeripheralsEventSource::MouseAction action) {
40+
void PeripheralsEventSource::onMousePressedEvent(int button, const Vector2& pos, MouseAction action) {
4541
if (ioCapture_ && ioCapture_->preventMouseEvent()) return;
4642

4743
auto listeners = mouseListeners_;//copy - IMPORTANT

src/threepp/loaders/MTLLoader.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,23 @@ namespace {
6161
TexParams texParams{.scale = Vector2(1, 1), .offset = Vector2(0, 0)};
6262

6363
auto items = utils::split(value, ' ');
64-
auto pos = std::find(items.begin(), items.end(), "-bm");
64+
auto pos = std::ranges::find(items, "-bm");
6565

6666
if (pos != items.end()) {
6767

6868
params.bumpScale = utils::parseFloat(*(pos + 1));
6969
items.erase(pos, pos + 2);
7070
}
7171

72-
pos = std::find(items.begin(), items.end(), "-s");
72+
pos = std::ranges::find(items, "-s");
7373

7474
if (pos != items.end()) {
7575

7676
texParams.scale.set(utils::parseFloat(*(pos + 1)), utils::parseFloat(*(pos + 2)));
7777
items.erase(pos, pos + 4);
7878
}
7979

80-
pos = std::find(items.begin(), items.end(), "-o");
80+
pos = std::ranges::find(items, "-o");
8181

8282
if (pos != items.end()) {
8383

0 commit comments

Comments
 (0)