HighMap library (C++)
Loading...
Searching...
No Matches
coord_frame.hpp
Go to the documentation of this file.
1/* Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU General
2 Public License. The full license is in the file LICENSE, distributed with
3 this software. */
4
12#pragma once
13#include <cmath>
14#include <map>
15#include <vector>
16
17#include "highmap/algebra.hpp"
19
20namespace hmap
21{
22
28{
29 float ax = 1.f;
30 float bx = 0.f;
31 float cx = 0.f;
32 float ay = 0.f;
33 float by = 1.f;
34 float cy = 0.f;
35
36 glm::vec2 apply(float x, float y) const;
37};
38
40{
41public:
42 CoordFrame();
43
44 CoordFrame(glm::vec2 origin, glm::vec2 size, float rotation_angle);
45
46 // Getters
47 glm::vec2 get_origin() const;
48
49 glm::vec2 get_size() const;
50
51 float get_rotation_angle() const;
52
53 // Setters
54 void set_origin(glm::vec2 new_origin);
55
56 void set_size(glm::vec2 new_size);
57
58 void set_rotation_angle(float new_angle);
59
60 // Methods
61
63
65 {
66 return compute_bounding_box();
67 }
68
69 bool intersects(const CoordFrame &other) const;
70
71 bool is_point_within(float gx, float gy) const;
72
73 bool is_unit_point_within(float rx, float ry) const;
74
76
77 glm::vec2 map_to_global_coords(float rx, float ry) const;
78
79 // relative coords always in [0, 1] x [0, 1] (unit square)
80 glm::vec2 map_to_relative_coords(float gx, float gy) const;
81
82 glm::vec2 map_to_relative_coords(const CoordFrame &other,
83 float rx,
84 float ry) const;
85
86 float normalized_distance_to_edges(float gx, float gy) const;
87
88 float normalized_shape_factor(float gx, float gy) const;
89
90 float normalized_shape_factor_rel(float rx, float ry) const;
91
92private:
93 glm::vec2 origin;
94 glm::vec2 size;
95 float rotation_angle;
96
97 float cos_angle;
98 float sin_angle;
99};
100
101} // namespace hmap
Header file defining basic vector and matrix manipulation classes.
Axis-aligned 2D bounding box in world coordinates.
Definition coord_frame.hpp:40
void set_origin(glm::vec2 new_origin)
Definition coord_frame.cpp:110
void set_rotation_angle(float new_angle)
Definition coord_frame.cpp:144
glm::vec2 map_to_global_coords(float rx, float ry) const
Definition coord_frame.cpp:154
void set_size(glm::vec2 new_size)
Definition coord_frame.cpp:115
bool intersects(const CoordFrame &other) const
Definition coord_frame.cpp:121
bool is_point_within(float gx, float gy) const
Definition coord_frame.cpp:130
float normalized_shape_factor_rel(float rx, float ry) const
Definition coord_frame.cpp:210
AffineTransform2D compute_relative_transform(const CoordFrame &other) const
Definition coord_frame.cpp:60
glm::vec2 get_size() const
Definition coord_frame.cpp:100
glm::vec2 get_origin() const
Definition coord_frame.cpp:95
CoordFrame()
Definition coord_frame.cpp:20
float normalized_shape_factor(float gx, float gy) const
Definition coord_frame.cpp:202
BBox2D compute_bbox() const
Definition coord_frame.hpp:64
bool is_unit_point_within(float rx, float ry) const
Definition coord_frame.cpp:138
BBox2D compute_bounding_box() const
Definition coord_frame.cpp:32
glm::vec2 map_to_relative_coords(float gx, float gy) const
Definition coord_frame.cpp:166
float get_rotation_angle() const
Definition coord_frame.cpp:105
float normalized_distance_to_edges(float gx, float gy) const
Definition coord_frame.cpp:190
Definition opencv.hpp:20
Lightweight 2D affine transformation mapping (x, y) -> (ax*x + bx*y + cx, ay*x + by*y + cy).
Definition coord_frame.hpp:28
float cy
Definition coord_frame.hpp:34
float cx
Definition coord_frame.hpp:31
float bx
Definition coord_frame.hpp:30
glm::vec2 apply(float x, float y) const
Definition coord_frame.cpp:14
float by
Definition coord_frame.hpp:33
float ay
Definition coord_frame.hpp:32
float ax
Definition coord_frame.hpp:29
Axis-aligned 2D bounding box in world coordinates.
Definition bbox2d.hpp:25