Skip to content

Commit d0268aa

Browse files
slope profiling
1 parent d3574f8 commit d0268aa

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

include/Math.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22
#include <cmath>
33
#include "Cell.h"
44
#include <map>
5+
#include <unordered_map>
6+
7+
struct SlopeMetaData
8+
{
9+
directions investigated_direction_;
10+
int altitude_difference_;
11+
bool operator==(const SlopeMetaData &rhs) const
12+
{
13+
return investigated_direction_ == rhs.investigated_direction_ &&
14+
altitude_difference_ == rhs.altitude_difference_;
15+
}
16+
};
17+
18+
template <>
19+
struct std::hash<SlopeMetaData>
20+
{
21+
std::size_t operator()(const SlopeMetaData &key) const
22+
{
23+
size_t h1 = std::hash<int>()(static_cast<int>(key.investigated_direction_));
24+
size_t h2 = std::hash<int>()(key.altitude_difference_);
25+
return h1 ^ (h2 << 1);
26+
}
27+
};
28+
529
class Math
630
{
731
private:
@@ -30,7 +54,7 @@ constexpr int throughPercentage(){
3054
class Math1 final: public Math
3155
{
3256
private:
33-
mutable std::map<double, int> result_slope_;
57+
mutable std::unordered_map<SlopeMetaData, int> result_slope_;
3458
mutable std::map<double, int> result_wind_;
3559
mutable std::map<int, int> result_overall;
3660
double calculateKoef(float windSpeed, double slopeAngleRad) const;

src/Math.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ double Math1::calculateKoef(float windSpeed, double slopeAngleRad) const
2121
double Math1::calculateWindKoef(const cell *c, directions InvestigatedDirection) const
2222
{
2323
auto wind = c->getWind().get();
24-
if (wind == nullptr){
24+
if (wind == nullptr)
25+
{
2526
return double(1);
2627
}
27-
float angleRadians = wind->angleBetweenDirections(InvestigatedDirection);// * pi() / 180;
28+
float angleRadians = wind->angleBetweenDirections(InvestigatedDirection); // * pi() / 180;
2829
double result = std::exp(wind->getWindSpeed() * (cos(angleRadians) - 1));
2930
result_wind_[result]++;
3031
return result;
@@ -43,7 +44,8 @@ double Math1::calculateGroundSlopeKoef(directions InvestigatedDirection, int alt
4344
coef = atan2(static_cast<double>(altitudeDifference), static_cast<double>(cellSizeInMeters() * sqrt(2.0)));
4445
}
4546
double result = std::exp(0.5 * coef);
46-
result_slope_[result]++;
47+
SlopeMetaData meta = {InvestigatedDirection, altitudeDifference};
48+
result_slope_[meta]++;
4749
return result;
4850
}
4951

@@ -65,19 +67,26 @@ bool Math1::willSpreadThroughOne(const cell *c, directions InvestigatedDirection
6567

6668
Math1::~Math1()
6769
{
68-
printf("slope profiling\n");
70+
printf("slope profiling\n");
71+
std::map<int, int> slope_distribution;
6972
for (auto &&i : result_slope_)
7073
{
71-
printf("%2.2f;%d\n",i.first, i.second);
74+
printf("%d,%d;%d\n", i.first.altitude_difference_, static_cast<int>(i.first.investigated_direction_), i.second);
75+
slope_distribution[i.second]++;
76+
}
77+
printf("slope distribution\n");
78+
for (auto &&i : slope_distribution)
79+
{
80+
printf("%d;%d\n", i.first, i.second);
7281
}
73-
printf("wind profiling\n");
82+
printf("wind profiling\n");
7483
for (auto &&i : result_wind_)
7584
{
76-
printf("%2.2f;%d\n",i.first, i.second);
85+
printf("%2.2f;%d\n", i.first, i.second);
7786
}
78-
printf("overall profiling\n");
87+
printf("overall profiling\n");
7988
for (auto &&i : result_overall)
8089
{
81-
printf("%d;%d\n",i.first, i.second);
90+
printf("%d;%d\n", i.first, i.second);
8291
}
8392
}

0 commit comments

Comments
 (0)