diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-04-27 11:26:28 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-04-27 11:26:28 +0400 |
commit | 4469ab985761abaacc99eb3d3c6b16a0aee927b1 (patch) | |
tree | 7aefdd86d06dada1459a18f6267a0ff119a9fed5 /source/blender/blenlib | |
parent | bb4942c9203602550968b27fa0ad29a911ae1ff1 (diff) |
code cleanup:
- move lasso functions into BLI (were in 3D view but UV editor needs access)
- remove unused UV functions (ones that assumed 3-4 sized UVs only)
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_lasso.h | 41 | ||||
-rw-r--r-- | source/blender/blenlib/CMakeLists.txt | 6 | ||||
-rw-r--r-- | source/blender/blenlib/intern/lasso.c | 129 | ||||
-rw-r--r-- | source/blender/blenlib/intern/listbase.c | 7 |
4 files changed, 175 insertions, 8 deletions
diff --git a/source/blender/blenlib/BLI_lasso.h b/source/blender/blenlib/BLI_lasso.h new file mode 100644 index 00000000000..2360173c3b8 --- /dev/null +++ b/source/blender/blenlib/BLI_lasso.h @@ -0,0 +1,41 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __BLI_LASSO_H__ +#define __BLI_LASSO_H__ + +/** \file BLI_lasso.h + * \ingroup bli + */ + +struct rcti; + +void BLI_lasso_boundbox(struct rcti *rect, int mcords[][2], short moves); +int BLI_lasso_is_point_inside(int mcords[][2], short moves, int sx, int sy, const int error_value); +int BLI_lasso_is_edge_inside(int mcords[][2], short moves, int x0, int y0, int x1, int y1, const int error_value); + +#endif diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index c06a1240729..61fe3b560e2 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -61,6 +61,7 @@ set(SRC intern/graph.c intern/gsqueue.c intern/jitter.c + intern/lasso.c intern/listbase.c intern/math_base.c intern/math_base_inline.c @@ -90,10 +91,9 @@ set(SRC intern/voxel.c intern/winstuff.c + BLI_args.h BLI_array.h BLI_bitmap.h - BLI_smallhash.h - BLI_args.h BLI_blenlib.h BLI_boxpack2d.h BLI_bpath.h @@ -114,6 +114,7 @@ set(SRC BLI_jitter.h BLI_kdopbvh.h BLI_kdtree.h + BLI_lasso.h BLI_linklist.h BLI_listbase.h BLI_math.h @@ -133,6 +134,7 @@ set(SRC BLI_rand.h BLI_rect.h BLI_scanfill.h + BLI_smallhash.h BLI_string.h BLI_string_cursor_utf8.h BLI_string_utf8.h diff --git a/source/blender/blenlib/intern/lasso.c b/source/blender/blenlib/intern/lasso.c new file mode 100644 index 00000000000..29b967fcd37 --- /dev/null +++ b/source/blender/blenlib/intern/lasso.c @@ -0,0 +1,129 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + * + */ + +/** \file blender/blenlib/intern/lasso.c + * \ingroup bli + */ + +#include "DNA_vec_types.h" + +#include "BLI_math.h" +#include "BLI_rect.h" + +#include "BLI_lasso.h" /* own include */ + +void BLI_lasso_boundbox(rcti *rect, int mcords[][2], short moves) +{ + short a; + + rect->xmin = rect->xmax = mcords[0][0]; + rect->ymin = rect->ymax = mcords[0][1]; + + for (a = 1; a < moves; a++) { + if (mcords[a][0] < rect->xmin) rect->xmin = mcords[a][0]; + else if (mcords[a][0] > rect->xmax) rect->xmax = mcords[a][0]; + if (mcords[a][1] < rect->ymin) rect->ymin = mcords[a][1]; + else if (mcords[a][1] > rect->ymax) rect->ymax = mcords[a][1]; + } +} + + +int BLI_lasso_is_point_inside(int mcords[][2], short moves, + const int sx, const int sy, + const int error_value) +{ + /* we do the angle rule, define that all added angles should be about zero or (2 * PI) */ + float angletot = 0.0, dot, ang, cross, fp1[2], fp2[2]; + int a; + int *p1, *p2; + + if (sx == error_value) { + return 0; + } + + p1 = mcords[moves - 1]; + p2 = mcords[0]; + + /* first vector */ + fp1[0] = (float)(p1[0] - sx); + fp1[1] = (float)(p1[1] - sy); + normalize_v2(fp1); + + for (a = 0; a < moves; a++) { + /* second vector */ + fp2[0] = (float)(p2[0] - sx); + fp2[1] = (float)(p2[1] - sy); + normalize_v2(fp2); + + /* dot and angle and cross */ + dot = fp1[0] * fp2[0] + fp1[1] * fp2[1]; + ang = fabs(saacos(dot)); + + cross = (float)((p1[1] - p2[1]) * (p1[0] - sx) + (p2[0] - p1[0]) * (p1[1] - sy)); + + if (cross < 0.0f) angletot -= ang; + else angletot += ang; + + /* circulate */ + fp1[0] = fp2[0]; fp1[1] = fp2[1]; + p1 = p2; + p2 = mcords[a + 1]; + } + + if (fabs(angletot) > 4.0) return 1; + return 0; +} + +/* edge version for lasso select. we assume boundbox check was done */ +int BLI_lasso_is_edge_inside(int mcords[][2], short moves, + int x0, int y0, int x1, int y1, + const int error_value) +{ + int v1[2], v2[2]; + int a; + + if (x0 == error_value || x1 == error_value) { + return 0; + } + + v1[0] = x0, v1[1] = y0; + v2[0] = x1, v2[1] = y1; + + /* check points in lasso */ + if (BLI_lasso_is_point_inside(mcords, moves, v1[0], v1[1], error_value)) return 1; + if (BLI_lasso_is_point_inside(mcords, moves, v2[0], v2[1], error_value)) return 1; + + /* no points in lasso, so we have to intersect with lasso edge */ + + if (isect_line_line_v2_int(mcords[0], mcords[moves - 1], v1, v2) > 0) return 1; + for (a = 0; a < moves - 1; a++) { + if (isect_line_line_v2_int(mcords[a], mcords[a + 1], v1, v2) > 0) return 1; + } + + return 0; +} diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c index fecaa507b5c..b2b18286cfb 100644 --- a/source/blender/blenlib/intern/listbase.c +++ b/source/blender/blenlib/intern/listbase.c @@ -1,9 +1,4 @@ -/* util.c - * - * various string, file, list operations. - * - * - * +/* * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or |