Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-04-27 11:26:28 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-04-27 11:26:28 +0400
commit4469ab985761abaacc99eb3d3c6b16a0aee927b1 (patch)
tree7aefdd86d06dada1459a18f6267a0ff119a9fed5 /source/blender/blenlib/intern/lasso.c
parentbb4942c9203602550968b27fa0ad29a911ae1ff1 (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/intern/lasso.c')
-rw-r--r--source/blender/blenlib/intern/lasso.c129
1 files changed, 129 insertions, 0 deletions
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;
+}