Debian Codegraph @

src/cdogs/vector.h

raw symbols SCIP
1 /*
2 Copyright (c) 2013-2014, 2016-2020 Cong Xu
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10 Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
13
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 POSSIBILITY OF SUCH DAMAGE.
25 */
26 #pragma once
27
28 #include <math.h>
29
30 #include "mathc/mathc.h"
31 #include "utils.h"
32
33 #define CHEBYSHEV_DISTANCE(x1, y1, x2, y2) \
34 MAX(fabsf((x1) - (x2)), fabsf((y1) - (y2)))
35
36 struct vec2i svec2i_scale_divide(const struct vec2i v, const mint_t scale);
37
38 struct vec2i Vec2iToTile(struct vec2i v);
39 struct vec2i Vec2iCenterOfTile(struct vec2i v);
40 struct vec2i Vec2ToTile(const struct vec2 v);
41 struct vec2 Vec2CenterOfTile(const struct vec2i v);
42
43 // Helper macros for positioning
44 #define CENTER_X(_pos, _size, _w) ((_pos).x + ((_size).x - (_w)) / 2)
45 #define CENTER_Y(_pos, _size, _h) ((_pos).y + ((_size).y - (_h)) / 2)
46
47 typedef struct
48 {
49 struct vec2i Pos;
50 struct vec2i Size;
51 } Rect2i;
52 // Convenience macro for looping through elements in rect
53 #define RECT_FOREACH(_r) \
54 { \
55 struct vec2i _v; \
56 for (_v.y = _r.Pos.y; _v.y < _r.Pos.y + _r.Size.y; _v.y++) \
57 { \
58 for (_v.x = _r.Pos.x; _v.x < _r.Pos.x + _r.Size.x; _v.x++) \
59 { \
60 const int _i = _v.x + _v.y * _r.Size.x; \
61 UNUSED(_i);
62 #define RECT_FOREACH_END() \
63 } \
64 } \
65 }
66
67 Rect2i Rect2iNew(const struct vec2i pos, const struct vec2i size);
68 Rect2i Rect2iZero(void);
69 bool Rect2iIsZero(const Rect2i r);
70 bool Rect2iIsAtEdge(const Rect2i r, const struct vec2i v);
71 bool Rect2iIsInside(const Rect2i r, const struct vec2i v);
72 bool Rect2iOverlap(const Rect2i r1, const Rect2i r2);
73 struct vec2i Rect2iCenter(const Rect2i r);