From 993dfd7d2a2eb18949a6c7680e05a950e7a1e9c8 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 12 Jul 2012 08:31:23 +0000 Subject: add bli rect funcs BLI_rctf_init_minmax, BLI_rcti_init_minmax --- source/blender/blenkernel/intern/colortools.c | 2 +- source/blender/blenkernel/intern/scene.c | 2 +- source/blender/blenlib/BLI_rect.h | 14 ++++------- source/blender/blenlib/intern/rct.c | 26 ++++++++++++++++++-- .../compositor/intern/COM_ExecutionGroup.cpp | 6 ++--- .../blender/compositor/intern/COM_MemoryBuffer.cpp | 4 ++-- .../compositor/intern/COM_NodeOperation.cpp | 2 +- .../operations/COM_GlareFogGlowOperation.cpp | 2 +- .../operations/COM_KeyingScreenOperation.cpp | 2 +- .../operations/COM_ReadBufferOperation.cpp | 2 +- source/blender/editors/screen/area.c | 28 +++++++++++----------- source/blender/editors/sculpt_paint/paint_utils.c | 4 ++-- source/blender/editors/space_file/file_ops.c | 2 +- source/blender/editors/space_image/image_buttons.c | 2 +- .../blender/editors/space_view3d/view3d_select.c | 6 ++--- 15 files changed, 60 insertions(+), 44 deletions(-) diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index 6879ec506f0..31ad4d0380a 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -71,7 +71,7 @@ CurveMapping *curvemapping_add(int tot, float minx, float miny, float maxx, floa clipmaxx = MAX2(minx, maxx); clipmaxy = MAX2(miny, maxy); - BLI_init_rctf(&cumap->curr, clipminx, clipmaxx, clipminy, clipmaxy); + BLI_rctf_init(&cumap->curr, clipminx, clipmaxx, clipminy, clipmaxy); cumap->clipr = cumap->curr; cumap->white[0] = cumap->white[1] = cumap->white[2] = 1.0f; diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 6f24eadd1b6..d9afd1eefb4 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -487,7 +487,7 @@ Scene *BKE_scene_add(const char *name) BLI_strncpy(sce->r.pic, U.renderdir, sizeof(sce->r.pic)); - BLI_init_rctf(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f); + BLI_rctf_init(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f); sce->r.osa = 8; /* note; in header_info.c the scene copy happens..., if you add more to renderdata it has to be checked there */ diff --git a/source/blender/blenlib/BLI_rect.h b/source/blender/blenlib/BLI_rect.h index 4d0e54e344c..49d10eb0be6 100644 --- a/source/blender/blenlib/BLI_rect.h +++ b/source/blender/blenlib/BLI_rect.h @@ -40,18 +40,12 @@ struct rcti; extern "C" { #endif -/* BLI_rct.c */ -/** - * Determine if a rect is empty. An empty - * rect is one with a zero (or negative) - * width or height. - * - * \return True if \a rect is empty. - */ int BLI_rcti_is_empty(const struct rcti *rect); int BLI_rctf_is_empty(const struct rctf *rect); -void BLI_init_rctf(struct rctf *rect, float xmin, float xmax, float ymin, float ymax); -void BLI_init_rcti(struct rcti *rect, int xmin, int xmax, int ymin, int ymax); +void BLI_rctf_init(struct rctf *rect, float xmin, float xmax, float ymin, float ymax); +void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax); +void BLI_rcti_init_minmax(struct rcti *rect); +void BLI_rctf_init_minmax(struct rctf *rect); void BLI_translate_rctf(struct rctf *rect, float x, float y); void BLI_translate_rcti(struct rcti *rect, int x, int y); void BLI_resize_rcti(struct rcti *rect, int x, int y); diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c index b4397ea4546..4ac30da2369 100644 --- a/source/blender/blenlib/intern/rct.c +++ b/source/blender/blenlib/intern/rct.c @@ -35,6 +35,9 @@ #include #include +#include +#include + #include "DNA_vec_types.h" #include "BLI_rect.h" @@ -57,6 +60,13 @@ int BLI_in_rcti(const rcti *rect, const int x, const int y) return 1; } +/** + * Determine if a rect is empty. An empty + * rect is one with a zero (or negative) + * width or height. + * + * \return True if \a rect is empty. + */ int BLI_in_rcti_v(const rcti *rect, const int xy[2]) { if (xy[0] < rect->xmin) return 0; @@ -149,7 +159,7 @@ void BLI_union_rcti(rcti *rct1, const rcti *rct2) if (rct1->ymax < rct2->ymax) rct1->ymax = rct2->ymax; } -void BLI_init_rctf(rctf *rect, float xmin, float xmax, float ymin, float ymax) +void BLI_rctf_init(rctf *rect, float xmin, float xmax, float ymin, float ymax) { if (xmin <= xmax) { rect->xmin = xmin; @@ -169,7 +179,7 @@ void BLI_init_rctf(rctf *rect, float xmin, float xmax, float ymin, float ymax) } } -void BLI_init_rcti(rcti *rect, int xmin, int xmax, int ymin, int ymax) +void BLI_rcti_init(rcti *rect, int xmin, int xmax, int ymin, int ymax) { if (xmin <= xmax) { rect->xmin = xmin; @@ -189,6 +199,18 @@ void BLI_init_rcti(rcti *rect, int xmin, int xmax, int ymin, int ymax) } } +void BLI_rcti_init_minmax(struct rcti *rect) +{ + rect->xmin = rect->ymin = INT_MAX; + rect->xmax = rect->ymax = INT_MIN; +} + +void BLI_rctf_init_minmax(struct rctf *rect) +{ + rect->xmin = rect->ymin = FLT_MAX; + rect->xmax = rect->ymax = FLT_MIN; +} + void BLI_translate_rcti(rcti *rect, int x, int y) { rect->xmin += x; diff --git a/source/blender/compositor/intern/COM_ExecutionGroup.cpp b/source/blender/compositor/intern/COM_ExecutionGroup.cpp index 1e42dba001a..46a0db7af2d 100644 --- a/source/blender/compositor/intern/COM_ExecutionGroup.cpp +++ b/source/blender/compositor/intern/COM_ExecutionGroup.cpp @@ -432,12 +432,12 @@ void ExecutionGroup::finalizeChunkExecution(int chunkNumber, MemoryBuffer **memo inline void ExecutionGroup::determineChunkRect(rcti *rect, const unsigned int xChunk, const unsigned int yChunk) const { if (this->m_singleThreaded) { - BLI_init_rcti(rect, 0, this->m_width, 0, this->m_height); + BLI_rcti_init(rect, 0, this->m_width, 0, this->m_height); } else { const unsigned int minx = xChunk * this->m_chunkSize; const unsigned int miny = yChunk * this->m_chunkSize; - BLI_init_rcti(rect, minx, min(minx + this->m_chunkSize, this->m_width), miny, min(miny + this->m_chunkSize, this->m_height)); + BLI_rcti_init(rect, minx, min(minx + this->m_chunkSize, this->m_width), miny, min(miny + this->m_chunkSize, this->m_height)); } } @@ -534,7 +534,7 @@ bool ExecutionGroup::scheduleChunkWhenPossible(ExecutionSystem *graph, int xChun for (index = 0; index < this->m_cachedReadOperations.size(); index++) { ReadBufferOperation *readOperation = (ReadBufferOperation *)this->m_cachedReadOperations[index]; - BLI_init_rcti(&area, 0, 0, 0, 0); + BLI_rcti_init(&area, 0, 0, 0, 0); MemoryProxy *memoryProxy = memoryProxies[index]; determineDependingAreaOfInterest(&rect, readOperation, &area); ExecutionGroup *group = memoryProxy->getExecutor(); diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.cpp b/source/blender/compositor/intern/COM_MemoryBuffer.cpp index 223c582d999..572308dd87f 100644 --- a/source/blender/compositor/intern/COM_MemoryBuffer.cpp +++ b/source/blender/compositor/intern/COM_MemoryBuffer.cpp @@ -40,7 +40,7 @@ int MemoryBuffer::getHeight() const MemoryBuffer::MemoryBuffer(MemoryProxy *memoryProxy, unsigned int chunkNumber, rcti *rect) { - BLI_init_rcti(&this->m_rect, rect->xmin, rect->xmax, rect->ymin, rect->ymax); + BLI_rcti_init(&this->m_rect, rect->xmin, rect->xmax, rect->ymin, rect->ymax); this->m_memoryProxy = memoryProxy; this->m_chunkNumber = chunkNumber; this->m_buffer = (float *)MEM_mallocN(sizeof(float) * determineBufferSize() * COM_NUMBER_OF_CHANNELS, "COM_MemoryBuffer"); @@ -51,7 +51,7 @@ MemoryBuffer::MemoryBuffer(MemoryProxy *memoryProxy, unsigned int chunkNumber, r MemoryBuffer::MemoryBuffer(MemoryProxy *memoryProxy, rcti *rect) { - BLI_init_rcti(&this->m_rect, rect->xmin, rect->xmax, rect->ymin, rect->ymax); + BLI_rcti_init(&this->m_rect, rect->xmin, rect->xmax, rect->ymin, rect->ymax); this->m_memoryProxy = memoryProxy; this->m_chunkNumber = -1; this->m_buffer = (float *)MEM_mallocN(sizeof(float) * determineBufferSize() * COM_NUMBER_OF_CHANNELS, "COM_MemoryBuffer"); diff --git a/source/blender/compositor/intern/COM_NodeOperation.cpp b/source/blender/compositor/intern/COM_NodeOperation.cpp index c3fa308971c..9baab584d9e 100644 --- a/source/blender/compositor/intern/COM_NodeOperation.cpp +++ b/source/blender/compositor/intern/COM_NodeOperation.cpp @@ -120,7 +120,7 @@ void NodeOperation::getConnectedInputSockets(vector *sockets) bool NodeOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) { if (this->isInputNode()) { - BLI_init_rcti(output, input->xmin, input->xmax, input->ymin, input->ymax); + BLI_rcti_init(output, input->xmin, input->xmax, input->ymin, input->ymax); return false; } else { diff --git a/source/blender/compositor/operations/COM_GlareFogGlowOperation.cpp b/source/blender/compositor/operations/COM_GlareFogGlowOperation.cpp index cb4c27a4c80..5452e779968 100644 --- a/source/blender/compositor/operations/COM_GlareFogGlowOperation.cpp +++ b/source/blender/compositor/operations/COM_GlareFogGlowOperation.cpp @@ -379,7 +379,7 @@ void GlareFogGlowOperation::generateGlare(float *data, MemoryBuffer *inputTile, // temp. src image // make the convolution kernel rcti kernelRect; - BLI_init_rcti(&kernelRect, 0, sz, 0, sz); + BLI_rcti_init(&kernelRect, 0, sz, 0, sz); ckrn = new MemoryBuffer(NULL, &kernelRect); scale = 0.25f * sqrtf((float)(sz * sz)); diff --git a/source/blender/compositor/operations/COM_KeyingScreenOperation.cpp b/source/blender/compositor/operations/COM_KeyingScreenOperation.cpp index cf20712cfeb..134fd8bc7fe 100644 --- a/source/blender/compositor/operations/COM_KeyingScreenOperation.cpp +++ b/source/blender/compositor/operations/COM_KeyingScreenOperation.cpp @@ -242,7 +242,7 @@ void *KeyingScreenOperation::initializeTileData(rcti *rect, MemoryBuffer **memor if (!triangulation) return NULL; - BLI_init_rctf(&rect_float, rect->xmin, rect->xmax, rect->ymin, rect->ymax); + BLI_rctf_init(&rect_float, rect->xmin, rect->xmax, rect->ymin, rect->ymax); tile_data = (TileData *) MEM_callocN(sizeof(TileData), "keying screen tile data"); diff --git a/source/blender/compositor/operations/COM_ReadBufferOperation.cpp b/source/blender/compositor/operations/COM_ReadBufferOperation.cpp index 882d302656d..c1aa51f5017 100644 --- a/source/blender/compositor/operations/COM_ReadBufferOperation.cpp +++ b/source/blender/compositor/operations/COM_ReadBufferOperation.cpp @@ -67,7 +67,7 @@ void ReadBufferOperation::executePixel(float *color, float x, float y, float dx, bool ReadBufferOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) { if (this == readOperation) { - BLI_init_rcti(output, input->xmin, input->xmax, input->ymin, input->ymax); + BLI_rcti_init(output, input->xmin, input->xmax, input->ymin, input->ymax); return true; } return false; diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index a79d38d4081..714700ec8f1 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -607,7 +607,7 @@ static void area_azone_initialize(ScrArea *sa) az->y1 = sa->totrct.ymin - 1; az->x2 = sa->totrct.xmin + (AZONESPOT - 1); az->y2 = sa->totrct.ymin + (AZONESPOT - 1); - BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2); + BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2); az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone"); BLI_addtail(&(sa->actionzones), az); @@ -616,7 +616,7 @@ static void area_azone_initialize(ScrArea *sa) az->y1 = sa->totrct.ymax + 1; az->x2 = sa->totrct.xmax - (AZONESPOT - 1); az->y2 = sa->totrct.ymax - (AZONESPOT - 1); - BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2); + BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2); } #define AZONEPAD_EDGE 4 @@ -650,7 +650,7 @@ static void region_azone_edge(AZone *az, ARegion *ar) break; } - BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2); + BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2); } static void region_azone_icon(ScrArea *sa, AZone *az, ARegion *ar) @@ -692,7 +692,7 @@ static void region_azone_icon(ScrArea *sa, AZone *az, ARegion *ar) break; } - BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2); + BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2); /* if more azones on 1 spot, set offset */ for (azt = sa->actionzones.first; azt; azt = azt->next) { @@ -706,7 +706,7 @@ static void region_azone_icon(ScrArea *sa, AZone *az, ARegion *ar) az->y1 -= AZONESPOT; az->y2 -= AZONESPOT; } - BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2); + BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2); } } } @@ -753,7 +753,7 @@ static void region_azone_tab_plus(ScrArea *sa, AZone *az, ARegion *ar) break; } /* rect needed for mouse pointer test */ - BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2); + BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2); } @@ -798,7 +798,7 @@ static void region_azone_tab(ScrArea *sa, AZone *az, ARegion *ar) break; } /* rect needed for mouse pointer test */ - BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2); + BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2); } #define AZONEPAD_TRIAW 16 @@ -843,7 +843,7 @@ static void region_azone_tria(ScrArea *sa, AZone *az, ARegion *ar) break; } /* rect needed for mouse pointer test */ - BLI_init_rcti(&az->rect, az->x1, az->x2, az->y1, az->y2); + BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2); } @@ -911,7 +911,7 @@ static void region_rect_recursive(ScrArea *sa, ARegion *ar, rcti *remainder, int return; /* no returns in function, winrct gets set in the end again */ - BLI_init_rcti(&ar->winrct, 0, 0, 0, 0); + BLI_rcti_init(&ar->winrct, 0, 0, 0, 0); /* for test; allow split of previously defined region */ if (ar->alignment & RGN_SPLIT_PREV) @@ -947,7 +947,7 @@ static void region_rect_recursive(ScrArea *sa, ARegion *ar, rcti *remainder, int else if (alignment == RGN_ALIGN_NONE) { /* typically last region */ ar->winrct = *remainder; - BLI_init_rcti(remainder, 0, 0, 0, 0); + BLI_rcti_init(remainder, 0, 0, 0, 0); } else if (alignment == RGN_ALIGN_TOP || alignment == RGN_ALIGN_BOTTOM) { @@ -1007,7 +1007,7 @@ static void region_rect_recursive(ScrArea *sa, ARegion *ar, rcti *remainder, int remainder->xmin = ar->winrct.xmax + 1; } else { - BLI_init_rcti(remainder, 0, 0, 0, 0); + BLI_rcti_init(remainder, 0, 0, 0, 0); } } else { @@ -1016,7 +1016,7 @@ static void region_rect_recursive(ScrArea *sa, ARegion *ar, rcti *remainder, int remainder->ymin = ar->winrct.ymax + 1; } else { - BLI_init_rcti(remainder, 0, 0, 0, 0); + BLI_rcti_init(remainder, 0, 0, 0, 0); } } } @@ -1036,7 +1036,7 @@ static void region_rect_recursive(ScrArea *sa, ARegion *ar, rcti *remainder, int if (count != 4) { /* let's stop adding regions */ - BLI_init_rcti(remainder, 0, 0, 0, 0); + BLI_rcti_init(remainder, 0, 0, 0, 0); if (G.debug & G_DEBUG) printf("region quadsplit failed\n"); } @@ -1058,7 +1058,7 @@ static void region_rect_recursive(ScrArea *sa, ARegion *ar, rcti *remainder, int else { /* right top */ ar->winrct.xmin = 1 + (remainder->xmin + remainder->xmax) / 2; ar->winrct.ymin = 1 + (remainder->ymin + remainder->ymax) / 2; - BLI_init_rcti(remainder, 0, 0, 0, 0); + BLI_rcti_init(remainder, 0, 0, 0, 0); } quad++; diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index 082e40f8e4c..26c51596a5e 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -41,6 +41,7 @@ #include "BLI_math.h" #include "BLI_utildefines.h" +#include "BLI_rect.h" #include "BKE_brush.h" #include "BKE_context.h" @@ -80,8 +81,7 @@ int paint_convert_bb_to_rect(rcti *rect, float projection_mat[4][4]; int i, j, k; - rect->xmin = rect->ymin = INT_MAX; - rect->xmax = rect->ymax = INT_MIN; + BLI_rcti_init_minmax(rect); /* return zero if the bounding box has non-positive volume */ if (bb_min[0] > bb_max[0] || bb_min[1] > bb_max[1] || bb_min[2] > bb_max[2]) diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 2d778b94216..9591e624296 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -81,7 +81,7 @@ static FileSelection find_file_mouse_rect(SpaceFile *sfile, struct ARegion *ar, UI_view2d_region_to_view(v2d, rect->xmin, rect->ymin, &fxmin, &fymin); UI_view2d_region_to_view(v2d, rect->xmax, rect->ymax, &fxmax, &fymax); - BLI_init_rcti(&rect_view, (int)(v2d->tot.xmin + fxmin), (int)(v2d->tot.xmin + fxmax), (int)(v2d->tot.ymax - fymin), (int)(v2d->tot.ymax - fymax)); + BLI_rcti_init(&rect_view, (int)(v2d->tot.xmin + fxmin), (int)(v2d->tot.xmin + fxmax), (int)(v2d->tot.ymax - fymin), (int)(v2d->tot.ymax - fymax)); sel = ED_fileselect_layout_offset_rect(sfile->layout, &rect_view); diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c index 116e155f501..99969405f9c 100644 --- a/source/blender/editors/space_image/image_buttons.c +++ b/source/blender/editors/space_image/image_buttons.c @@ -276,7 +276,7 @@ static void preview_cb(struct ScrArea *sa, struct uiBlock *block) /* while dragging we need to update the rects, otherwise it doesn't end with correct one */ - BLI_init_rctf(&dispf, 15.0f, (block->maxx - block->minx) - 15.0f, 15.0f, (block->maxy - block->miny) - 15.0f); + BLI_rctf_init(&dispf, 15.0f, (block->maxx - block->minx) - 15.0f, 15.0f, (block->maxy - block->miny) - 15.0f); ui_graphics_to_window_rct(sa->win, &dispf, disprect); /* correction for gla draw */ diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 43add69987b..39ec7514a88 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -1130,19 +1130,19 @@ static short mixed_bones_object_selectbuffer(ViewContext *vc, unsigned int *buff short a, hits15, hits9 = 0, hits5 = 0; short has_bones15 = 0, has_bones9 = 0, has_bones5 = 0; - BLI_init_rcti(&rect, mval[0] - 14, mval[0] + 14, mval[1] - 14, mval[1] + 14); + BLI_rcti_init(&rect, mval[0] - 14, mval[0] + 14, mval[1] - 14, mval[1] + 14); hits15 = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect); if (hits15 > 0) { for (a = 0; a < hits15; a++) if (buffer[4 * a + 3] & 0xFFFF0000) has_bones15 = 1; offs = 4 * hits15; - BLI_init_rcti(&rect, mval[0] - 9, mval[0] + 9, mval[1] - 9, mval[1] + 9); + BLI_rcti_init(&rect, mval[0] - 9, mval[0] + 9, mval[1] - 9, mval[1] + 9); hits9 = view3d_opengl_select(vc, buffer + offs, MAXPICKBUF - offs, &rect); if (hits9 > 0) { for (a = 0; a < hits9; a++) if (buffer[offs + 4 * a + 3] & 0xFFFF0000) has_bones9 = 1; offs += 4 * hits9; - BLI_init_rcti(&rect, mval[0] - 5, mval[0] + 5, mval[1] - 5, mval[1] + 5); + BLI_rcti_init(&rect, mval[0] - 5, mval[0] + 5, mval[1] - 5, mval[1] + 5); hits5 = view3d_opengl_select(vc, buffer + offs, MAXPICKBUF - offs, &rect); if (hits5 > 0) { for (a = 0; a < hits5; a++) if (buffer[offs + 4 * a + 3] & 0xFFFF0000) has_bones5 = 1; -- cgit v1.2.3