Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- struct Point {
- double x;
- double y;
- Point() = default;
- Point(double _x, double _y) : x(_x),
- y(_y) {}
- };
- struct Polygon {
- std::vector<Point> points;
- Polygon() = default;
- explicit Polygon(std::vector<Point> &_points) : points(_points) {}
- Polygon(std::initializer_list<Point> &_points) : points(_points) {}
- };
- typedef Polygon Path;
- struct Graph {
- private:
- std::vector<Point> points;
- std::vector<std::vector<int> > g;
- std::vector<int> p; //used in dfs
- std::vector<int> used; // used in dfs
- void dfs(int v) {
- used[v] = true;
- for (auto u : g[v]) {
- if (!used[u]) {
- p[u] = v;
- dfs(v);
- }
- }
- }
- public:
- Graph() = default;
- /* finds path in graph. Returns empty path if and only if path doesn't exist */
- Path find_path(int s, int t) {
- size_t n = points.size();
- p.assign(n, -1);
- used.assign(n, false);
- Path ans;
- dfs(s);
- if (p[t] == -1) {
- return ans;
- }
- int cur = t;
- while (cur != s) {
- ans.points.emplace_back(points[cur]);
- cur = p[cur];
- }
- ans.points.emplace_back(points[cur]);
- return ans;
- }
- };
- class Map {
- private:
- std::vector<Polygon> hedges;
- double height;
- double width;
- public:
- Map() : height(0), width(0), hedges() {}
- Map(std::initializer_list<Polygon> &_hedges, double _height, double _width) : hedges(_hedges),
- height(_height),
- width(_width) {}
- Map(std::vector<Polygon> &_hedges, double _height, double _width) : hedges(_hedges),
- height(_height),
- width(_width) {}
- Map(double _height, double _width) : height(_height), width(_width) {}
- Graph make_graph() {
- //making graph
- }
- Path find_path(Point a, Point b) {
- //finding path in graph
- }
- };
- int main() {
- Map map(480, 960);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement