Skip to content

Commit c08e4f9

Browse files
committed
fix Rect documentation
1 parent 7666b0a commit c08e4f9

File tree

4 files changed

+48
-18
lines changed

4 files changed

+48
-18
lines changed

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ This file is a list of ideas for gf. Some of them will eventually be in gf. Othe
44

55
## core
66

7-
- (rect) fix the documentation
87
- (geometry) add more algorithms from [here](http://geomalgorithms.com/algorithms.html)
98
- (spatial) add linear and quadratic RTree
109
- (color) color interpolation (and color space)

docs/snippets/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ add_executable(gfdev_core_doc
1313
doc_class_clock.cc
1414
doc_class_flags.cc
1515
doc_class_image.cc
16+
doc_class_rect.cc
1617
doc_class_time.cc
1718
doc_struct_circ.cc
1819
doc_tutorial_id.cc

docs/snippets/doc_class_rect.cc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Gamedev Framework (gf)
3+
* Copyright (C) 2016-2022 Julien Bernard
4+
*
5+
* This software is provided 'as-is', without any express or implied
6+
* warranty. In no event will the authors be held liable for any damages
7+
* arising from the use of this software.
8+
*
9+
* Permission is granted to anyone to use this software for any purpose,
10+
* including commercial applications, and to alter it and redistribute it
11+
* freely, subject to the following restrictions:
12+
*
13+
* 1. The origin of this software must not be misrepresented; you must not
14+
* claim that you wrote the original software. If you use this software
15+
* in a product, an acknowledgment in the product documentation would be
16+
* appreciated but is not required.
17+
* 2. Altered source versions must be plainly marked as such, and must not be
18+
* misrepresented as being the original software.
19+
* 3. This notice may not be removed or altered from any source distribution.
20+
*/
21+
#include <gf/Rect.h>
22+
#include <gf/Unused.h>
23+
24+
void dummyRectUsage() {
25+
/// [rect]
26+
// Define a rectangle, located at (0, 0) with a size of 20x5
27+
gf::RectI r1 = gf::RectI::fromSize({ 20, 5 });
28+
29+
// Define another rectangle, located at (4, 2) with a size of 18x10
30+
gf::Vector2i position(4, 2);
31+
gf::Vector2i size(18, 10);
32+
gf::RectI r2 = gf::RectI::fromPositionSize(position, size);
33+
34+
// Test intersections with the point (3, 1)
35+
bool b1 = r1.contains({ 3, 1 }); // true
36+
bool b2 = r2.contains({ 3, 1 }); // false
37+
38+
// Test the intersection between r1 and r2
39+
gf::RectI result;
40+
bool b3 = r1.intersects(r2, result); // true
41+
// result == (4, 2, 16, 3)
42+
/// [rect]
43+
44+
gf::unused(b1, b2, b3);
45+
}

include/gf/Rect.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,9 @@ inline namespace v1 {
6464
*
6565
* Usage example:
6666
*
67-
* ~~~{.cc}
68-
* // Define a rectangle, located at (0, 0) with a size of 20x5
69-
* gf::RectI r1(0, 0, 20, 5);
67+
* @snippet snippets/doc_class_rect.cc rect
7068
*
71-
* // Define another rectangle, located at (4, 2) with a size of 18x10
72-
* gf::Vector2i position(4, 2);
73-
* gf::Vector2i size(18, 10);
74-
* gf::RectI r2(position, size);
75-
*
76-
* // Test intersections with the point (3, 1)
77-
* bool b1 = r1.contains({ 3, 1 }); // true
78-
* bool b2 = r2.contains({ 3, 1 }); // false
79-
*
80-
* // Test the intersection between r1 and r2
81-
* gf::RectI result;
82-
* bool b3 = r1.intersects(r2, result); // true
83-
* // result == (4, 2, 16, 3)
84-
* ~~~
69+
* @sa gf::Circ
8570
*/
8671
template<typename T>
8772
struct Rect {

0 commit comments

Comments
 (0)