header_utils
Loading...
Searching...
No Matches
ellipse.h
1
4
5#pragma once
6
7#include "geometry_common.h"
8#include "shape_concepts.h"
9
10namespace ghassanpl::geometry
11{
12 template <std::floating_point T>
13 struct tellipse
14 {
15 glm::tvec2<T> center;
16 glm::tvec2<T> radii;
17
18 static tellipse inside_rect(trec2<T> const& rec) noexcept
19 {
20 return { rec.center(), rec.half_size() };
21 }
22
23 static tellipse outside_rect(trec2<T> const& rec) noexcept;
24
25 bool contains(glm::tvec2<T> pt) const
26 {
27 const auto d = pt - center;
28 return (d.x * d.x) / (radii.x * radii.x) + (d.y * d.y) / (radii.y * radii.y) <= T(1);
29 }
30
31 T edge_length() const
32 {
35 const auto a = std::max(radii.x, radii.y);
36 const auto b = std::min(radii.x, radii.y);
37 const auto h = ((a - b) * (a - b)) / ((a + b) * (a + b));
38 return glm::pi<T>() * (a + b) * (1 + ((3 * h) / (10 + sqrtf(4 - 3 * h))));
39 }
40
41 glm::tvec2<T> edge_point_alpha(T t) const
42 {
43 throw "unimplemented";
44 }
45
46 T calculate_area() const { return glm::pi<T>() * radii.x * radii.y; }
47 glm::tvec2<T> edge_point(T t) const { return edge_point_alpha(t / edge_length()); }
48 trec2<T> bounding_box() const { return trec2<T>{center - radii, center + radii}; }
49
50 glm::tvec2<T> projected(glm::tvec2<T> pt) const
51 {
53 throw "unimplemented";
54 }
55 };
56
57 using ellipse = tellipse<float>;
58
59 static_assert(area_shape<ellipse, float>);
60}
constexpr auto bit_count
Equal to the number of bits in the type.
Definition bits.h:33
constexpr __contains_fn contains
contains(range, el)
Definition ranges.h:247