Skip to content

Commit 68fa57a

Browse files
Merge branch 'alandefreitas:master' into fix-build-pedantic
2 parents 14216b5 + 2147152 commit 68fa57a

File tree

9 files changed

+520
-52
lines changed

9 files changed

+520
-52
lines changed

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9263,6 +9263,13 @@ If contributing to the documentation, please edit [`README.md`](README.md) direc
92639263
<sub><b>Luis CC!ceres</b></sub>
92649264
</a>
92659265
</td>
9266+
<td align="center">
9267+
<a href="https://github.com/matthew-hennefarth">
9268+
<img src="https://avatars.githubusercontent.com/u/27997339?v=4" width="100;" alt="matthew-hennefarth"/>
9269+
<br />
9270+
<sub><b>matthew-hennefarth</b></sub>
9271+
</a>
9272+
</td>
92669273
<td align="center">
92679274
<a href="https://github.com/actions-user">
92689275
<img src="https://avatars.githubusercontent.com/u/65916846?v=4" width="100;" alt="actions-user"/>
@@ -9276,15 +9283,15 @@ If contributing to the documentation, please edit [`README.md`](README.md) direc
92769283
<br />
92779284
<sub><b>Marcus Asteborg</b></sub>
92789285
</a>
9279-
</td>
9286+
</td></tr>
9287+
<tr>
92809288
<td align="center">
92819289
<a href="https://github.com/Zengit123">
92829290
<img src="https://avatars.githubusercontent.com/u/13079947?v=4" width="100;" alt="Zengit123"/>
92839291
<br />
92849292
<sub><b>Zengit</b></sub>
92859293
</a>
9286-
</td></tr>
9287-
<tr>
9294+
</td>
92889295
<td align="center">
92899296
<a href="https://github.com/madronalabs">
92909297
<img src="https://avatars.githubusercontent.com/u/1434276?v=4" width="100;" alt="madronalabs"/>
@@ -9319,15 +9326,15 @@ If contributing to the documentation, please edit [`README.md`](README.md) direc
93199326
<br />
93209327
<sub><b>Dimitrij Mijoski</b></sub>
93219328
</a>
9322-
</td>
9329+
</td></tr>
9330+
<tr>
93239331
<td align="center">
93249332
<a href="https://github.com/MaBnt">
93259333
<img src="https://avatars.githubusercontent.com/u/28400222?v=4" width="100;" alt="MaBnt"/>
93269334
<br />
93279335
<sub><b>MaBnt</b></sub>
93289336
</a>
9329-
</td></tr>
9330-
<tr>
9337+
</td>
93319338
<td align="center">
93329339
<a href="https://github.com/kaffehalv">
93339340
<img src="https://avatars.githubusercontent.com/u/33203776?v=4" width="100;" alt="kaffehalv"/>

docs/examples/vector_fields/quiver/quiver_6.svg

Lines changed: 144 additions & 0 deletions
Loading
11.8 KB
Loading

docs/examples/vector_fields/quiver3/quiver3_2.svg

Lines changed: 309 additions & 0 deletions
Loading
12.5 KB
Loading

source/matplot/axes_objects/vectors.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ namespace matplot {
4141
const std::vector<double> &y_data,
4242
const std::vector<double> &u_data,
4343
const std::vector<double> &v_data,
44-
const std::vector<double> &m_data,
44+
const std::vector<double> &c_data,
4545
std::string_view line_spec)
4646
: axes_object(parent), line_spec_(this, line_spec), y_data_(y_data),
47-
x_data_(x_data), u_data_(u_data), v_data_(v_data), m_data_(m_data) {}
47+
x_data_(x_data), u_data_(u_data), v_data_(v_data), c_data_(c_data) {}
4848

4949
vectors::vectors(class axes_type *parent, const std::vector<double> &x_data,
5050
const std::vector<double> &y_data,
@@ -63,20 +63,20 @@ namespace matplot {
6363
const std::vector<double> &u_data,
6464
const std::vector<double> &v_data,
6565
const std::vector<double> &w_data,
66-
const std::vector<double> &m_data,
66+
const std::vector<double> &c_data,
6767
std::string_view line_spec)
6868
: axes_object(parent), line_spec_(this, line_spec), y_data_(y_data),
6969
x_data_(x_data), z_data_(z_data), u_data_(u_data), v_data_(v_data),
70-
w_data_(w_data), m_data_(m_data) {}
70+
w_data_(w_data), c_data_(c_data) {}
7171

7272
std::string vectors::plot_string() {
7373
maybe_update_line_spec();
7474
std::stringstream ss;
7575
ss << " '-' with vectors";
76-
if (!m_data_.empty()) {
76+
if (!c_data_.empty()) {
7777
ss << " linecolor palette";
7878
ss << " linewidth " << line_spec_.line_width();
79-
79+
8080
switch (line_spec_.line_style()) {
8181
case line_spec::line_style::solid_line:
8282
ss << " dashtype 1";
@@ -123,7 +123,7 @@ namespace matplot {
123123
double u_value = u_data_.size() > i ? u_data_[i] : 0;
124124
double v_value = v_data_.size() > i ? v_data_[i] : 0;
125125
double w_value = w_data_.size() > i ? w_data_[i] : 0;
126-
double m_value = m_data_.size() > i ? m_data_[i] : 0;
126+
double c_value = c_data_.size() > i ? c_data_[i] : 0;
127127

128128
bool is_end_of_series =
129129
!std::isfinite(x_value) || !std::isfinite(y_value) ||
@@ -143,11 +143,19 @@ namespace matplot {
143143
}
144144

145145
if (normalize_) {
146-
double mag = sqrt(u_value * u_value + v_value * v_value +
147-
w_value * w_value);
148-
u_value *= scale_ / mag;
149-
v_value *= scale_ / mag;
150-
w_value *= scale_ / mag;
146+
double mag =
147+
std::sqrt(u_value * u_value + v_value * v_value +
148+
w_value * w_value);
149+
if (mag != 0.0) {
150+
u_value /= mag;
151+
v_value /= mag;
152+
w_value /= mag;
153+
}
154+
if (scale_ != 0.0) {
155+
u_value *= scale_;
156+
v_value *= scale_;
157+
w_value *= scale_;
158+
}
151159
}
152160

153161
ss << " " << u_value;
@@ -157,8 +165,8 @@ namespace matplot {
157165
} else if (parent_->is_3d()) {
158166
ss << " " << 0.0;
159167
}
160-
if (!m_data_.empty()) {
161-
ss << " " << m_value;
168+
if (!c_data_.empty()) {
169+
ss << " " << c_value;
162170
}
163171

164172
ss << "\n";
@@ -179,7 +187,7 @@ namespace matplot {
179187
}
180188

181189
void vectors::maybe_update_line_spec() {
182-
if (!line_spec_.user_color() && m_data_.empty()) {
190+
if (!line_spec_.user_color() && c_data_.empty()) {
183191
auto c = parent_->get_color_and_bump();
184192
line_spec_.color(c);
185193
} else if (line_spec_.has_non_custom_marker() &&

source/matplot/axes_objects/vectors.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ namespace matplot {
4545
const std::vector<double> &v_data,
4646
std::string_view line_spec = "");
4747

48-
/// \brief Create 2D vectors with custom origin and magnitude colors
48+
/// \brief Create 2D vectors with custom origin and colors
4949
vectors(class axes_type *parent, const std::vector<double> &x_data,
5050
const std::vector<double> &y_data,
5151
const std::vector<double> &u_data,
5252
const std::vector<double> &v_data,
53-
const std::vector<double> &m_data,
53+
const std::vector<double> &c_data,
5454
std::string_view line_spec = "");
5555

5656
/// \brief Create 3D vectors with custom origin
@@ -62,14 +62,14 @@ namespace matplot {
6262
const std::vector<double> &w_data,
6363
std::string_view line_spec = "");
6464

65-
/// \brief Create 3D vectors with custom origin and magnitude colors
65+
/// \brief Create 3D vectors with custom origin and colors
6666
vectors(class axes_type *parent, const std::vector<double> &x_data,
6767
const std::vector<double> &y_data,
6868
const std::vector<double> &z_data,
6969
const std::vector<double> &u_data,
7070
const std::vector<double> &v_data,
7171
const std::vector<double> &w_data,
72-
const std::vector<double> &m_data,
72+
const std::vector<double> &c_data,
7373
std::string_view line_spec = "");
7474

7575
/// If we receive an axes_handle, we can convert it to a raw
@@ -224,8 +224,8 @@ namespace matplot {
224224
std::vector<double> v_data_{};
225225
std::vector<double> w_data_{};
226226

227-
/// Vector magnitude
228-
std::vector<double> m_data_{};
227+
/// Vector color mapping values
228+
std::vector<double> c_data_{};
229229

230230
/// Positions at which we want markers to appear
231231
std::vector<size_t> marker_indices_{};

source/matplot/core/axes_type.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4526,7 +4526,7 @@ namespace matplot {
45264526
const std::vector<double> &y,
45274527
const std::vector<double> &u,
45284528
const std::vector<double> &v,
4529-
const std::vector<double> &m, double scale,
4529+
const std::vector<double> &c, double scale,
45304530
std::string_view line_spec) {
45314531
axes_silencer temp_silencer_{this};
45324532

@@ -4562,7 +4562,7 @@ namespace matplot {
45624562
: v;
45634563

45644564
vectors_handle l = std::make_shared<class vectors>(
4565-
this, x, y, u_scaled, v_scaled, m, line_spec);
4565+
this, x, y, u_scaled, v_scaled, c, line_spec);
45664566
l->scale(scale);
45674567
this->emplace_object(l);
45684568
return l;
@@ -4573,14 +4573,14 @@ namespace matplot {
45734573
const std::vector<std::vector<double>> &y,
45744574
const std::vector<std::vector<double>> &u,
45754575
const std::vector<std::vector<double>> &v,
4576-
const std::vector<std::vector<double>> &m,
4576+
const std::vector<std::vector<double>> &c,
45774577
double scale, std::string_view line_spec) {
45784578
return this->quiver(flatten(x), flatten(y), flatten(u), flatten(v),
4579-
(m.empty()) ? std::vector<double>{} : flatten(m),
4579+
(c.empty()) ? std::vector<double>{} : flatten(c),
45804580
scale, line_spec);
45814581
}
45824582

4583-
/// Quiver - 2d x,y,u,v with no magnitude
4583+
/// Quiver - 2d x,y,u,v with no color mapping
45844584
vectors_handle axes_type::quiver(const std::vector<std::vector<double>> &x,
45854585
const std::vector<std::vector<double>> &y,
45864586
const std::vector<std::vector<double>> &u,
@@ -4590,7 +4590,7 @@ namespace matplot {
45904590
scale, line_spec);
45914591
}
45924592

4593-
/// Quiver - x,y,u,v with magnitude
4593+
/// Quiver - x,y,u,v
45944594
vectors_handle axes_type::quiver(const std::vector<double> &x,
45954595
const std::vector<double> &y,
45964596
const std::vector<double> &u,
@@ -4605,7 +4605,7 @@ namespace matplot {
46054605
const std::vector<double> &x, const std::vector<double> &y,
46064606
const std::vector<double> &z, const std::vector<double> &u,
46074607
const std::vector<double> &v, const std::vector<double> &w,
4608-
const std::vector<double> &m, double scale,
4608+
const std::vector<double> &c, double scale,
46094609
std::string_view line_spec) {
46104610
axes_silencer temp_silencer_{this};
46114611

@@ -4656,7 +4656,7 @@ namespace matplot {
46564656
: w;
46574657

46584658
vectors_handle l = std::make_shared<class vectors>(
4659-
this, x, y, z, u_scaled, v_scaled, w_scaled, m, line_spec);
4659+
this, x, y, z, u_scaled, v_scaled, w_scaled, c, line_spec);
46604660
l->scale(scale);
46614661
this->emplace_object(l);
46624662

@@ -4670,16 +4670,16 @@ namespace matplot {
46704670
const std::vector<std::vector<double>> &u,
46714671
const std::vector<std::vector<double>> &v,
46724672
const std::vector<std::vector<double>> &w,
4673-
const std::vector<std::vector<double>> &m,
4673+
const std::vector<std::vector<double>> &c,
46744674
double scale,
46754675
std::string_view line_spec) {
46764676
return this->quiver3(flatten(x), flatten(y), flatten(z), flatten(u),
46774677
flatten(v), flatten(w),
4678-
(m.empty()) ? std::vector<double>{} : flatten(m),
4678+
(c.empty()) ? std::vector<double>{} : flatten(c),
46794679
scale, line_spec);
46804680
}
46814681

4682-
/// Quiver 3d - 2d vectors with no magnitude
4682+
/// Quiver 3d - 2d vectors with no color mapping
46834683
vectors_handle axes_type::quiver3(const std::vector<std::vector<double>> &x,
46844684
const std::vector<std::vector<double>> &y,
46854685
const std::vector<std::vector<double>> &z,
@@ -4697,17 +4697,17 @@ namespace matplot {
46974697
const std::vector<std::vector<double>> &u,
46984698
const std::vector<std::vector<double>> &v,
46994699
const std::vector<std::vector<double>> &w,
4700-
const std::vector<std::vector<double>> &m,
4700+
const std::vector<std::vector<double>> &c,
47014701
double scale,
47024702
std::string_view line_spec) {
47034703
auto [n, p] = size(z);
47044704
vector_1d x = iota(1., static_cast<double>(p));
47054705
vector_1d y = iota(1., static_cast<double>(n));
47064706
auto [xx, yy] = meshgrid(x, y);
4707-
return this->quiver3(xx, yy, z, u, v, w, m, scale, line_spec);
4707+
return this->quiver3(xx, yy, z, u, v, w, c, scale, line_spec);
47084708
}
47094709

4710-
/// Quiver 3d - Automatic x and y - 2d vectors no magnitude
4710+
/// Quiver 3d - Automatic x and y - 2d vectors no color mapping
47114711
vectors_handle axes_type::quiver3(const std::vector<std::vector<double>> &z,
47124712
const std::vector<std::vector<double>> &u,
47134713
const std::vector<std::vector<double>> &v,
@@ -4718,7 +4718,7 @@ namespace matplot {
47184718
scale, line_spec);
47194719
}
47204720

4721-
/// Quiver 3d - no magnitude
4721+
/// Quiver 3d - no color mapping
47224722
vectors_handle axes_type::quiver3(
47234723
const std::vector<double> &x, const std::vector<double> &y,
47244724
const std::vector<double> &z, const std::vector<double> &u,

source/matplot/core/axes_type.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,27 +1409,27 @@ namespace matplot {
14091409
const std::vector<double> &y,
14101410
const std::vector<double> &u,
14111411
const std::vector<double> &v,
1412-
const std::vector<double> &m, double scale = 1.0,
1412+
const std::vector<double> &c, double scale = 1.0,
14131413
std::string_view line_spec = "");
14141414

14151415
/// Quiver - 2d x,y,u,v
14161416
vectors_handle quiver(const std::vector<std::vector<double>> &x,
14171417
const std::vector<std::vector<double>> &y,
14181418
const std::vector<std::vector<double>> &u,
14191419
const std::vector<std::vector<double>> &v,
1420-
const std::vector<std::vector<double>> &m,
1420+
const std::vector<std::vector<double>> &c,
14211421
double scale = 1.0,
14221422
std::string_view line_spec = "");
14231423

1424-
/// Quiver - 2d x,y,u,v with no magnitude
1424+
/// Quiver - 2d x,y,u,v with no color mapping
14251425
vectors_handle quiver(const std::vector<std::vector<double>> &x,
14261426
const std::vector<std::vector<double>> &y,
14271427
const std::vector<std::vector<double>> &u,
14281428
const std::vector<std::vector<double>> &v,
14291429
double scale = 1.0,
14301430
std::string_view line_spec = "");
14311431

1432-
/// Quiver - x,y,u,v with no magnitude
1432+
/// Quiver - x,y,u,v with no color mapping
14331433
vectors_handle quiver(const std::vector<double> &x,
14341434
const std::vector<double> &y,
14351435
const std::vector<double> &u,
@@ -1441,7 +1441,7 @@ namespace matplot {
14411441
quiver3(const std::vector<double> &x, const std::vector<double> &y,
14421442
const std::vector<double> &z, const std::vector<double> &u,
14431443
const std::vector<double> &v, const std::vector<double> &w,
1444-
const std::vector<double> &m, double scale = 1.0,
1444+
const std::vector<double> &c, double scale = 1.0,
14451445
std::string_view line_spec = "");
14461446

14471447
/// Quiver 3d - 2d vectors
@@ -1451,11 +1451,11 @@ namespace matplot {
14511451
const std::vector<std::vector<double>> &u,
14521452
const std::vector<std::vector<double>> &v,
14531453
const std::vector<std::vector<double>> &w,
1454-
const std::vector<std::vector<double>> &m,
1454+
const std::vector<std::vector<double>> &c,
14551455
double scale = 1.0,
14561456
std::string_view line_spec = "");
14571457

1458-
/// Quiver 3d - 2d vectors no magnitude
1458+
/// Quiver 3d - 2d vectors no color mapping
14591459
vectors_handle quiver3(const std::vector<std::vector<double>> &x,
14601460
const std::vector<std::vector<double>> &y,
14611461
const std::vector<std::vector<double>> &z,
@@ -1470,19 +1470,19 @@ namespace matplot {
14701470
const std::vector<std::vector<double>> &u,
14711471
const std::vector<std::vector<double>> &v,
14721472
const std::vector<std::vector<double>> &w,
1473-
const std::vector<std::vector<double>> &m,
1473+
const std::vector<std::vector<double>> &c,
14741474
double scale = 1.0,
14751475
std::string_view line_spec = "");
14761476

1477-
/// Quiver 3d - Automatic x and y - 2d vectors no magnitude
1477+
/// Quiver 3d - Automatic x and y - 2d vectors no color mapping
14781478
vectors_handle quiver3(const std::vector<std::vector<double>> &z,
14791479
const std::vector<std::vector<double>> &u,
14801480
const std::vector<std::vector<double>> &v,
14811481
const std::vector<std::vector<double>> &w,
14821482
double scale = 1.0,
14831483
std::string_view line_spec = "");
14841484

1485-
/// Quiver 3d - no magnitude
1485+
/// Quiver 3d - no color mapping
14861486
vectors_handle
14871487
quiver3(const std::vector<double> &x, const std::vector<double> &y,
14881488
const std::vector<double> &z, const std::vector<double> &u,

0 commit comments

Comments
 (0)