[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46001] trunk/blender/source/blender: code cleanup:

Campbell Barton ideasman42 at gmail.com
Fri Apr 27 09:26:29 CEST 2012


Revision: 46001
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46001
Author:   campbellbarton
Date:     2012-04-27 07:26:28 +0000 (Fri, 27 Apr 2012)
Log Message:
-----------
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)

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/CMakeLists.txt
    trunk/blender/source/blender/blenlib/intern/listbase.c
    trunk/blender/source/blender/editors/include/ED_view3d.h
    trunk/blender/source/blender/editors/mesh/meshtools.c
    trunk/blender/source/blender/editors/physics/particle_edit.c
    trunk/blender/source/blender/editors/space_view3d/view3d_select.c
    trunk/blender/source/blender/editors/uvedit/uvedit_draw.c
    trunk/blender/source/blender/editors/uvedit/uvedit_intern.h
    trunk/blender/source/blender/editors/uvedit/uvedit_ops.c

Modified: trunk/blender/source/blender/blenlib/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/blenlib/CMakeLists.txt	2012-04-27 03:01:27 UTC (rev 46000)
+++ trunk/blender/source/blender/blenlib/CMakeLists.txt	2012-04-27 07:26:28 UTC (rev 46001)
@@ -61,6 +61,7 @@
 	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 @@
 	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 @@
 	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 @@
 	BLI_rand.h
 	BLI_rect.h
 	BLI_scanfill.h
+	BLI_smallhash.h
 	BLI_string.h
 	BLI_string_cursor_utf8.h
 	BLI_string_utf8.h

Modified: trunk/blender/source/blender/blenlib/intern/listbase.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/listbase.c	2012-04-27 03:01:27 UTC (rev 46000)
+++ trunk/blender/source/blender/blenlib/intern/listbase.c	2012-04-27 07:26:28 UTC (rev 46001)
@@ -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

Modified: trunk/blender/source/blender/editors/include/ED_view3d.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_view3d.h	2012-04-27 03:01:27 UTC (rev 46000)
+++ trunk/blender/source/blender/editors/include/ED_view3d.h	2012-04-27 07:26:28 UTC (rev 46001)
@@ -269,8 +269,6 @@
 
 /* XXX should move to BLI_math */
 int edge_inside_circle(short centx, short centy, short rad, short x1, short y1, short x2, short y2);
-int lasso_inside(int mcords[][2], short moves, int sx, int sy);
-int lasso_inside_edge(int mcords[][2], short moves, int x0, int y0, int x1, int y1);
 
 /* get 3d region from context, also if mouse is in header or toolbar */
 struct RegionView3D *ED_view3d_context_rv3d(struct bContext *C);

Modified: trunk/blender/source/blender/editors/mesh/meshtools.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/meshtools.c	2012-04-27 03:01:27 UTC (rev 46000)
+++ trunk/blender/source/blender/editors/mesh/meshtools.c	2012-04-27 07:26:28 UTC (rev 46001)
@@ -1016,7 +1016,7 @@
 		BMFace *efa;
 		
 		BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
-			poly_uv_center(em, efa, cent);
+			uv_poly_center(em, efa, cent);
 			
 			if ( (fabs(cent[0] - cent_vec[0]) < 0.001) && (fabs(cent[1] - cent_vec[1]) < 0.001) ) {
 				BMIter liter;

Modified: trunk/blender/source/blender/editors/physics/particle_edit.c
===================================================================
--- trunk/blender/source/blender/editors/physics/particle_edit.c	2012-04-27 03:01:27 UTC (rev 46000)
+++ trunk/blender/source/blender/editors/physics/particle_edit.c	2012-04-27 07:26:28 UTC (rev 46001)
@@ -45,7 +45,9 @@
 #include "DNA_space_types.h"
 
 #include "BLI_math.h"
-#include "BLI_blenlib.h"
+#include "BLI_lasso.h"
+#include "BLI_listbase.h"
+#include "BLI_string.h"
 #include "BLI_dynstr.h"
 #include "BLI_kdtree.h"
 #include "BLI_rand.h"
@@ -1633,7 +1635,9 @@
 				copy_v3_v3(co, key->co);
 				mul_m4_v3(mat, co);
 				project_int(ar, co, vertco);
-				if ((vertco[0] != IS_CLIPPED) && lasso_inside(mcords,moves,vertco[0],vertco[1]) && key_test_depth(&data, co)) {
+				if ((vertco[0] != IS_CLIPPED) &&
+				    BLI_lasso_is_point_inside(mcords,moves,vertco[0],vertco[1]) && key_test_depth(&data, co))
+				{
 					if (select && !(key->flag & PEK_SELECT)) {
 						key->flag |= PEK_SELECT;
 						point->flag |= PEP_EDIT_RECALC;
@@ -1651,7 +1655,9 @@
 			copy_v3_v3(co, key->co);
 			mul_m4_v3(mat, co);
 			project_int(ar, co,vertco);
-			if ((vertco[0] != IS_CLIPPED) && lasso_inside(mcords,moves,vertco[0],vertco[1]) && key_test_depth(&data, co)) {
+			if ((vertco[0] != IS_CLIPPED) &&
+			    BLI_lasso_is_point_inside(mcords,moves,vertco[0],vertco[1]) && key_test_depth(&data, co))
+			{
 				if (select && !(key->flag & PEK_SELECT)) {
 					key->flag |= PEK_SELECT;
 					point->flag |= PEP_EDIT_RECALC;

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_select.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_select.c	2012-04-27 03:01:27 UTC (rev 46000)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_select.c	2012-04-27 07:26:28 UTC (rev 46001)
@@ -48,9 +48,12 @@
 #include "MEM_guardedalloc.h"
 
 #include "BLI_math.h"
-#include "BLI_blenlib.h"
+#include "BLI_lasso.h"
+#include "BLI_rect.h"
 #include "BLI_rand.h"
 #include "BLI_linklist.h"
+#include "BLI_listbase.h"
+#include "BLI_string.h"
 #include "BLI_utildefines.h"
 
 /* vertex box select */
@@ -319,80 +322,7 @@
 #define MOVES_GESTURE 50
 #define MOVES_LASSO 500
 
-int lasso_inside(int mcords[][2], short moves, int sx, int sy)
-{
-	/* we do the angle rule, define that all added angles should be about zero or 2*PI */
-	float angletot = 0.0, len, dot, ang, cross, fp1[2], fp2[2];
-	int a;
-	int *p1, *p2;
-	
-	if (sx == IS_CLIPPED)
-		return 0;
-	
-	p1 = mcords[moves - 1];
-	p2 = mcords[0];
-	
-	/* first vector */
-	fp1[0] = (float)(p1[0] - sx);
-	fp1[1] = (float)(p1[1] - sy);
-	len = sqrt(fp1[0] * fp1[0] + fp1[1] * fp1[1]);
-	fp1[0] /= len;
-	fp1[1] /= len;
-	
-	for (a = 0; a < moves; a++) {
-		/* second vector */
-		fp2[0] = (float)(p2[0] - sx);
-		fp2[1] = (float)(p2[1] - sy);
-		len = sqrt(fp2[0] * fp2[0] + fp2[1] * fp2[1]);
-		fp2[0] /= len;
-		fp2[1] /= len;
-		
-		/* 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 lasso_inside_edge(int mcords[][2], short moves, int x0, int y0, int x1, int y1)
-{
-	int v1[2], v2[2];
-	int a;
-
-	if (x0 == IS_CLIPPED || x1 == IS_CLIPPED)
-		return 0;
-	
-	v1[0] = x0, v1[1] = y0;
-	v2[0] = x1, v2[1] = y1;
-
-	/* check points in lasso */
-	if (lasso_inside(mcords, moves, v1[0], v1[1])) return 1;
-	if (lasso_inside(mcords, moves, v2[0], v2[1])) 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;
-}
-
-
 /* warning; lasso select with backbuffer-check draws in backbuf with persp(PERSP_WIN) 
  * and returns with persp(PERSP_VIEW). After lasso select backbuf is not OK
  */
@@ -412,7 +342,7 @@
 			mul_v3_m4v3(vec, ob->obmat, pchan->pose_tail);
 			project_int(vc->ar, vec, sco2);
 			
-			if (lasso_inside_edge(mcords, moves, sco1[0], sco1[1], sco2[0], sco2[1])) {
+			if (BLI_lasso_is_edge_inside(mcords, moves, sco1[0], sco1[1], sco2[0], sco2[1], IS_CLIPPED)) {
 				if (select) pchan->bone->flag |= BONE_SELECTED;
 				else pchan->bone->flag &= ~BONE_SELECTED;
 			}
@@ -441,7 +371,7 @@
 	for (base = vc->scene->base.first; base; base = base->next) {
 		if (BASE_SELECTABLE(vc->v3d, base)) { /* use this to avoid un-needed lasso lookups */
 			project_short(vc->ar, base->object->obmat[3], &base->sx);
-			if (lasso_inside(mcords, moves, base->sx, base->sy)) {
+			if (BLI_lasso_is_point_inside(mcords, moves, base->sx, base->sy, IS_CLIPPED)) {
 				
 				if (select) ED_base_object_select(base, BA_SELECT);
 				else ED_base_object_select(base, BA_DESELECT);
@@ -454,26 +384,13 @@
 	}
 }
 
-static void lasso_select_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];
-	}
-}
-
 static void do_lasso_select_mesh__doSelectVert(void *userData, BMVert *eve, int x, int y, int UNUSED(index))
 {
 	LassoSelectUserData *data = userData;
 
-	if (BLI_in_rcti(data->rect, x, y) && lasso_inside(data->mcords, data->moves, x, y)) {
+	if (BLI_in_rcti(data->rect, x, y) &&
+	    BLI_lasso_is_point_inside(data->mcords, data->moves, x, y, IS_CLIPPED))
+	{
 		BM_vert_select_set(data->vc->em->bm, eve, data->select);
 	}
 }
@@ -484,14 +401,15 @@
 	if (EDBM_backbuf_check(bm_solidoffs + index)) {
 		if (data->pass == 0) {
 			if (edge_fully_inside_rect(data->rect, x0, y0, x1, y1)  &&
-			    lasso_inside(data->mcords, data->moves, x0, y0) &&
-			    lasso_inside(data->mcords, data->moves, x1, y1)) {
+			    BLI_lasso_is_point_inside(data->mcords, data->moves, x0, y0, IS_CLIPPED) &&
+			    BLI_lasso_is_point_inside(data->mcords, data->moves, x1, y1, IS_CLIPPED))
+			{
 				BM_edge_select_set(data->vc->em->bm, eed, data->select);
 				data->done = 1;
 			}
 		}
 		else {
-			if (lasso_inside_edge(data->mcords, data->moves, x0, y0, x1, y1)) {
+			if (BLI_lasso_is_edge_inside(data->mcords, data->moves, x0, y0, x1, y1, IS_CLIPPED)) {
 				BM_edge_select_set(data->vc->em->bm, eed, data->select);
 			}
 		}
@@ -501,7 +419,9 @@
 {
 	LassoSelectUserData *data = userData;
 
-	if (BLI_in_rcti(data->rect, x, y) && lasso_inside(data->mcords, data->moves, x, y)) {
+	if (BLI_in_rcti(data->rect, x, y) &&
+	    BLI_lasso_is_point_inside(data->mcords, data->moves, x, y, IS_CLIPPED))
+	{
 		BM_face_select_set(data->vc->em->bm, efa, data->select);
 	}
 }
@@ -513,7 +433,7 @@
 	rcti rect;
 	int bbsel;
 	
-	lasso_select_boundbox(&rect, mcords, moves);
+	BLI_lasso_boundbox(&rect, mcords, moves);
 	
 	/* set editmesh */
 	vc->em = BMEdit_FromObject(vc->obedit);
@@ -577,7 +497,7 @@
 	int screenUV[2], nverts, i, ok = 1;
 	rcti rect;
 	
-	lasso_select_boundbox(&rect, mcords, moves);
+	BLI_lasso_boundbox(&rect, mcords, moves);
 	

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list