FireSTARR
Loading...
Searching...
No Matches
CellPoints.h
1/* Copyright (c) Jordan Evens, 2005, 2021 */
2/* Copyright (c) Queen's Printer for Ontario, 2020. */
3/* Copyright (c) His Majesty the King in Right of Canada as represented by the Minister of Natural Resources, 2021-2025. */
4
5/* SPDX-License-Identifier: AGPL-3.0-or-later */
6
7#pragma once
8#include "stdafx.h"
9#include "InnerPos.h"
10#include "IntensityMap.h"
11
12namespace fs::sim
13{
15// using sim::CellPoints;
16using topo::Cell;
17using topo::SpreadKey;
18class SpreadData : std::tuple<DurationSize, IntensitySize, ROSSize, Direction, Direction>
19{
20public:
21 using std::tuple<DurationSize, IntensitySize, ROSSize, Direction, Direction>::tuple;
22 DurationSize time() const
23 {
24 return std::get<0>(*this);
25 }
26 IntensitySize intensity() const
27 {
28 return std::get<1>(*this);
29 }
30 ROSSize ros() const
31 {
32 return std::get<2>(*this);
33 }
34 Direction direction() const
35 {
36 return std::get<3>(*this);
37 }
38 Direction direction_previous() const
39 {
40 return std::get<4>(*this);
41 }
42};
43
44static constexpr size_t FURTHEST_N = 0;
45static constexpr size_t FURTHEST_NNE = 1;
46static constexpr size_t FURTHEST_NE = 2;
47static constexpr size_t FURTHEST_ENE = 3;
48static constexpr size_t FURTHEST_E = 4;
49static constexpr size_t FURTHEST_ESE = 5;
50static constexpr size_t FURTHEST_SE = 6;
51static constexpr size_t FURTHEST_SSE = 7;
52static constexpr size_t FURTHEST_S = 8;
53static constexpr size_t FURTHEST_SSW = 9;
54static constexpr size_t FURTHEST_SW = 10;
55static constexpr size_t FURTHEST_WSW = 11;
56static constexpr size_t FURTHEST_W = 12;
57static constexpr size_t FURTHEST_WNW = 13;
58static constexpr size_t FURTHEST_NW = 14;
59static constexpr size_t FURTHEST_NNW = 15;
60static constexpr size_t NUM_DIRECTIONS = 16;
61
62static constexpr auto MASK_NE = DIRECTION_N & DIRECTION_NE & DIRECTION_E;
63static constexpr auto MASK_SE = DIRECTION_S & DIRECTION_SE & DIRECTION_E;
64static constexpr auto MASK_SW = DIRECTION_S & DIRECTION_SW & DIRECTION_W;
65static constexpr auto MASK_NW = DIRECTION_N & DIRECTION_NW & DIRECTION_W;
66// mask of sides that would need to be burned for direction to not matter
67static constexpr std::array<CellIndex, NUM_DIRECTIONS> DIRECTION_MASKS{
68 DIRECTION_N,
69 MASK_NE,
70 MASK_NE,
71 MASK_NE,
72 DIRECTION_E,
73 MASK_SE,
74 MASK_SE,
75 MASK_SE,
76 DIRECTION_S,
77 MASK_SW,
78 MASK_SW,
79 MASK_SW,
80 DIRECTION_W,
81 MASK_NW,
82 MASK_NW,
83 MASK_NW};
84
85class CellPointsMap;
86// using dist_pt = pair<DistanceSize, InnerPos>;
87// using array_cellpts = std::array<dist_pt, NUM_DIRECTIONS>;
88using array_dists = std::array<DistanceSize, NUM_DIRECTIONS>;
89using array_pts = std::array<InnerPos, NUM_DIRECTIONS>;
90// using array_cellpts = pair<CellPoints::array_dists, CellPoints::array_pts>;
91using array_dirs = std::array<MathSize, NUM_DIRECTIONS>;
92using array_cellpts = std::tuple<array_dists, array_pts, array_dirs>;
93// using array_cellpts = std::array<DistanceSize, NUM_DIRECTIONS>;
95 : public array_cellpts
96{
97public:
98 using array_cellpts::array_cellpts;
99 inline const array_dists& distances() const
100 {
101 return std::get<0>(*this);
102 }
103 inline const array_pts& points() const
104 {
105 return std::get<1>(*this);
106 }
107 inline const array_dirs& directions() const
108 {
109 return std::get<2>(*this);
110 }
111 inline array_dists& distances()
112 {
113 return std::get<0>(*this);
114 }
115 inline array_pts& points()
116 {
117 return std::get<1>(*this);
118 }
119 inline array_dirs& directions()
120 {
121 return std::get<2>(*this);
122 }
123};
128{
129public:
130 using spreading_points = map<SpreadKey, vector<pair<Location, CellPoints>>>;
131 CellPoints() noexcept;
132 // // HACK: so we can emplace with NULL
133 // CellPoints(size_t) noexcept;
134 // HACK: so we can emplace with nullptr
135 CellPoints(const CellPoints* rhs) noexcept;
136 // CellPoints(const vector<InnerPos>& pts) noexcept;
138 const XYPos& src,
139 const SpreadData& spread_current,
140 const XYSize x,
141 const XYSize y) noexcept;
142 CellPoints(CellPoints&& rhs) noexcept = default;
143 CellPoints(const CellPoints& rhs) noexcept = default;
144 CellPoints& operator=(CellPoints&& rhs) noexcept = default;
145 CellPoints& operator=(const CellPoints& rhs) noexcept = default;
146 CellPoints& insert(
147 const XYPos& src,
148 const SpreadData& spread_current,
149 const XYSize x,
150 const XYSize y) noexcept;
151 CellPoints& insert(const InnerPos& p) noexcept;
152 // template <class _ForwardIterator>
153 // CellPoints& insert(_ForwardIterator begin, _ForwardIterator end)
154 // {
155 // // don't do anything if empty
156 // if (end != begin)
157 // {
158 // auto it = begin;
159 // while (end != it)
160 // {
161 // (*it);
162 // ++it;
163 // }
164 // }
165 // return *this;
166 // }
167 void add_source(const CellIndex src);
168 CellIndex sources() const
169 {
170 return src_;
171 }
172 CellPoints& merge(const CellPoints& rhs);
173 set<XYPos> unique() const noexcept;
174#ifdef DEBUG_CELLPOINTS
175 size_t size() const noexcept;
176#endif
177 bool operator<(const CellPoints& rhs) const noexcept;
178 bool operator==(const CellPoints& rhs) const noexcept;
179 [[nodiscard]] Location location() const noexcept;
180 void clear();
181 // const array_pts points() const;
182 bool empty() const;
183 SpreadData spread_arrival_;
184 SpreadData spread_internal_;
185 SpreadData spread_exit_;
186 // DurationSize arrival_time_;
187 // IntensitySize intensity_at_arrival_;
188 // ROSSize ros_at_arrival_;
189 // Direction raz_at_arrival_;
190 // friend CellPointsMap;
191 // FIX: just access directly for now
192public:
193 CellPointArrays pts_;
194 // use Idx instead of Location so it can be negative (invalid)
195 CellPos cell_x_y_;
196 CellIndex src_;
197private:
198 CellPoints(const Idx cell_x, const Idx cell_y) noexcept;
199 CellPoints(const XYPos& p) noexcept;
200};
201
202using spreading_points = CellPoints::spreading_points;
203class Scenario;
204// map that merges items when try_emplace doesn't insert
206{
207public:
209 // CellPoints& insert(
210 // const DurationSize& arrival_time,
211 // const IntensitySize intensity,
212 // const ROSSize& ros,
213 // const Direction& raz,
214 // const XYSize x,
215 // const XYSize y) noexcept;
216 CellPoints& insert(
217 const XYPos& src,
218 const SpreadData& spread_current,
219 const XYSize x,
220 const XYSize y) noexcept;
221 CellPointsMap& merge(
222 const BurnedData& unburnable,
223 const CellPointsMap& rhs) noexcept;
224 set<XYPos> unique() const noexcept;
225#ifdef DEBUG_CELLPOINTS
226 size_t size() const noexcept;
227#endif
228 // apply function to each CellPoints within and remove matches
229 void remove_if(std::function<bool(const pair<Location, CellPoints>&)> F) noexcept;
230 // FIX: public for debugging right now
231 // private:
232 map<Location, CellPoints> map_;
233};
234}
Definition CellPoints.h:96
Definition CellPoints.h:206
Definition CellPoints.h:128
The position within the Environment that a spreading point has.
Definition InnerPos.h:81
The position within a Cell that a spreading point has.
Definition InnerPos.h:59
A single Scenario in an Iteration using a specific FireWeather stream.
Definition Scenario.h:38
Definition CellPoints.h:19
The position within the Environment that a spreading point has.
Definition InnerPos.h:67
Definition Location.h:229
Direction with access to degrees or radians.
Definition Weather.h:64