Atlas - SDL_rect.c

Home / ext / SDL / src / video Lines: 1 | Size: 4112 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 Sam Lantinga <[email protected]> 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 "SDL_internal.h" 22 23#include "SDL_rect_c.h" 24 25/* There's no float version of this at the moment, because it's not a public API 26 and internally we only need the int version. */ 27bool SDL_GetSpanEnclosingRect(int width, int height, 28 int numrects, const SDL_Rect *rects, SDL_Rect *span) 29{ 30 int i; 31 int span_y1, span_y2; 32 int rect_y1, rect_y2; 33 34 CHECK_PARAM(width < 1) { 35 SDL_InvalidParamError("width"); 36 return false; 37 } 38 CHECK_PARAM(height < 1) { 39 SDL_InvalidParamError("height"); 40 return false; 41 } 42 CHECK_PARAM(!rects) { 43 SDL_InvalidParamError("rects"); 44 return false; 45 } 46 CHECK_PARAM(!span) { 47 SDL_InvalidParamError("span"); 48 return false; 49 } 50 CHECK_PARAM(numrects < 1) { 51 SDL_InvalidParamError("numrects"); 52 return false; 53 } 54 55 // Initialize to empty rect 56 span_y1 = height; 57 span_y2 = 0; 58 59 for (i = 0; i < numrects; ++i) { 60 rect_y1 = rects[i].y; 61 rect_y2 = rect_y1 + rects[i].h; 62 63 // Clip out of bounds rectangles, and expand span rect 64 if (rect_y1 < 0) { 65 span_y1 = 0; 66 } else if (rect_y1 < span_y1) { 67 span_y1 = rect_y1; 68 } 69 if (rect_y2 > height) { 70 span_y2 = height; 71 } else if (rect_y2 > span_y2) { 72 span_y2 = rect_y2; 73 } 74 } 75 if (span_y2 > span_y1) { 76 span->x = 0; 77 span->y = span_y1; 78 span->w = width; 79 span->h = (span_y2 - span_y1); 80 return true; 81 } 82 return false; 83} 84 85// For use with the Cohen-Sutherland algorithm for line clipping, in SDL_rect_impl.h 86#define CODE_BOTTOM 1 87#define CODE_TOP 2 88#define CODE_LEFT 4 89#define CODE_RIGHT 8 90 91// Same code twice, for float and int versions... 92#define RECTTYPE SDL_Rect 93#define POINTTYPE SDL_Point 94#define SCALARTYPE int 95#define BIGSCALARTYPE Sint64 96#define COMPUTEOUTCODE ComputeOutCode 97#define ENCLOSEPOINTS_EPSILON 1 98#define SDL_RECT_CAN_OVERFLOW SDL_RectCanOverflow 99#define SDL_HASINTERSECTION SDL_HasRectIntersection 100#define SDL_INTERSECTRECT SDL_GetRectIntersection 101#define SDL_RECTEMPTY SDL_RectEmpty 102#define SDL_UNIONRECT SDL_GetRectUnion 103#define SDL_ENCLOSEPOINTS SDL_GetRectEnclosingPoints 104#define SDL_INTERSECTRECTANDLINE SDL_GetRectAndLineIntersection 105#include "SDL_rect_impl.h" 106 107#define RECTTYPE SDL_FRect 108#define POINTTYPE SDL_FPoint 109#define SCALARTYPE float 110#define BIGSCALARTYPE double 111#define COMPUTEOUTCODE ComputeOutCodeFloat 112#define ENCLOSEPOINTS_EPSILON 0.0f 113#define SDL_RECT_CAN_OVERFLOW SDL_RectCanOverflowFloat 114#define SDL_HASINTERSECTION SDL_HasRectIntersectionFloat 115#define SDL_INTERSECTRECT SDL_GetRectIntersectionFloat 116#define SDL_RECTEMPTY SDL_RectEmptyFloat 117#define SDL_UNIONRECT SDL_GetRectUnionFloat 118#define SDL_ENCLOSEPOINTS SDL_GetRectEnclosingPointsFloat 119#define SDL_INTERSECTRECTANDLINE SDL_GetRectAndLineIntersectionFloat 120#include "SDL_rect_impl.h" 121
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.