Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
minimum_enclosing_circle_example.cc
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
44# include <geom_algorithms.H>
45
46# include <cassert>
47# include <iostream>
48
49using namespace Aleph;
50using namespace std;
51
52static void print_banner(const char * title)
53{
54 cout << "[Aleph Geometry Example] " << title << "\n";
55 cout << "============================================================\n";
56}
57
58int main()
59{
60 print_banner("Minimum Enclosing Circle");
61
63 pts.append(Point(0, 0));
64 pts.append(Point(5, 2));
65 pts.append(Point(9, 8));
66 pts.append(Point(3, 4));
67 pts.append(Point(4, 4));
68 pts.append(Point(8, 1));
69 pts.append(Point(7, 7));
70 pts.append(Point(1, 6));
71
73 const auto circle = mec(pts);
74
75 cout << "Center: (" << circle.center.get_x() << ", "
76 << circle.center.get_y() << ")" << endl;
77 cout << "Radius: " << circle.radius() << endl;
78 cout << "Radius^2: " << circle.radius_squared << endl;
79
80 // Verify all points are inside
81 bool all_inside = true;
82 for (DynList<Point>::Iterator it(pts); it.has_curr(); it.next_ne())
83 {
84 const Point & p = it.get_curr();
85 const bool inside = circle.contains(p);
86 cout << " (" << p.get_x() << ", " << p.get_y() << ") -> "
87 << (inside ? "inside" : "OUTSIDE") << endl;
88 if (not inside)
89 all_inside = false;
90 }
91
93 cout << "All points contained: YES" << endl;
94
95 // Test with initializer list
96 const auto c2 = mec({Point(0, 0), Point(4, 0), Point(4, 4), Point(0, 4)});
97 cout << "\nSquare test: center = (" << c2.center.get_x() << ", "
98 << c2.center.get_y() << "), radius = " << c2.radius() << endl;
99 assert(c2.center == Point(2, 2));
100 assert(c2.radius_squared == 8);
101
102 cout << "STATUS: OK" << endl;
103 return 0;
104}
Iterator on the items of list.
Definition htlist.H:1420
Dynamic singly linked list with functional programming support.
Definition htlist.H:1155
T & append(const T &item)
Definition htlist.H:1271
bool has_curr() const noexcept
Definition htlist.H:930
Smallest circle enclosing a point set (Welzl's algorithm).
Represents a point with rectangular coordinates in a 2D plane.
Definition point.H:229
const Geom_Number & get_x() const noexcept
Gets the x-coordinate value.
Definition point.H:457
const Geom_Number & get_y() const noexcept
Gets the y-coordinate value.
Definition point.H:466
Computational geometry algorithms.
static void print_banner(const char *title)
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
STL namespace.