2012-04-27 07:26:28 +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
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup bli
|
2012-04-27 07:26:28 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "DNA_vec_types.h"
|
|
|
|
|
|
|
|
#include "BLI_math.h"
|
2013-09-01 03:43:10 +00:00
|
|
|
#include "BLI_strict_flags.h"
|
2012-04-27 07:26:28 +00:00
|
|
|
|
2018-02-18 21:27:33 +11:00
|
|
|
#include "BLI_lasso_2d.h" /* own include */
|
2012-04-27 07:26:28 +00:00
|
|
|
|
2013-09-01 03:43:10 +00:00
|
|
|
void BLI_lasso_boundbox(rcti *rect, const int mcords[][2], const unsigned int moves)
|
2012-04-27 07:26:28 +00:00
|
|
|
{
|
2013-09-01 03:43:10 +00:00
|
|
|
unsigned int a;
|
2012-04-27 07:26:28 +00:00
|
|
|
|
|
|
|
rect->xmin = rect->xmax = mcords[0][0];
|
|
|
|
rect->ymin = rect->ymax = mcords[0][1];
|
|
|
|
|
|
|
|
for (a = 1; a < moves; a++) {
|
|
|
|
if (mcords[a][0] < rect->xmin) rect->xmin = mcords[a][0];
|
|
|
|
else if (mcords[a][0] > rect->xmax) rect->xmax = mcords[a][0];
|
|
|
|
if (mcords[a][1] < rect->ymin) rect->ymin = mcords[a][1];
|
|
|
|
else if (mcords[a][1] > rect->ymax) rect->ymax = mcords[a][1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-01 03:43:10 +00:00
|
|
|
bool BLI_lasso_is_point_inside(const int mcords[][2], const unsigned int moves,
|
2013-03-09 05:35:49 +00:00
|
|
|
const int sx, const int sy,
|
|
|
|
const int error_value)
|
2012-04-27 07:26:28 +00:00
|
|
|
{
|
2013-09-01 03:43:10 +00:00
|
|
|
if (sx == error_value || moves == 0) {
|
2013-03-09 05:35:49 +00:00
|
|
|
return false;
|
2012-04-27 07:26:28 +00:00
|
|
|
}
|
2013-03-14 21:44:16 +00:00
|
|
|
else {
|
|
|
|
int pt[2] = {sx, sy};
|
2013-10-04 10:48:24 +00:00
|
|
|
return isect_point_poly_v2_int(pt, mcords, moves, true);
|
2012-04-27 07:26:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* edge version for lasso select. we assume boundbox check was done */
|
2013-09-01 03:43:10 +00:00
|
|
|
bool BLI_lasso_is_edge_inside(const int mcords[][2], const unsigned int moves,
|
2013-03-09 05:35:49 +00:00
|
|
|
int x0, int y0, int x1, int y1,
|
|
|
|
const int error_value)
|
2012-04-27 07:26:28 +00:00
|
|
|
{
|
|
|
|
|
2013-09-01 03:43:10 +00:00
|
|
|
if (x0 == error_value || x1 == error_value || moves == 0) {
|
2013-03-09 05:35:49 +00:00
|
|
|
return false;
|
2012-04-27 07:26:28 +00:00
|
|
|
}
|
|
|
|
|
2016-03-05 09:16:12 +11:00
|
|
|
const int v1[2] = {x0, y0}, v2[2] = {x1, y1};
|
2012-04-27 07:26:28 +00:00
|
|
|
|
|
|
|
/* check points in lasso */
|
2013-03-09 05:35:49 +00:00
|
|
|
if (BLI_lasso_is_point_inside(mcords, moves, v1[0], v1[1], error_value)) return true;
|
|
|
|
if (BLI_lasso_is_point_inside(mcords, moves, v2[0], v2[1], error_value)) return true;
|
2012-04-27 07:26:28 +00:00
|
|
|
|
|
|
|
/* no points in lasso, so we have to intersect with lasso edge */
|
|
|
|
|
2015-11-13 07:25:36 +11:00
|
|
|
if (isect_seg_seg_v2_int(mcords[0], mcords[moves - 1], v1, v2) > 0) return true;
|
2016-03-05 09:16:12 +11:00
|
|
|
for (unsigned int a = 0; a < moves - 1; a++) {
|
2015-11-13 07:25:36 +11:00
|
|
|
if (isect_seg_seg_v2_int(mcords[a], mcords[a + 1], v1, v2) > 0) return true;
|
2012-04-27 07:26:28 +00:00
|
|
|
}
|
|
|
|
|
2013-03-09 05:35:49 +00:00
|
|
|
return false;
|
2012-04-27 07:26:28 +00:00
|
|
|
}
|