| 
									
										
										
										
											2011-02-23 10:52:22 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2008-01-07 19:13:47 +00:00
										 |  |  |  * ***** BEGIN GPL LICENSE BLOCK ***** | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * 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 | 
					
						
							| 
									
										
										
										
											2008-01-07 19:13:47 +00:00
										 |  |  |  * of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * 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, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * 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. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2008-01-07 19:13:47 +00:00
										 |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  |  * (uit traces) maart 95 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-27 20:37:56 +00:00
										 |  |  | /** \file blender/blenlib/intern/scanfill.c
 | 
					
						
							|  |  |  |  *  \ingroup bli | 
					
						
							| 
									
										
										
										
											2016-05-06 00:37:31 +10:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Triangulate multiple 2D/3D polygon with support for holes, | 
					
						
							|  |  |  |  * use for tessellating curves, fonts and geometry. | 
					
						
							|  |  |  |  * See main function #BLI_scanfill_calc | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Uses sweep-line method. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \note There is a similar API in polyfill2d.c | 
					
						
							|  |  |  |  * which uses ear clipping, but has no hole support. | 
					
						
							| 
									
										
										
										
											2011-02-27 20:37:56 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <math.h>
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							| 
									
										
										
										
											2009-09-06 02:43:36 +00:00
										 |  |  | #include <string.h>
 | 
					
						
							| 
									
										
										
										
											2014-02-06 02:10:19 +11:00
										 |  |  | #include <limits.h>
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-13 17:46:30 +00:00
										 |  |  | #include "BLI_listbase.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | #include "BLI_math.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | #include "BLI_memarena.h"
 | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_scanfill.h"  /* own include */
 | 
					
						
							| 
									
										
										
										
											2009-07-22 22:35:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-30 20:35:59 +11:00
										 |  |  | #include "BLI_strict_flags.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | /* local types */ | 
					
						
							|  |  |  | typedef struct PolyFill { | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | 	unsigned int edges, verts; | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 	float min_xy[2], max_xy[2]; | 
					
						
							| 
									
										
										
										
											2014-02-06 02:10:19 +11:00
										 |  |  | 	unsigned short nr; | 
					
						
							| 
									
										
										
										
											2014-02-13 16:46:51 +11:00
										 |  |  | 	bool f; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } PolyFill; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 22:17:30 +00:00
										 |  |  | typedef struct ScanFillVertLink { | 
					
						
							| 
									
										
										
										
											2012-05-13 14:47:53 +00:00
										 |  |  | 	ScanFillVert *vert; | 
					
						
							|  |  |  | 	ScanFillEdge *edge_first, *edge_last; | 
					
						
							| 
									
										
										
										
											2012-02-19 22:17:30 +00:00
										 |  |  | } ScanFillVertLink; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* local funcs */ | 
					
						
							| 
									
										
										
										
											2005-08-14 06:08:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-18 14:30:57 +00:00
										 |  |  | #define SF_EPSILON   0.00003f
 | 
					
						
							| 
									
										
										
										
											2013-12-28 17:17:55 +11:00
										 |  |  | #define SF_EPSILON_SQ (SF_EPSILON * SF_EPSILON)
 | 
					
						
							| 
									
										
										
										
											2012-04-18 14:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 16:46:51 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ScanFillVert.status */ | 
					
						
							| 
									
										
										
										
											2014-02-13 14:13:42 +11:00
										 |  |  | #define SF_VERT_NEW        0  /* all new verts have this flag set */
 | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | #define SF_VERT_AVAILABLE  1  /* available - in an edge */
 | 
					
						
							| 
									
										
										
										
											2014-02-13 16:46:51 +11:00
										 |  |  | #define SF_VERT_ZERO_LEN   2
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-18 14:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 16:46:51 +11:00
										 |  |  | /* ScanFillEdge.status */ | 
					
						
							| 
									
										
										
										
											2012-04-18 14:30:57 +00:00
										 |  |  | /* Optionally set ScanFillEdge f to this to mark original boundary edges.
 | 
					
						
							| 
									
										
										
										
											2012-05-05 00:23:55 +00:00
										 |  |  |  * Only needed if there are internal diagonal edges passed to BLI_scanfill_calc. */ | 
					
						
							| 
									
										
										
										
											2014-02-13 14:13:42 +11:00
										 |  |  | #define SF_EDGE_NEW      0  /* all new edges have this flag set */
 | 
					
						
							|  |  |  | // #define SF_EDGE_BOUNDARY 1  /* UNUSED */
 | 
					
						
							|  |  |  | #define SF_EDGE_INTERNAL 2  /* edge is created while scan-filling */
 | 
					
						
							| 
									
										
										
										
											2012-04-18 14:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 16:46:51 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* PolyFill.status */ | 
					
						
							|  |  |  | #define SF_POLY_NEW   0  /* all polys initialized to this */
 | 
					
						
							|  |  |  | #define SF_POLY_VALID 1  /* has at least 3 verts */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | /* ****  FUNCTIONS FOR QSORT *************************** */ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-14 06:08:41 +00:00
										 |  |  | static int vergscdata(const void *a1, const void *a2) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 	const ScanFillVertLink *x1 = a1, *x2 = a2; | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-13 14:47:53 +00:00
										 |  |  | 	if      (x1->vert->xy[1] < x2->vert->xy[1]) return  1; | 
					
						
							|  |  |  | 	else if (x1->vert->xy[1] > x2->vert->xy[1]) return -1; | 
					
						
							|  |  |  | 	else if (x1->vert->xy[0] > x2->vert->xy[0]) return  1; | 
					
						
							|  |  |  | 	else if (x1->vert->xy[0] < x2->vert->xy[0]) return -1; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-14 06:08:41 +00:00
										 |  |  | static int vergpoly(const void *a1, const void *a2) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 	const PolyFill *x1 = a1, *x2 = a2; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 	if      (x1->min_xy[0] > x2->min_xy[0]) return  1; | 
					
						
							|  |  |  | 	else if (x1->min_xy[0] < x2->min_xy[0]) return -1; | 
					
						
							|  |  |  | 	else if (x1->min_xy[1] > x2->min_xy[1]) return  1; | 
					
						
							|  |  |  | 	else if (x1->min_xy[1] < x2->min_xy[1]) return -1; | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | /* ****  FILL ROUTINES *************************** */ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | ScanFillVert *BLI_scanfill_vert_add(ScanFillContext *sf_ctx, const float vec[3]) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | 	ScanFillVert *sf_v; | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | 	sf_v = BLI_memarena_alloc(sf_ctx->arena, sizeof(ScanFillVert)); | 
					
						
							| 
									
										
										
										
											2011-05-24 05:59:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | 	BLI_addtail(&sf_ctx->fillvertbase, sf_v); | 
					
						
							| 
									
										
										
										
											2012-02-19 22:36:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | 	sf_v->tmp.p = NULL; | 
					
						
							|  |  |  | 	copy_v3_v3(sf_v->co, vec); | 
					
						
							| 
									
										
										
										
											2011-09-24 16:38:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | 	/* just zero out the rest */ | 
					
						
							|  |  |  | 	zero_v2(sf_v->xy); | 
					
						
							|  |  |  | 	sf_v->keyindex = 0; | 
					
						
							| 
									
										
										
										
											2014-02-05 05:22:21 +11:00
										 |  |  | 	sf_v->poly_nr = sf_ctx->poly_nr; | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | 	sf_v->edge_tot = 0; | 
					
						
							| 
									
										
										
										
											2014-02-13 14:13:42 +11:00
										 |  |  | 	sf_v->f = SF_VERT_NEW; | 
					
						
							| 
									
										
										
										
											2014-02-13 16:46:51 +11:00
										 |  |  | 	sf_v->user_flag = 0; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | 	return sf_v; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-05 00:23:55 +00:00
										 |  |  | ScanFillEdge *BLI_scanfill_edge_add(ScanFillContext *sf_ctx, ScanFillVert *v1, ScanFillVert *v2) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | 	ScanFillEdge *sf_ed; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | 	sf_ed = BLI_memarena_alloc(sf_ctx->arena, sizeof(ScanFillEdge)); | 
					
						
							|  |  |  | 	BLI_addtail(&sf_ctx->filledgebase, sf_ed); | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | 	sf_ed->v1 = v1; | 
					
						
							|  |  |  | 	sf_ed->v2 = v2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* just zero out the rest */ | 
					
						
							| 
									
										
										
										
											2014-02-05 05:22:21 +11:00
										 |  |  | 	sf_ed->poly_nr = sf_ctx->poly_nr; | 
					
						
							| 
									
										
										
										
											2014-02-13 14:13:42 +11:00
										 |  |  | 	sf_ed->f = SF_EDGE_NEW; | 
					
						
							| 
									
										
										
										
											2014-02-13 16:46:51 +11:00
										 |  |  | 	sf_ed->user_flag = 0; | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | 	sf_ed->tmp.c = 0; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | 	return sf_ed; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | static void addfillface(ScanFillContext *sf_ctx, ScanFillVert *v1, ScanFillVert *v2, ScanFillVert *v3) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* does not make edges */ | 
					
						
							| 
									
										
										
										
											2012-05-13 14:47:53 +00:00
										 |  |  | 	ScanFillFace *sf_tri; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | 	sf_tri = BLI_memarena_alloc(sf_ctx->arena, sizeof(ScanFillFace)); | 
					
						
							| 
									
										
										
										
											2012-05-13 14:47:53 +00:00
										 |  |  | 	BLI_addtail(&sf_ctx->fillfacebase, sf_tri); | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-13 14:47:53 +00:00
										 |  |  | 	sf_tri->v1 = v1; | 
					
						
							|  |  |  | 	sf_tri->v2 = v2; | 
					
						
							|  |  |  | 	sf_tri->v3 = v3; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | static bool boundisect(PolyFill *pf2, PolyFill *pf1) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* has pf2 been touched (intersected) by pf1 ? with bounding box */ | 
					
						
							|  |  |  | 	/* test first if polys exist */ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-01 14:33:38 +01:00
										 |  |  | 	if (pf1->edges == 0 || pf2->edges == 0) return false; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-01 14:33:38 +01:00
										 |  |  | 	if (pf2->max_xy[0] < pf1->min_xy[0]) return false; | 
					
						
							|  |  |  | 	if (pf2->max_xy[1] < pf1->min_xy[1]) return false; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-01 14:33:38 +01:00
										 |  |  | 	if (pf2->min_xy[0] > pf1->max_xy[0]) return false; | 
					
						
							|  |  |  | 	if (pf2->min_xy[1] > pf1->max_xy[1]) return false; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* join */ | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 	if (pf2->max_xy[0] < pf1->max_xy[0]) pf2->max_xy[0] = pf1->max_xy[0]; | 
					
						
							|  |  |  | 	if (pf2->max_xy[1] < pf1->max_xy[1]) pf2->max_xy[1] = pf1->max_xy[1]; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 	if (pf2->min_xy[0] > pf1->min_xy[0]) pf2->min_xy[0] = pf1->min_xy[0]; | 
					
						
							|  |  |  | 	if (pf2->min_xy[1] > pf1->min_xy[1]) pf2->min_xy[1] = pf1->min_xy[1]; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-01 14:33:38 +01:00
										 |  |  | 	return true; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | static void mergepolysSimp(ScanFillContext *sf_ctx, PolyFill *pf1, PolyFill *pf2)    /* add pf2 to pf1 */ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-19 22:17:30 +00:00
										 |  |  | 	ScanFillVert *eve; | 
					
						
							|  |  |  | 	ScanFillEdge *eed; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* replace old poly numbers */ | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 	for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) { | 
					
						
							|  |  |  | 		if (eve->poly_nr == pf2->nr) { | 
					
						
							|  |  |  | 			eve->poly_nr = pf1->nr; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (eed = sf_ctx->filledgebase.first; eed; eed = eed->next) { | 
					
						
							|  |  |  | 		if (eed->poly_nr == pf2->nr) { | 
					
						
							|  |  |  | 			eed->poly_nr = pf1->nr; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 	pf1->verts += pf2->verts; | 
					
						
							|  |  |  | 	pf1->edges += pf2->edges; | 
					
						
							|  |  |  | 	pf2->verts = pf2->edges = 0; | 
					
						
							|  |  |  | 	pf1->f = (pf1->f | pf2->f); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | static bool testedgeside(const float v1[2], const float v2[2], const float v3[2]) | 
					
						
							| 
									
										
										
										
											2012-07-01 09:54:44 +00:00
										 |  |  | /* is v3 to the right of v1-v2 ? With exception: v3 == v1 || v3 == v2 */ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	float inp; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 	inp = (v2[0] - v1[0]) * (v1[1] - v3[1]) + | 
					
						
							|  |  |  | 	      (v1[1] - v2[1]) * (v1[0] - v3[0]); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 	if (inp < 0.0f) { | 
					
						
							| 
									
										
										
										
											2014-12-01 14:33:38 +01:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | 	else if (inp == 0.0f) { | 
					
						
							| 
									
										
										
										
											2014-12-01 14:33:38 +01:00
										 |  |  | 		if (v1[0] == v3[0] && v1[1] == v3[1]) return false; | 
					
						
							|  |  |  | 		if (v2[0] == v3[0] && v2[1] == v3[1]) return false; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-12-01 14:33:38 +01:00
										 |  |  | 	return true; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | static bool addedgetoscanvert(ScanFillVertLink *sc, ScanFillEdge *eed) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* find first edge to the right of eed, and insert eed before that */ | 
					
						
							| 
									
										
										
										
											2012-02-19 22:17:30 +00:00
										 |  |  | 	ScanFillEdge *ed; | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 	float fac, fac1, x, y; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-13 14:47:53 +00:00
										 |  |  | 	if (sc->edge_first == NULL) { | 
					
						
							|  |  |  | 		sc->edge_first = sc->edge_last = eed; | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 		eed->prev = eed->next = NULL; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 	x = eed->v1->xy[0]; | 
					
						
							|  |  |  | 	y = eed->v1->xy[1]; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 	fac1 = eed->v2->xy[1] - y; | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 	if (fac1 == 0.0f) { | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 		fac1 = 1.0e10f * (eed->v2->xy[0] - x); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-02-10 17:06:05 +00:00
										 |  |  | 	else { | 
					
						
							|  |  |  | 		fac1 = (x - eed->v2->xy[0]) / fac1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-13 14:47:53 +00:00
										 |  |  | 	for (ed = sc->edge_first; ed; ed = ed->next) { | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-18 14:30:57 +00:00
										 |  |  | 		if (ed->v2 == eed->v2) { | 
					
						
							| 
									
										
										
										
											2014-12-01 14:33:38 +01:00
										 |  |  | 			return false; | 
					
						
							| 
									
										
										
										
											2012-04-18 14:30:57 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 		fac = ed->v2->xy[1] - y; | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 		if (fac == 0.0f) { | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 			fac = 1.0e10f * (ed->v2->xy[0] - x); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 			fac = (x - ed->v2->xy[0]) / fac; | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-18 14:30:57 +00:00
										 |  |  | 		if (fac > fac1) { | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-05-13 14:47:53 +00:00
										 |  |  | 	if (ed) BLI_insertlinkbefore((ListBase *)&(sc->edge_first), ed, eed); | 
					
						
							|  |  |  | 	else BLI_addtail((ListBase *)&(sc->edge_first), eed); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-01 14:33:38 +01:00
										 |  |  | 	return true; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-05 05:39:28 +11:00
										 |  |  | static ScanFillVertLink *addedgetoscanlist(ScanFillVertLink *scdata, ScanFillEdge *eed, unsigned int len) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-19 22:17:30 +00:00
										 |  |  | 	/* inserts edge at correct location in ScanFillVertLink list */ | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* returns sc when edge already exists */ | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 	ScanFillVertLink *sc, scsearch; | 
					
						
							| 
									
										
										
										
											2012-02-19 22:17:30 +00:00
										 |  |  | 	ScanFillVert *eve; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* which vert is left-top? */ | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 	if (eed->v1->xy[1] == eed->v2->xy[1]) { | 
					
						
							|  |  |  | 		if (eed->v1->xy[0] > eed->v2->xy[0]) { | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 			eve = eed->v1; | 
					
						
							|  |  |  | 			eed->v1 = eed->v2; | 
					
						
							|  |  |  | 			eed->v2 = eve; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 	else if (eed->v1->xy[1] < eed->v2->xy[1]) { | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 		eve = eed->v1; | 
					
						
							|  |  |  | 		eed->v1 = eed->v2; | 
					
						
							|  |  |  | 		eed->v2 = eve; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* find location in list */ | 
					
						
							| 
									
										
										
										
											2012-05-13 14:47:53 +00:00
										 |  |  | 	scsearch.vert = eed->v1; | 
					
						
							| 
									
										
										
										
											2014-02-05 05:39:28 +11:00
										 |  |  | 	sc = (ScanFillVertLink *)bsearch(&scsearch, scdata, len, | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 	                                 sizeof(ScanFillVertLink), vergscdata); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | 	if (UNLIKELY(sc == NULL)) { | 
					
						
							|  |  |  | 		printf("Error in search edge: %p\n", (void *)eed); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (addedgetoscanvert(sc, eed) == false) { | 
					
						
							|  |  |  | 		return sc; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-07 03:36:05 +00:00
										 |  |  | 	return NULL; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | static bool boundinsideEV(ScanFillEdge *eed, ScanFillVert *eve) | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | /* is eve inside boundbox eed */ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 	float minx, maxx, miny, maxy; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 	if (eed->v1->xy[0] < eed->v2->xy[0]) { | 
					
						
							|  |  |  | 		minx = eed->v1->xy[0]; | 
					
						
							|  |  |  | 		maxx = eed->v2->xy[0]; | 
					
						
							| 
									
										
										
										
											2012-03-24 06:18:31 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 		minx = eed->v2->xy[0]; | 
					
						
							|  |  |  | 		maxx = eed->v1->xy[0]; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 	if (eve->xy[0] >= minx && eve->xy[0] <= maxx) { | 
					
						
							|  |  |  | 		if (eed->v1->xy[1] < eed->v2->xy[1]) { | 
					
						
							|  |  |  | 			miny = eed->v1->xy[1]; | 
					
						
							|  |  |  | 			maxy = eed->v2->xy[1]; | 
					
						
							| 
									
										
										
										
											2012-03-24 06:18:31 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 			miny = eed->v2->xy[1]; | 
					
						
							|  |  |  | 			maxy = eed->v1->xy[1]; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-04-18 14:36:56 +00:00
										 |  |  | 		if (eve->xy[1] >= miny && eve->xy[1] <= maxy) { | 
					
						
							| 
									
										
										
										
											2014-12-01 14:33:38 +01:00
										 |  |  | 			return true; | 
					
						
							| 
									
										
										
										
											2012-04-18 14:36:56 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-12-01 14:33:38 +01:00
										 |  |  | 	return false; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | static void testvertexnearedge(ScanFillContext *sf_ctx) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-04 02:54:19 +11:00
										 |  |  | 	/* only vertices with (->edge_tot == 1) are being tested for
 | 
					
						
							| 
									
										
										
										
											2012-03-03 20:19:11 +00:00
										 |  |  | 	 * being close to an edge, if true insert */ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 22:17:30 +00:00
										 |  |  | 	ScanFillVert *eve; | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 	ScanFillEdge *eed, *ed1; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-18 14:30:57 +00:00
										 |  |  | 	for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) { | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 		if (eve->edge_tot == 1) { | 
					
						
							| 
									
										
										
										
											2012-09-11 02:18:27 +00:00
										 |  |  | 			/* find the edge which has vertex eve,
 | 
					
						
							|  |  |  | 			 * note: we _know_ this will crash if 'ed1' becomes NULL | 
					
						
							|  |  |  | 			 * but this will never happen. */ | 
					
						
							|  |  |  | 			for (ed1 = sf_ctx->filledgebase.first; | 
					
						
							|  |  |  | 			     !(ed1->v1 == eve || ed1->v2 == eve); | 
					
						
							|  |  |  | 			     ed1 = ed1->next) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				/* do nothing */ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-09-11 02:18:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 			if (ed1->v1 == eve) { | 
					
						
							|  |  |  | 				ed1->v1 = ed1->v2; | 
					
						
							|  |  |  | 				ed1->v2 = eve; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-04-18 14:30:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			for (eed = sf_ctx->filledgebase.first; eed; eed = eed->next) { | 
					
						
							| 
									
										
										
										
											2012-02-19 22:17:30 +00:00
										 |  |  | 				if (eve != eed->v1 && eve != eed->v2 && eve->poly_nr == eed->poly_nr) { | 
					
						
							| 
									
										
										
										
											2013-04-10 23:59:37 +00:00
										 |  |  | 					if (compare_v2v2(eve->xy, eed->v1->xy, SF_EPSILON)) { | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 						ed1->v2 = eed->v1; | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 						eed->v1->edge_tot++; | 
					
						
							|  |  |  | 						eve->edge_tot = 0; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2013-04-10 23:59:37 +00:00
										 |  |  | 					else if (compare_v2v2(eve->xy, eed->v2->xy, SF_EPSILON)) { | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 						ed1->v2 = eed->v2; | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 						eed->v2->edge_tot++; | 
					
						
							|  |  |  | 						eve->edge_tot = 0; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					else { | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 						if (boundinsideEV(eed, eve)) { | 
					
						
							| 
									
										
										
										
											2013-12-28 17:17:55 +11:00
										 |  |  | 							const float dist = dist_squared_to_line_v2(eed->v1->xy, eed->v2->xy, eve->xy); | 
					
						
							|  |  |  | 							if (dist < SF_EPSILON_SQ) { | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 								/* new edge */ | 
					
						
							| 
									
										
										
										
											2012-05-05 00:23:55 +00:00
										 |  |  | 								ed1 = BLI_scanfill_edge_add(sf_ctx, eed->v1, eve); | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-29 01:54:58 +00:00
										 |  |  | 								/* printf("fill: vertex near edge %x\n", eve); */ | 
					
						
							| 
									
										
										
										
											2012-02-19 22:17:30 +00:00
										 |  |  | 								ed1->poly_nr = eed->poly_nr; | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 								eed->v1 = eve; | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 								eve->edge_tot = 3; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 								break; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | static void splitlist(ScanFillContext *sf_ctx, ListBase *tempve, ListBase *temped, unsigned short nr) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* everything is in templist, write only poly nr to fillist */ | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 	ScanFillVert *eve, *eve_next; | 
					
						
							|  |  |  | 	ScanFillEdge *eed, *eed_next; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 	BLI_movelisttolist(tempve, &sf_ctx->fillvertbase); | 
					
						
							|  |  |  | 	BLI_movelisttolist(temped, &sf_ctx->filledgebase); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (eve = tempve->first; eve; eve = eve_next) { | 
					
						
							|  |  |  | 		eve_next = eve->next; | 
					
						
							| 
									
										
										
										
											2012-02-19 22:17:30 +00:00
										 |  |  | 		if (eve->poly_nr == nr) { | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 			BLI_remlink(tempve, eve); | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 			BLI_addtail(&sf_ctx->fillvertbase, eve); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 	for (eed = temped->first; eed; eed = eed_next) { | 
					
						
							|  |  |  | 		eed_next = eed->next; | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 		if (eed->poly_nr == nr) { | 
					
						
							|  |  |  | 			BLI_remlink(temped, eed); | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 			BLI_addtail(&sf_ctx->filledgebase, eed); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | static unsigned int scanfill(ScanFillContext *sf_ctx, PolyFill *pf, const int flag) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-05 05:39:28 +11:00
										 |  |  | 	ScanFillVertLink *scdata; | 
					
						
							| 
									
										
										
										
											2012-02-19 22:17:30 +00:00
										 |  |  | 	ScanFillVertLink *sc = NULL, *sc1; | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 	ScanFillVert *eve, *v1, *v2, *v3; | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 	ScanFillEdge *eed, *eed_next, *ed1, *ed2, *ed3; | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | 	unsigned int a, b, verts, maxface, totface; | 
					
						
							|  |  |  | 	const unsigned short nr = pf->nr; | 
					
						
							|  |  |  | 	bool twoconnected = false; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-03 20:19:11 +00:00
										 |  |  | 	/* PRINTS */ | 
					
						
							|  |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 	verts = pf->verts; | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 	for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) { | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 		printf("vert: %x co: %f %f\n", eve, eve->xy[0], eve->xy[1]); | 
					
						
							| 
									
										
										
										
											2012-09-16 04:58:18 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (eed = sf_ctx->filledgebase.first; eed; eed = eed->next) { | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 		printf("edge: %x  verts: %x %x\n", eed, eed->v1, eed->v2); | 
					
						
							| 
									
										
										
										
											2012-03-03 20:19:11 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* STEP 0: remove zero sized edges */ | 
					
						
							| 
									
										
										
										
											2012-11-26 23:18:04 +00:00
										 |  |  | 	if (flag & BLI_SCANFILL_CALC_REMOVE_DOUBLES) { | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 		for (eed = sf_ctx->filledgebase.first; eed; eed = eed->next) { | 
					
						
							| 
									
										
										
										
											2012-11-26 23:18:04 +00:00
										 |  |  | 			if (equals_v2v2(eed->v1->xy, eed->v2->xy)) { | 
					
						
							|  |  |  | 				if (eed->v1->f == SF_VERT_ZERO_LEN && eed->v2->f != SF_VERT_ZERO_LEN) { | 
					
						
							|  |  |  | 					eed->v2->f = SF_VERT_ZERO_LEN; | 
					
						
							|  |  |  | 					eed->v2->tmp.v = eed->v1->tmp.v; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else if (eed->v2->f == SF_VERT_ZERO_LEN && eed->v1->f != SF_VERT_ZERO_LEN) { | 
					
						
							|  |  |  | 					eed->v1->f = SF_VERT_ZERO_LEN; | 
					
						
							|  |  |  | 					eed->v1->tmp.v = eed->v2->tmp.v; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else if (eed->v2->f == SF_VERT_ZERO_LEN && eed->v1->f == SF_VERT_ZERO_LEN) { | 
					
						
							|  |  |  | 					eed->v1->tmp.v = eed->v2->tmp.v; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else { | 
					
						
							|  |  |  | 					eed->v2->f = SF_VERT_ZERO_LEN; | 
					
						
							|  |  |  | 					eed->v2->tmp.v = eed->v1; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* STEP 1: make using FillVert and FillEdge lists a sorted
 | 
					
						
							| 
									
										
										
										
											2012-03-03 20:19:11 +00:00
										 |  |  | 	 * ScanFillVertLink list | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2014-02-06 01:02:22 +11:00
										 |  |  | 	sc = scdata = MEM_mallocN(sizeof(*scdata) * pf->verts, "Scanfill1"); | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 	verts = 0; | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 	for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) { | 
					
						
							| 
									
										
										
										
											2012-02-19 22:17:30 +00:00
										 |  |  | 		if (eve->poly_nr == nr) { | 
					
						
							| 
									
										
										
										
											2012-04-18 14:30:57 +00:00
										 |  |  | 			if (eve->f != SF_VERT_ZERO_LEN) { | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 				verts++; | 
					
						
							| 
									
										
										
										
											2014-02-13 14:13:42 +11:00
										 |  |  | 				eve->f = SF_VERT_NEW;  /* flag for connectedges later on */ | 
					
						
							| 
									
										
										
										
											2012-05-13 14:47:53 +00:00
										 |  |  | 				sc->vert = eve; | 
					
						
							| 
									
										
										
										
											2014-02-06 01:02:22 +11:00
										 |  |  | 				sc->edge_first = sc->edge_last = NULL; | 
					
						
							| 
									
										
										
										
											2013-02-15 12:26:47 +00:00
										 |  |  | 				/* if (even->tmp.v == NULL) eve->tmp.u = verts; */ /* Note, debug print only will work for curve polyfill, union is in use for mesh */ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 				sc++; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-05 05:39:28 +11:00
										 |  |  | 	qsort(scdata, verts, sizeof(ScanFillVertLink), vergscdata); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-26 23:18:04 +00:00
										 |  |  | 	if (flag & BLI_SCANFILL_CALC_REMOVE_DOUBLES) { | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 		for (eed = sf_ctx->filledgebase.first; eed; eed = eed_next) { | 
					
						
							|  |  |  | 			eed_next = eed->next; | 
					
						
							| 
									
										
										
										
											2012-11-26 23:18:04 +00:00
										 |  |  | 			BLI_remlink(&sf_ctx->filledgebase, eed); | 
					
						
							|  |  |  | 			/* This code is for handling zero-length edges that get
 | 
					
						
							|  |  |  | 			 * collapsed in step 0. It was removed for some time to | 
					
						
							|  |  |  | 			 * fix trunk bug #4544, so if that comes back, this code | 
					
						
							|  |  |  | 			 * may need some work, or there will have to be a better | 
					
						
							|  |  |  | 			 * fix to #4544. | 
					
						
							|  |  |  | 			 * | 
					
						
							|  |  |  | 			 * warning, this can hang on un-ordered edges, see: [#33281] | 
					
						
							|  |  |  | 			 * for now disable 'BLI_SCANFILL_CALC_REMOVE_DOUBLES' for ngons. | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			if (eed->v1->f == SF_VERT_ZERO_LEN) { | 
					
						
							|  |  |  | 				v1 = eed->v1; | 
					
						
							|  |  |  | 				while ((eed->v1->f == SF_VERT_ZERO_LEN) && (eed->v1->tmp.v != v1) && (eed->v1 != eed->v1->tmp.v)) | 
					
						
							|  |  |  | 					eed->v1 = eed->v1->tmp.v; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (eed->v2->f == SF_VERT_ZERO_LEN) { | 
					
						
							|  |  |  | 				v2 = eed->v2; | 
					
						
							|  |  |  | 				while ((eed->v2->f == SF_VERT_ZERO_LEN) && (eed->v2->tmp.v != v2) && (eed->v2 != eed->v2->tmp.v)) | 
					
						
							|  |  |  | 					eed->v2 = eed->v2->tmp.v; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (eed->v1 != eed->v2) { | 
					
						
							| 
									
										
										
										
											2014-02-05 05:39:28 +11:00
										 |  |  | 				addedgetoscanlist(scdata, eed, verts); | 
					
						
							| 
									
										
										
										
											2012-11-26 23:18:04 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-11-22 14:04:33 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-11-26 23:18:04 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 		for (eed = sf_ctx->filledgebase.first; eed; eed = eed_next) { | 
					
						
							|  |  |  | 			eed_next = eed->next; | 
					
						
							| 
									
										
										
										
											2012-11-26 23:18:04 +00:00
										 |  |  | 			BLI_remlink(&sf_ctx->filledgebase, eed); | 
					
						
							|  |  |  | 			if (eed->v1 != eed->v2) { | 
					
						
							| 
									
										
										
										
											2014-02-05 05:39:28 +11:00
										 |  |  | 				addedgetoscanlist(scdata, eed, verts); | 
					
						
							| 
									
										
										
										
											2012-11-26 23:18:04 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-11-22 14:04:33 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-03 20:19:11 +00:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 	sc = sf_ctx->_scdata; | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 	for (a = 0; a < verts; a++) { | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 		printf("\nscvert: %x\n", sc->vert); | 
					
						
							|  |  |  | 		for (eed = sc->edge_first; eed; eed = eed->next) { | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 			printf(" ed %x %x %x\n", eed, eed->v1, eed->v2); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sc++; | 
					
						
							| 
									
										
										
										
											2012-03-03 20:19:11 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* STEP 2: FILL LOOP */ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 16:46:51 +11:00
										 |  |  | 	if (pf->f == SF_POLY_NEW) | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | 		twoconnected = true; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* (temporal) security: never much more faces than vertices */ | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 	totface = 0; | 
					
						
							| 
									
										
										
										
											2012-12-27 06:39:27 +00:00
										 |  |  | 	if (flag & BLI_SCANFILL_CALC_HOLES) { | 
					
						
							|  |  |  | 		maxface = 2 * verts;       /* 2*verts: based at a filled circle within a triangle */ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		maxface = verts - 2;       /* when we don't calc any holes, we assume face is a non overlapping loop */ | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-05 05:39:28 +11:00
										 |  |  | 	sc = scdata; | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 	for (a = 0; a < verts; a++) { | 
					
						
							| 
									
										
										
										
											2013-02-15 12:26:47 +00:00
										 |  |  | 		/* printf("VERTEX %d index %d\n", a, sc->vert->tmp.u); */ | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 		/* set connectflags  */ | 
					
						
							|  |  |  | 		for (ed1 = sc->edge_first; ed1; ed1 = eed_next) { | 
					
						
							|  |  |  | 			eed_next = ed1->next; | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 			if (ed1->v1->edge_tot == 1 || ed1->v2->edge_tot == 1) { | 
					
						
							| 
									
										
										
										
											2012-05-13 14:47:53 +00:00
										 |  |  | 				BLI_remlink((ListBase *)&(sc->edge_first), ed1); | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 				BLI_addtail(&sf_ctx->filledgebase, ed1); | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 				if (ed1->v1->edge_tot > 1) ed1->v1->edge_tot--; | 
					
						
							|  |  |  | 				if (ed1->v2->edge_tot > 1) ed1->v2->edge_tot--; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-02-10 17:06:05 +00:00
										 |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 				ed1->v2->f = SF_VERT_AVAILABLE; | 
					
						
							| 
									
										
										
										
											2013-02-10 17:06:05 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-05-13 14:47:53 +00:00
										 |  |  | 		while (sc->edge_first) { /* for as long there are edges */ | 
					
						
							|  |  |  | 			ed1 = sc->edge_first; | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 			ed2 = ed1->next; | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-30 22:53:27 +00:00
										 |  |  | 			/* commented out... the ESC here delivers corrupted memory (and doesnt work during grab) */ | 
					
						
							| 
									
										
										
										
											2012-03-24 07:52:14 +00:00
										 |  |  | 			/* if (callLocalInterruptCallBack()) break; */ | 
					
						
							| 
									
										
										
										
											2012-12-27 06:39:27 +00:00
										 |  |  | 			if (totface >= maxface) { | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 				/* printf("Fill error: endless loop. Escaped at vert %d,  tot: %d.\n", a, verts); */ | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 				a = verts; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-08-07 03:36:05 +00:00
										 |  |  | 			if (ed2 == NULL) { | 
					
						
							| 
									
										
										
										
											2012-05-13 14:47:53 +00:00
										 |  |  | 				sc->edge_first = sc->edge_last = NULL; | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 				/* printf("just 1 edge to vert\n"); */ | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 				BLI_addtail(&sf_ctx->filledgebase, ed1); | 
					
						
							| 
									
										
										
										
											2014-02-13 14:13:42 +11:00
										 |  |  | 				ed1->v2->f = SF_VERT_NEW; | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 				ed1->v1->edge_tot--; | 
					
						
							|  |  |  | 				ed1->v2->edge_tot--; | 
					
						
							| 
									
										
										
										
											2012-03-24 06:18:31 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 				/* test rest of vertices */ | 
					
						
							| 
									
										
										
										
											2013-02-15 12:26:47 +00:00
										 |  |  | 				ScanFillVertLink *best_sc = NULL; | 
					
						
							| 
									
										
										
										
											2016-04-20 09:52:27 +10:00
										 |  |  | 				float angle_best_cos = -1.0f; | 
					
						
							| 
									
										
										
										
											2012-04-18 14:36:56 +00:00
										 |  |  | 				float miny; | 
					
						
							| 
									
										
										
										
											2013-02-15 12:57:11 +00:00
										 |  |  | 				bool firsttime = false; | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 				v1 = ed1->v2; | 
					
						
							|  |  |  | 				v2 = ed1->v1; | 
					
						
							|  |  |  | 				v3 = ed2->v2; | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 				/* this happens with a serial of overlapping edges */ | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 				if (v1 == v2 || v2 == v3) break; | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-15 12:26:47 +00:00
										 |  |  | 				/* printf("test verts %d %d %d\n", v1->tmp.u, v2->tmp.u, v3->tmp.u); */ | 
					
						
							| 
									
										
										
										
											2012-10-23 13:28:22 +00:00
										 |  |  | 				miny = min_ff(v1->xy[1], v3->xy[1]); | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 				sc1 = sc + 1; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-15 12:26:47 +00:00
										 |  |  | 				for (b = a + 1; b < verts; b++, sc1++) { | 
					
						
							| 
									
										
										
										
											2014-02-13 14:13:42 +11:00
										 |  |  | 					if (sc1->vert->f == SF_VERT_NEW) { | 
					
						
							| 
									
										
										
										
											2012-05-13 14:47:53 +00:00
										 |  |  | 						if (sc1->vert->xy[1] <= miny) break; | 
					
						
							| 
									
										
										
										
											2012-12-27 06:39:27 +00:00
										 |  |  | 						if (testedgeside(v1->xy, v2->xy, sc1->vert->xy)) { | 
					
						
							|  |  |  | 							if (testedgeside(v2->xy, v3->xy, sc1->vert->xy)) { | 
					
						
							| 
									
										
										
										
											2012-05-13 14:47:53 +00:00
										 |  |  | 								if (testedgeside(v3->xy, v1->xy, sc1->vert->xy)) { | 
					
						
							| 
									
										
										
										
											2013-02-15 12:26:47 +00:00
										 |  |  | 									/* point is in triangle */ | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-15 12:26:47 +00:00
										 |  |  | 									/* because multiple points can be inside triangle (concave holes) */ | 
					
						
							|  |  |  | 									/* we continue searching and pick the one with sharpest corner */ | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-15 12:57:11 +00:00
										 |  |  | 									if (best_sc == NULL) { | 
					
						
							| 
									
										
										
										
											2013-06-24 18:22:59 +00:00
										 |  |  | 										/* even without holes we need to keep checking [#35861] */ | 
					
						
							| 
									
										
										
										
											2013-02-15 12:26:47 +00:00
										 |  |  | 										best_sc = sc1; | 
					
						
							| 
									
										
										
										
											2013-02-15 12:57:11 +00:00
										 |  |  | 									} | 
					
						
							| 
									
										
										
										
											2013-02-15 12:26:47 +00:00
										 |  |  | 									else { | 
					
						
							|  |  |  | 										/* prevent angle calc for the simple cases only 1 vertex is found */ | 
					
						
							| 
									
										
										
										
											2013-02-15 12:57:11 +00:00
										 |  |  | 										if (firsttime == false) { | 
					
						
							| 
									
										
										
										
											2016-04-20 09:52:27 +10:00
										 |  |  | 											angle_best_cos = cos_v2v2v2(v2->xy, v1->xy, best_sc->vert->xy); | 
					
						
							| 
									
										
										
										
											2013-02-15 12:57:11 +00:00
										 |  |  | 											firsttime = true; | 
					
						
							| 
									
										
										
										
											2013-02-15 12:26:47 +00:00
										 |  |  | 										} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-20 09:52:27 +10:00
										 |  |  | 										const float angle_test_cos = cos_v2v2v2(v2->xy, v1->xy, sc1->vert->xy); | 
					
						
							|  |  |  | 										if (angle_test_cos > angle_best_cos) { | 
					
						
							| 
									
										
										
										
											2013-02-15 12:26:47 +00:00
										 |  |  | 											best_sc = sc1; | 
					
						
							| 
									
										
										
										
											2016-04-20 09:52:27 +10:00
										 |  |  | 											angle_best_cos = angle_test_cos; | 
					
						
							| 
									
										
										
										
											2013-02-15 12:26:47 +00:00
										 |  |  | 										} | 
					
						
							|  |  |  | 									} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2012-12-27 06:39:27 +00:00
										 |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-15 12:26:47 +00:00
										 |  |  | 				if (best_sc) { | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 					/* make new edge, and start over */ | 
					
						
							| 
									
										
										
										
											2013-02-15 12:26:47 +00:00
										 |  |  | 					/* printf("add new edge %d %d and start again\n", v2->tmp.u, best_sc->vert->tmp.u); */ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-15 12:26:47 +00:00
										 |  |  | 					ed3 = BLI_scanfill_edge_add(sf_ctx, v2, best_sc->vert); | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 					BLI_remlink(&sf_ctx->filledgebase, ed3); | 
					
						
							| 
									
										
										
										
											2012-05-13 14:47:53 +00:00
										 |  |  | 					BLI_insertlinkbefore((ListBase *)&(sc->edge_first), ed2, ed3); | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 					ed3->v2->f = SF_VERT_AVAILABLE; | 
					
						
							| 
									
										
										
										
											2014-02-13 14:13:42 +11:00
										 |  |  | 					ed3->f = SF_EDGE_INTERNAL; | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 					ed3->v1->edge_tot++; | 
					
						
							|  |  |  | 					ed3->v2->edge_tot++; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				else { | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 					/* new triangle */ | 
					
						
							| 
									
										
										
										
											2013-02-15 12:26:47 +00:00
										 |  |  | 					/* printf("add face %d %d %d\n", v1->tmp.u, v2->tmp.u, v3->tmp.u); */ | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 					addfillface(sf_ctx, v1, v2, v3); | 
					
						
							| 
									
										
										
										
											2004-09-18 20:15:37 +00:00
										 |  |  | 					totface++; | 
					
						
							| 
									
										
										
										
											2012-05-13 14:47:53 +00:00
										 |  |  | 					BLI_remlink((ListBase *)&(sc->edge_first), ed1); | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 					BLI_addtail(&sf_ctx->filledgebase, ed1); | 
					
						
							| 
									
										
										
										
											2014-02-13 14:13:42 +11:00
										 |  |  | 					ed1->v2->f = SF_VERT_NEW; | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 					ed1->v1->edge_tot--; | 
					
						
							|  |  |  | 					ed1->v2->edge_tot--; | 
					
						
							| 
									
										
										
										
											2011-11-29 11:49:53 +00:00
										 |  |  | 					/* ed2 can be removed when it's a boundary edge */ | 
					
						
							| 
									
										
										
										
											2014-02-13 14:13:42 +11:00
										 |  |  | 					if (((ed2->f == SF_EDGE_NEW) && twoconnected) /* || (ed2->f == SF_EDGE_BOUNDARY) */) { | 
					
						
							| 
									
										
										
										
											2012-05-13 14:47:53 +00:00
										 |  |  | 						BLI_remlink((ListBase *)&(sc->edge_first), ed2); | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 						BLI_addtail(&sf_ctx->filledgebase, ed2); | 
					
						
							| 
									
										
										
										
											2014-02-13 14:13:42 +11:00
										 |  |  | 						ed2->v2->f = SF_VERT_NEW; | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 						ed2->v1->edge_tot--; | 
					
						
							|  |  |  | 						ed2->v2->edge_tot--; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 					/* new edge */ | 
					
						
							| 
									
										
										
										
											2012-05-05 00:23:55 +00:00
										 |  |  | 					ed3 = BLI_scanfill_edge_add(sf_ctx, v1, v3); | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 					BLI_remlink(&sf_ctx->filledgebase, ed3); | 
					
						
							| 
									
										
										
										
											2014-02-13 14:13:42 +11:00
										 |  |  | 					ed3->f = SF_EDGE_INTERNAL; | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 					ed3->v1->edge_tot++; | 
					
						
							|  |  |  | 					ed3->v2->edge_tot++; | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-29 01:54:58 +00:00
										 |  |  | 					/* printf("add new edge %x %x\n", v1, v3); */ | 
					
						
							| 
									
										
										
										
											2014-02-05 05:39:28 +11:00
										 |  |  | 					sc1 = addedgetoscanlist(scdata, ed3, verts); | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 					if (sc1) {  /* ed3 already exists: remove if a boundary */ | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 						/* printf("Edge exists\n"); */ | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 						ed3->v1->edge_tot--; | 
					
						
							|  |  |  | 						ed3->v2->edge_tot--; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 						for (ed3 = sc1->edge_first; ed3; ed3 = ed3->next) { | 
					
						
							| 
									
										
										
										
											2014-01-16 19:15:53 +11:00
										 |  |  | 							if ((ed3->v1 == v1 && ed3->v2 == v3) || (ed3->v1 == v3 && ed3->v2 == v1)) { | 
					
						
							| 
									
										
										
										
											2014-02-13 14:13:42 +11:00
										 |  |  | 								if (twoconnected /* || (ed3->f == SF_EDGE_BOUNDARY) */) { | 
					
						
							| 
									
										
										
										
											2012-05-13 14:47:53 +00:00
										 |  |  | 									BLI_remlink((ListBase *)&(sc1->edge_first), ed3); | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 									BLI_addtail(&sf_ctx->filledgebase, ed3); | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 									ed3->v1->edge_tot--; | 
					
						
							|  |  |  | 									ed3->v2->edge_tot--; | 
					
						
							| 
									
										
										
										
											2011-11-29 11:49:53 +00:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 								break; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 			/* test for loose edges */ | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 			for (ed1 = sc->edge_first; ed1; ed1 = eed_next) { | 
					
						
							|  |  |  | 				eed_next = ed1->next; | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 				if (ed1->v1->edge_tot < 2 || ed1->v2->edge_tot < 2) { | 
					
						
							| 
									
										
										
										
											2012-05-13 14:47:53 +00:00
										 |  |  | 					BLI_remlink((ListBase *)&(sc->edge_first), ed1); | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 					BLI_addtail(&sf_ctx->filledgebase, ed1); | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 					if (ed1->v1->edge_tot > 1) ed1->v1->edge_tot--; | 
					
						
							|  |  |  | 					if (ed1->v2->edge_tot > 1) ed1->v2->edge_tot--; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 			/* done with loose edges */ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-12-27 06:39:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		sc++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-05 05:39:28 +11:00
										 |  |  | 	MEM_freeN(scdata); | 
					
						
							| 
									
										
										
										
											2011-05-13 16:04:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-27 06:39:27 +00:00
										 |  |  | 	BLI_assert(totface <= maxface); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-13 16:04:20 +00:00
										 |  |  | 	return totface; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-10 23:52:07 +00:00
										 |  |  | void BLI_scanfill_begin(ScanFillContext *sf_ctx) | 
					
						
							| 
									
										
										
										
											2011-04-16 23:58:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 	memset(sf_ctx, 0, sizeof(*sf_ctx)); | 
					
						
							| 
									
										
										
										
											2014-02-06 02:10:19 +11:00
										 |  |  | 	sf_ctx->poly_nr = SF_POLY_UNSET; | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | 	sf_ctx->arena = BLI_memarena_new(BLI_SCANFILL_ARENA_SIZE, __func__); | 
					
						
							| 
									
										
										
										
											2011-04-16 23:58:49 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | void BLI_scanfill_begin_arena(ScanFillContext *sf_ctx, MemArena *arena) | 
					
						
							| 
									
										
										
										
											2012-04-16 18:24:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | 	memset(sf_ctx, 0, sizeof(*sf_ctx)); | 
					
						
							| 
									
										
										
										
											2014-02-06 02:10:19 +11:00
										 |  |  | 	sf_ctx->poly_nr = SF_POLY_UNSET; | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | 	sf_ctx->arena = arena; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BLI_scanfill_end(ScanFillContext *sf_ctx) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BLI_memarena_free(sf_ctx->arena); | 
					
						
							|  |  |  | 	sf_ctx->arena = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-08 06:07:10 +11:00
										 |  |  | 	BLI_listbase_clear(&sf_ctx->fillvertbase); | 
					
						
							|  |  |  | 	BLI_listbase_clear(&sf_ctx->filledgebase); | 
					
						
							|  |  |  | 	BLI_listbase_clear(&sf_ctx->fillfacebase); | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BLI_scanfill_end_arena(ScanFillContext *sf_ctx, MemArena *arena) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BLI_memarena_clear(arena); | 
					
						
							|  |  |  | 	BLI_assert(sf_ctx->arena == arena); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-08 06:07:10 +11:00
										 |  |  | 	BLI_listbase_clear(&sf_ctx->fillvertbase); | 
					
						
							|  |  |  | 	BLI_listbase_clear(&sf_ctx->filledgebase); | 
					
						
							|  |  |  | 	BLI_listbase_clear(&sf_ctx->fillfacebase); | 
					
						
							| 
									
										
										
										
											2012-04-16 18:24:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | unsigned int BLI_scanfill_calc_ex(ScanFillContext *sf_ctx, const int flag, const float nor_proj[3]) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							| 
									
										
										
										
											2012-03-03 20:19:11 +00:00
										 |  |  | 	 * - fill works with its own lists, so create that first (no faces!) | 
					
						
							|  |  |  | 	 * - for vertices, put in ->tmp.v the old pointer | 
					
						
							|  |  |  | 	 * - struct elements xs en ys are not used here: don't hide stuff in it | 
					
						
							|  |  |  | 	 * - edge flag ->f becomes 2 when it's a new edge | 
					
						
							|  |  |  | 	 * - mode: & 1 is check for crossings, then create edges (TO DO ) | 
					
						
							|  |  |  | 	 * - returns number of triangle faces added. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	ListBase tempve, temped; | 
					
						
							| 
									
										
										
										
											2012-02-19 22:17:30 +00:00
										 |  |  | 	ScanFillVert *eve; | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | 	ScanFillEdge *eed, *eed_next; | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 	PolyFill *pflist, *pf; | 
					
						
							| 
									
										
										
										
											2012-04-16 16:24:55 +00:00
										 |  |  | 	float *min_xy_p, *max_xy_p; | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | 	unsigned int totfaces = 0;  /* total faces added */ | 
					
						
							|  |  |  | 	unsigned short a, c, poly = 0; | 
					
						
							|  |  |  | 	bool ok; | 
					
						
							| 
									
										
										
										
											2013-04-26 21:04:12 +00:00
										 |  |  | 	float mat_2d[3][3]; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-02 22:54:00 +00:00
										 |  |  | 	BLI_assert(!nor_proj || len_squared_v3(nor_proj) > FLT_EPSILON); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-05 05:00:17 +11:00
										 |  |  | #ifdef DEBUG
 | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 	for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) { | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | 		/* these values used to be set,
 | 
					
						
							|  |  |  | 		 * however they should always be zero'd so check instead */ | 
					
						
							|  |  |  | 		BLI_assert(eve->f == 0); | 
					
						
							| 
									
										
										
										
											2014-02-05 05:22:21 +11:00
										 |  |  | 		BLI_assert(sf_ctx->poly_nr || eve->poly_nr == 0); | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | 		BLI_assert(eve->edge_tot == 0); | 
					
						
							| 
									
										
										
										
											2009-07-22 22:35:58 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-05 05:00:17 +11:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-07-22 22:35:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* first test vertices if they are in edges */ | 
					
						
							|  |  |  | 	/* including resetting of flags */ | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 	for (eed = sf_ctx->filledgebase.first; eed; eed = eed->next) { | 
					
						
							| 
									
										
										
										
											2014-02-06 02:10:19 +11:00
										 |  |  | 		BLI_assert(sf_ctx->poly_nr != SF_POLY_UNSET || eed->poly_nr == SF_POLY_UNSET); | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 		eed->v1->f = SF_VERT_AVAILABLE; | 
					
						
							|  |  |  | 		eed->v2->f = SF_VERT_AVAILABLE; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 	for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) { | 
					
						
							| 
									
										
										
										
											2014-02-13 14:13:42 +11:00
										 |  |  | 		if (eve->f == SF_VERT_AVAILABLE) { | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-05 05:00:17 +11:00
										 |  |  | 	if (UNLIKELY(eve == NULL)) { | 
					
						
							| 
									
										
										
										
											2012-04-16 16:24:55 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-04-16 18:24:49 +00:00
										 |  |  | 		float n[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (nor_proj) { | 
					
						
							|  |  |  | 			copy_v3_v3(n, nor_proj); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			/* define projection: with 'best' normal */ | 
					
						
							|  |  |  | 			/* Newell's Method */ | 
					
						
							|  |  |  | 			/* Similar code used elsewhere, but this checks for double ups
 | 
					
						
							|  |  |  | 			 * which historically this function supports so better not change */ | 
					
						
							| 
									
										
										
										
											2014-08-07 14:42:47 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			/* warning: this only gives stable direction with single polygons,
 | 
					
						
							| 
									
										
										
										
											2014-08-17 12:18:40 +10:00
										 |  |  | 			 * ideally we'd calculate connectivity and each polys normal, see T41047 */ | 
					
						
							| 
									
										
										
										
											2014-04-27 00:20:55 +10:00
										 |  |  | 			const float *v_prev; | 
					
						
							| 
									
										
										
										
											2012-04-16 18:24:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			zero_v3(n); | 
					
						
							|  |  |  | 			eve = sf_ctx->fillvertbase.last; | 
					
						
							| 
									
										
										
										
											2012-04-16 16:24:55 +00:00
										 |  |  | 			v_prev = eve->co; | 
					
						
							| 
									
										
										
										
											2012-04-16 18:24:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) { | 
					
						
							| 
									
										
										
										
											2012-04-18 14:30:57 +00:00
										 |  |  | 				if (LIKELY(!compare_v3v3(v_prev, eve->co, SF_EPSILON))) { | 
					
						
							| 
									
										
										
										
											2012-04-16 18:24:49 +00:00
										 |  |  | 					add_newell_cross_v3_v3v3(n, v_prev, eve->co); | 
					
						
							| 
									
										
										
										
											2012-04-18 14:06:59 +00:00
										 |  |  | 					v_prev = eve->co; | 
					
						
							| 
									
										
										
										
											2012-04-16 18:24:49 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-03-20 19:32:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 16:24:55 +00:00
										 |  |  | 		if (UNLIKELY(normalize_v3(n) == 0.0f)) { | 
					
						
							| 
									
										
										
										
											2012-04-18 05:52:18 +00:00
										 |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											2012-04-16 16:24:55 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-26 21:04:12 +00:00
										 |  |  | 		axis_dominant_v3_to_m3(mat_2d, n); | 
					
						
							| 
									
										
										
										
											2012-04-16 16:24:55 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* STEP 1: COUNT POLYS */ | 
					
						
							| 
									
										
										
										
											2014-02-06 02:10:19 +11:00
										 |  |  | 	if (sf_ctx->poly_nr != SF_POLY_UNSET) { | 
					
						
							|  |  |  | 		poly = (unsigned short)(sf_ctx->poly_nr + 1); | 
					
						
							|  |  |  | 		sf_ctx->poly_nr = SF_POLY_UNSET; | 
					
						
							| 
									
										
										
										
											2014-02-05 05:22:21 +11:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 19:09:28 +11:00
										 |  |  | 	if (flag & BLI_SCANFILL_CALC_POLYS && (poly == 0)) { | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 		for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) { | 
					
						
							| 
									
										
										
										
											2013-04-26 21:04:12 +00:00
										 |  |  | 			mul_v2_m3v3(eve->xy, mat_2d, eve->co); | 
					
						
							| 
									
										
										
										
											2012-12-27 06:39:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			/* get first vertex with no poly number */ | 
					
						
							| 
									
										
										
										
											2014-02-06 02:10:19 +11:00
										 |  |  | 			if (eve->poly_nr == SF_POLY_UNSET) { | 
					
						
							| 
									
										
										
										
											2014-02-05 05:00:17 +11:00
										 |  |  | 				unsigned int toggle = 0; | 
					
						
							| 
									
										
										
										
											2012-12-27 06:39:27 +00:00
										 |  |  | 				/* now a sort of select connected */ | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | 				ok = true; | 
					
						
							| 
									
										
										
										
											2012-12-27 06:39:27 +00:00
										 |  |  | 				eve->poly_nr = poly; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				while (ok) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | 					ok = false; | 
					
						
							| 
									
										
										
										
											2012-12-27 06:39:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | 					toggle++; | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 					for (eed = (toggle & 1) ? sf_ctx->filledgebase.first : sf_ctx->filledgebase.last; | 
					
						
							|  |  |  | 					     eed; | 
					
						
							|  |  |  | 					     eed = (toggle & 1) ? eed->next : eed->prev) | 
					
						
							|  |  |  | 					{ | 
					
						
							| 
									
										
										
										
											2014-02-06 02:10:19 +11:00
										 |  |  | 						if (eed->v1->poly_nr == SF_POLY_UNSET && eed->v2->poly_nr == poly) { | 
					
						
							| 
									
										
										
										
											2012-12-27 06:39:27 +00:00
										 |  |  | 							eed->v1->poly_nr = poly; | 
					
						
							|  |  |  | 							eed->poly_nr = poly; | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | 							ok = true; | 
					
						
							| 
									
										
										
										
											2012-12-27 06:39:27 +00:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2014-02-06 02:10:19 +11:00
										 |  |  | 						else if (eed->v2->poly_nr == SF_POLY_UNSET && eed->v1->poly_nr == poly) { | 
					
						
							| 
									
										
										
										
											2012-12-27 06:39:27 +00:00
										 |  |  | 							eed->v2->poly_nr = poly; | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 							eed->poly_nr = poly; | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | 							ok = true; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2014-02-06 02:10:19 +11:00
										 |  |  | 						else if (eed->poly_nr == SF_POLY_UNSET) { | 
					
						
							| 
									
										
										
										
											2012-12-27 06:39:27 +00:00
										 |  |  | 							if (eed->v1->poly_nr == poly && eed->v2->poly_nr == poly) { | 
					
						
							|  |  |  | 								eed->poly_nr = poly; | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | 								ok = true; | 
					
						
							| 
									
										
										
										
											2012-12-27 06:39:27 +00:00
										 |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-02-06 02:10:19 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				poly++; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-12-27 06:39:27 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-12-29 01:54:58 +00:00
										 |  |  | 		/* printf("amount of poly's: %d\n", poly); */ | 
					
						
							| 
									
										
										
										
											2012-12-27 06:39:27 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-05 05:22:21 +11:00
										 |  |  | 	else if (poly) { | 
					
						
							|  |  |  | 		/* we pre-calculated poly_nr */ | 
					
						
							|  |  |  | 		for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) { | 
					
						
							|  |  |  | 			mul_v2_m3v3(eve->xy, mat_2d, eve->co); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-12-27 06:39:27 +00:00
										 |  |  | 	else { | 
					
						
							|  |  |  | 		poly = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 		for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) { | 
					
						
							| 
									
										
										
										
											2013-04-26 21:04:12 +00:00
										 |  |  | 			mul_v2_m3v3(eve->xy, mat_2d, eve->co); | 
					
						
							| 
									
										
										
										
											2014-02-06 02:10:19 +11:00
										 |  |  | 			eve->poly_nr = 0; | 
					
						
							| 
									
										
										
										
											2012-12-27 06:39:27 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		for (eed = sf_ctx->filledgebase.first; eed; eed = eed->next) { | 
					
						
							| 
									
										
										
										
											2014-02-06 02:10:19 +11:00
										 |  |  | 			eed->poly_nr = 0; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* STEP 2: remove loose edges and strings of edges */ | 
					
						
							| 
									
										
										
										
											2014-02-04 02:54:19 +11:00
										 |  |  | 	if (flag & BLI_SCANFILL_CALC_LOOSE) { | 
					
						
							| 
									
										
										
										
											2014-02-05 05:00:17 +11:00
										 |  |  | 		unsigned int toggle = 0; | 
					
						
							| 
									
										
										
										
											2014-02-04 02:54:19 +11:00
										 |  |  | 		for (eed = sf_ctx->filledgebase.first; eed; eed = eed->next) { | 
					
						
							|  |  |  | 			if (eed->v1->edge_tot++ > 250) break; | 
					
						
							|  |  |  | 			if (eed->v2->edge_tot++ > 250) break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (eed) { | 
					
						
							|  |  |  | 			/* otherwise it's impossible to be sure you can clear vertices */ | 
					
						
							| 
									
										
										
										
											2013-08-28 02:14:24 +00:00
										 |  |  | #ifdef DEBUG
 | 
					
						
							| 
									
										
										
										
											2014-02-04 02:54:19 +11:00
										 |  |  | 			printf("No vertices with 250 edges allowed!\n"); | 
					
						
							| 
									
										
										
										
											2013-08-28 02:14:24 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-02-04 02:54:19 +11:00
										 |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* does it only for vertices with (->edge_tot == 1) */ | 
					
						
							|  |  |  | 		testvertexnearedge(sf_ctx); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ok = true; | 
					
						
							|  |  |  | 		while (ok) { | 
					
						
							|  |  |  | 			ok = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			toggle++; | 
					
						
							|  |  |  | 			for (eed = (toggle & 1) ? sf_ctx->filledgebase.first : sf_ctx->filledgebase.last; | 
					
						
							|  |  |  | 			     eed; | 
					
						
							|  |  |  | 			     eed = eed_next) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				eed_next = (toggle & 1) ? eed->next : eed->prev; | 
					
						
							|  |  |  | 				if (eed->v1->edge_tot == 1) { | 
					
						
							|  |  |  | 					eed->v2->edge_tot--; | 
					
						
							|  |  |  | 					BLI_remlink(&sf_ctx->fillvertbase, eed->v1); | 
					
						
							|  |  |  | 					BLI_remlink(&sf_ctx->filledgebase, eed); | 
					
						
							|  |  |  | 					ok = true; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else if (eed->v2->edge_tot == 1) { | 
					
						
							|  |  |  | 					eed->v1->edge_tot--; | 
					
						
							|  |  |  | 					BLI_remlink(&sf_ctx->fillvertbase, eed->v2); | 
					
						
							|  |  |  | 					BLI_remlink(&sf_ctx->filledgebase, eed); | 
					
						
							|  |  |  | 					ok = true; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-08 06:07:10 +11:00
										 |  |  | 		if (BLI_listbase_is_empty(&sf_ctx->filledgebase)) { | 
					
						
							| 
									
										
										
										
											2014-02-04 02:54:19 +11:00
										 |  |  | 			/* printf("All edges removed\n"); */ | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-04 02:54:19 +11:00
										 |  |  | 	else { | 
					
						
							|  |  |  | 		/* skip checks for loose edges */ | 
					
						
							|  |  |  | 		for (eed = sf_ctx->filledgebase.first; eed; eed = eed->next) { | 
					
						
							|  |  |  | 			eed->v1->edge_tot++; | 
					
						
							|  |  |  | 			eed->v2->edge_tot++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | #ifdef DEBUG
 | 
					
						
							|  |  |  | 		/* ensure we're right! */ | 
					
						
							|  |  |  | 		for (eed = sf_ctx->filledgebase.first; eed; eed = eed->next) { | 
					
						
							|  |  |  | 			BLI_assert(eed->v1->edge_tot != 1); | 
					
						
							|  |  |  | 			BLI_assert(eed->v2->edge_tot != 1); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* CURRENT STATUS:
 | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 	 * - eve->f        :1 = available in edges | 
					
						
							|  |  |  | 	 * - eve->poly_nr  :polynumber | 
					
						
							|  |  |  | 	 * - eve->edge_tot :amount of edges connected to vertex | 
					
						
							|  |  |  | 	 * - eve->tmp.v    :store! original vertex number | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2013-02-21 17:15:55 +00:00
										 |  |  | 	 * - eed->f        :1 = boundary edge (optionally set by caller) | 
					
						
							|  |  |  | 	 * - eed->poly_nr  :poly number | 
					
						
							| 
									
										
										
										
											2012-03-03 20:19:11 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* STEP 3: MAKE POLYFILL STRUCT */ | 
					
						
							| 
									
										
										
										
											2014-02-06 01:02:22 +11:00
										 |  |  | 	pflist = MEM_mallocN(sizeof(*pflist) * (size_t)poly, "edgefill"); | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 	pf = pflist; | 
					
						
							| 
									
										
										
										
											2014-02-06 02:10:19 +11:00
										 |  |  | 	for (a = 0; a < poly; a++) { | 
					
						
							| 
									
										
										
										
											2014-02-06 01:02:22 +11:00
										 |  |  | 		pf->edges = pf->verts = 0; | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | 		pf->min_xy[0] = pf->min_xy[1] =  1.0e20f; | 
					
						
							|  |  |  | 		pf->max_xy[0] = pf->max_xy[1] = -1.0e20f; | 
					
						
							| 
									
										
										
										
											2014-02-13 16:46:51 +11:00
										 |  |  | 		pf->f = SF_POLY_NEW; | 
					
						
							| 
									
										
										
										
											2014-02-06 01:02:22 +11:00
										 |  |  | 		pf->nr = a; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		pf++; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 	for (eed = sf_ctx->filledgebase.first; eed; eed = eed->next) { | 
					
						
							| 
									
										
										
										
											2014-02-06 02:10:19 +11:00
										 |  |  | 		pflist[eed->poly_nr].edges++; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-04 02:23:01 +11:00
										 |  |  | 	for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) { | 
					
						
							| 
									
										
										
										
											2014-02-06 02:10:19 +11:00
										 |  |  | 		pflist[eve->poly_nr].verts++; | 
					
						
							|  |  |  | 		min_xy_p = pflist[eve->poly_nr].min_xy; | 
					
						
							|  |  |  | 		max_xy_p = pflist[eve->poly_nr].max_xy; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 		min_xy_p[0] = (min_xy_p[0]) < (eve->xy[0]) ? (min_xy_p[0]) : (eve->xy[0]); | 
					
						
							|  |  |  | 		min_xy_p[1] = (min_xy_p[1]) < (eve->xy[1]) ? (min_xy_p[1]) : (eve->xy[1]); | 
					
						
							|  |  |  | 		max_xy_p[0] = (max_xy_p[0]) > (eve->xy[0]) ? (max_xy_p[0]) : (eve->xy[0]); | 
					
						
							|  |  |  | 		max_xy_p[1] = (max_xy_p[1]) > (eve->xy[1]) ? (max_xy_p[1]) : (eve->xy[1]); | 
					
						
							| 
									
										
										
										
											2014-02-13 16:46:51 +11:00
										 |  |  | 		if (eve->edge_tot > 2) { | 
					
						
							|  |  |  | 			pflist[eve->poly_nr].f = SF_POLY_VALID; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* STEP 4: FIND HOLES OR BOUNDS, JOIN THEM
 | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 	 *  ( bounds just to divide it in pieces for optimization, | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	 *    the edgefill itself has good auto-hole detection) | 
					
						
							|  |  |  | 	 * WATCH IT: ONLY WORKS WITH SORTED POLYS!!! */ | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 11:47:00 +11:00
										 |  |  | 	if ((flag & BLI_SCANFILL_CALC_HOLES) && (poly > 1)) { | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | 		unsigned short *polycache, *pc; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 		/* so, sort first */ | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | 		qsort(pflist, (size_t)poly, sizeof(PolyFill), vergpoly); | 
					
						
							| 
									
										
										
										
											2012-03-03 20:19:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 		pf = pflist; | 
					
						
							| 
									
										
										
										
											2014-02-06 02:10:19 +11:00
										 |  |  | 		for (a = 0; a < poly; a++) { | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 			printf("poly:%d edges:%d verts:%d flag: %d\n", a, pf->edges, pf->verts, pf->f); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 			PRINT2(f, f, pf->min[0], pf->min[1]); | 
					
						
							|  |  |  | 			pf++; | 
					
						
							| 
									
										
										
										
											2012-03-03 20:19:11 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-02-06 01:02:22 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		polycache = pc = MEM_callocN(sizeof(*polycache) * (size_t)poly, "polycache"); | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 		pf = pflist; | 
					
						
							|  |  |  | 		for (a = 0; a < poly; a++, pf++) { | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | 			for (c = (unsigned short)(a + 1); c < poly; c++) { | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 				/* if 'a' inside 'c': join (bbox too)
 | 
					
						
							|  |  |  | 				 * Careful: 'a' can also be inside another poly. | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 				 */ | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 				if (boundisect(pf, pflist + c)) { | 
					
						
							|  |  |  | 					*pc = c; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 					pc++; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 				/* only for optimize! */ | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 				/* else if (pf->max_xy[0] < (pflist+c)->min[cox]) break; */ | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 			while (pc != polycache) { | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 				pc--; | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 				mergepolysSimp(sf_ctx, pf, pflist + *pc); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		MEM_freeN(polycache); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-03 20:19:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  | 	printf("after merge\n"); | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 	pf = pflist; | 
					
						
							| 
									
										
										
										
											2014-02-06 02:10:19 +11:00
										 |  |  | 	for (a = 0; a < poly; a++) { | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 		printf("poly:%d edges:%d verts:%d flag: %d\n", a, pf->edges, pf->verts, pf->f); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		pf++; | 
					
						
							| 
									
										
										
										
											2012-03-03 20:19:11 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* STEP 5: MAKE TRIANGLES */ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 	tempve.first = sf_ctx->fillvertbase.first; | 
					
						
							|  |  |  | 	tempve.last = sf_ctx->fillvertbase.last; | 
					
						
							|  |  |  | 	temped.first = sf_ctx->filledgebase.first; | 
					
						
							|  |  |  | 	temped.last = sf_ctx->filledgebase.last; | 
					
						
							| 
									
										
										
										
											2014-02-08 06:07:10 +11:00
										 |  |  | 	BLI_listbase_clear(&sf_ctx->fillvertbase); | 
					
						
							|  |  |  | 	BLI_listbase_clear(&sf_ctx->filledgebase); | 
					
						
							| 
									
										
										
										
											2012-04-16 05:23:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	pf = pflist; | 
					
						
							|  |  |  | 	for (a = 0; a < poly; a++) { | 
					
						
							|  |  |  | 		if (pf->edges > 1) { | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 			splitlist(sf_ctx, &tempve, &temped, pf->nr); | 
					
						
							| 
									
										
										
										
											2012-11-26 23:18:04 +00:00
										 |  |  | 			totfaces += scanfill(sf_ctx, pf, flag); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		pf++; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-04-16 06:48:57 +00:00
										 |  |  | 	BLI_movelisttolist(&sf_ctx->fillvertbase, &tempve); | 
					
						
							|  |  |  | 	BLI_movelisttolist(&sf_ctx->filledgebase, &temped); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-26 16:02:26 +00:00
										 |  |  | 	/* FREE */ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MEM_freeN(pflist); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-13 16:04:20 +00:00
										 |  |  | 	return totfaces; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 03:37:45 +00:00
										 |  |  | unsigned int BLI_scanfill_calc(ScanFillContext *sf_ctx, const int flag) | 
					
						
							| 
									
										
										
										
											2013-08-28 02:07:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	return BLI_scanfill_calc_ex(sf_ctx, flag, NULL); | 
					
						
							|  |  |  | } |