acme
Foundational cross-platform layer of the ca2 framework
Toggle main menu visibility
Loading...
Searching...
No Matches
ellipse.h
1
#pragma once
2
3
4
#include "contains.h"
5
#include "rectangle.h"
6
7
8
template
< prototype_number NUMBER >
9
class
ellipse_type :
10
public
::rectangle_type < NUMBER >
11
{
12
public
:
13
14
15
ellipse_type() {}
16
template
< prototype_number NUMBER2 >
17
ellipse_type(
const
ellipse_type < NUMBER2 > & ellipse)
18
{
19
20
21
22
}
23
24
25
void
set(const ::rectangle_type < NUMBER > & rectangle) { ::rectangle_type < NUMBER >::operator =(rectangle); }
26
27
auto
radius()
const
{
return
this->size() / (NUMBER) 2; }
28
29
static
bool
contains(const ::point_type < NUMBER > & center, const ::size_type < NUMBER > & radius,
30
const ::point_type < NUMBER > & point)
31
32
{
33
34
if
(radius.is_empty())
35
{
36
37
return
false
;
38
39
}
40
41
::f64 x = point.x;
42
43
::f64 y = point.y;
44
45
::f64 Δx = x - center.x;
46
47
::f64 Δy = y - center.y;
48
49
if
(radius.cx == radius.cy)
50
{
51
52
::f64 r = radius.cx;
53
54
::f64 square_distance = (Δx * Δx) + (Δy * Δy);
55
56
::f64 square_boundary = (r * r);
57
58
return
square_distance <= square_boundary;
59
60
}
61
else
62
{
63
64
::f64 normal_distance = ((Δx * Δx) / (radius.cx * radius.cx) + (Δy * Δy) / (radius.cx * radius.cy));
65
66
return
normal_distance <= 1.0;
67
68
}
69
70
}
71
72
73
bool
contains(const ::point_type < NUMBER > & point)
74
{
75
76
if
(!::rectangle_type < NUMBER >::contains(point))
77
{
78
79
return
false
;
80
81
}
82
83
auto
center = this->center();
84
85
auto
radius = this->radius();
86
87
if
(!contains(center, radius, point))
88
{
89
90
return
false
;
91
92
}
93
94
return
true
;
95
96
}
97
98
99
};
100
101
102
103
prototype
geometry2d
ellipse.h
Generated by
1.17.0