This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/blenlib/BLI_kdtree_impl.h
Ray molenkamp ea70bd2abf MSVC: Fix macro collision with MSVC Headers
Picked up while investigating a build error on the functions branch
which seems to use this specific header in a way master doesn't.

The problem:

The MSVC headers define a `_CONCAT` macro, so does BLI_kdtree_imp.h
however at the end `BLI_kdtree_imp.h` undefines the macro making the
MS headers that still rely on it "unhappy".

Who's fault is this:

Ours, C99 Spec says

```
7.1.3 Reserved identifiers

- All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.

...

if the program removes (with #undef) any macro definition of an identifier in the first
group listed above, the behavior is undefined.
```

So we should not have defined it, and we definitely should not
have undefined it.

We have *tons* of these violations, although fixing them would be great
at one point lots of them are in /extern or in the 3rd party deps,
I'd rather deal with them on a case by case basis when it actually
causes issues.

Differential Revision: https://developer.blender.org/D5790

Reviewers: campbellbarton, JacquesLucke
2019-09-14 09:59:42 -06:00

99 lines
3.8 KiB
C++

/*
* 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.
*/
/** \file
* \ingroup bli
* \brief A kd-tree for nearest neighbor search.
*/
#include "BLI_compiler_attrs.h"
#define _BLI_CONCAT_AUX(MACRO_ARG1, MACRO_ARG2) MACRO_ARG1##MACRO_ARG2
#define _BLI_CONCAT(MACRO_ARG1, MACRO_ARG2) _BLI_CONCAT_AUX(MACRO_ARG1, MACRO_ARG2)
#define BLI_kdtree_nd_(id) _BLI_CONCAT(KDTREE_PREFIX_ID, _##id)
struct KDTree;
typedef struct KDTree KDTree;
typedef struct KDTreeNearest {
int index;
float dist;
float co[KD_DIMS];
} KDTreeNearest;
KDTree *BLI_kdtree_nd_(new)(unsigned int maxsize);
void BLI_kdtree_nd_(free)(KDTree *tree);
void BLI_kdtree_nd_(balance)(KDTree *tree) ATTR_NONNULL(1);
void BLI_kdtree_nd_(insert)(KDTree *tree, int index, const float co[KD_DIMS]) ATTR_NONNULL(1, 3);
int BLI_kdtree_nd_(find_nearest)(const KDTree *tree,
const float co[KD_DIMS],
KDTreeNearest *r_nearest) ATTR_NONNULL(1, 2);
int BLI_kdtree_nd_(find_nearest_n)(const KDTree *tree,
const float co[KD_DIMS],
KDTreeNearest *r_nearest,
const uint nearest_len_capacity) ATTR_NONNULL(1, 2, 3);
int BLI_kdtree_nd_(range_search)(const KDTree *tree,
const float co[KD_DIMS],
KDTreeNearest **r_nearest,
const float range) ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT;
int BLI_kdtree_nd_(find_nearest_cb)(
const KDTree *tree,
const float co[KD_DIMS],
int (*filter_cb)(void *user_data, int index, const float co[KD_DIMS], float dist_sq),
void *user_data,
KDTreeNearest *r_nearest);
void BLI_kdtree_nd_(range_search_cb)(
const KDTree *tree,
const float co[KD_DIMS],
float range,
bool (*search_cb)(void *user_data, int index, const float co[KD_DIMS], float dist_sq),
void *user_data);
int BLI_kdtree_nd_(calc_duplicates_fast)(const KDTree *tree,
const float range,
bool use_index_order,
int *doubles);
int BLI_kdtree_nd_(deduplicate)(KDTree *tree);
/* Versions of find/range search that take a squared distance callback to support bias. */
int BLI_kdtree_nd_(find_nearest_n_with_len_squared_cb)(
const KDTree *tree,
const float co[KD_DIMS],
KDTreeNearest *r_nearest,
const uint nearest_len_capacity,
float (*len_sq_fn)(const float co_search[KD_DIMS],
const float co_test[KD_DIMS],
const void *user_data),
const void *user_data) ATTR_NONNULL(1, 2, 3);
int BLI_kdtree_nd_(range_search_with_len_squared_cb)(
const KDTree *tree,
const float co[KD_DIMS],
KDTreeNearest **r_nearest,
const float range,
float (*len_sq_fn)(const float co_search[KD_DIMS],
const float co_test[KD_DIMS],
const void *user_data),
const void *user_data) ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT;
#undef _BLI_CONCAT_AUX
#undef _BLI_CONCAT
#undef BLI_kdtree_nd_