<<
path:
root/public/0x2lib.git/html/0x2_Math.jai
blob: 5fe67b60f9e9feef6c95c659048b6a6878e69d85
[raw]
[clear marker]
3// TODO: Need module param for cringe xyz ordering
6Rect_Origin :: enum_flags {
22roundf :: inline (x: float) -> float {
23 return floor(x + 0.5);
26round :: inline (x: float) -> int {
27 return xx floor(x + 0.5);
34rect_scale :: (rect: *$T/interface Rectangle, scale: Vector2, origin: Rect_Origin = .NONE) {
35 rect.* = rect_scale(rect.*, scale, origin);
42rect_scale :: (rect: $T/interface Rectangle, scale: Vector2, origin: Rect_Origin = .NONE) -> T {
45 if !origin || origin == .NONE then origin = .MID;
48 width = rect.width * scale.x;
51 else if origin & .RIGHT {
52 width = rect.width * scale.x;
53 x = (rect.x + rect.width) - width;
55 else if origin & .MID {
56 width = rect.width * scale.x;
57 x = (rect.x + rect.width / 2.0) - width / 2.0;
61 height = rect.height * scale.y;
64 else if origin & .BOTTOM {
65 height = rect.height * scale.y;
66 y = (rect.y + rect.height) - height;
68 else if origin & .MID {
69 height = rect.height * scale.y;
70 y = (rect.y + rect.height / 2.0) - height / 2.0;
81 x: float; /** top-left corner position x */
82 y: float; /** top-left corner position y */
88using, only(floor, Vector2) Math :: #import "Math";
92------------------------------------------------------------------------------
93This software is available under 2 licenses -- choose whichever you prefer.
94------------------------------------------------------------------------------
95ALTERNATIVE A - MIT License
96Copyright (c) 2026 Adam Blazeowsky
97Permission is hereby granted, free of charge, to any person obtaining a copy of
98this software and associated documentation files (the "Software"), to deal in
99the Software without restriction, including without limitation the rights to
100use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
101of the Software, and to permit persons to whom the Software is furnished to do
102so, subject to the following conditions:
103The above copyright notice and this permission notice shall be included in all
104copies or substantial portions of the Software.
105THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
106IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
107FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
108AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
109LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
110OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
112------------------------------------------------------------------------------
113ALTERNATIVE B - Public Domain (www.unlicense.org)
114This is free and unencumbered software released into the public domain.
115Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
116software, either in source code form or as a compiled binary, for any purpose,
117commercial or non-commercial, and by any means.
118In jurisdictions that recognize copyright laws, the author or authors of this
119software dedicate any and all copyright interest in the software to the public
120domain. We make this dedication for the benefit of the public at large and to
121the detriment of our heirs and successors. We intend this dedication to be an
122overt act of relinquishment in perpetuity of all present and future rights to
123this software under copyright law.
124THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
125IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
126FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
127AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
128ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
129WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
130------------------------------------------------------------------------------