123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- /*
- ISC License
- Copyright (c) 2023-2024, Bruce A Henderson
- Permission to use, copy, modify, and/or distribute this software for any purpose
- with or without fee is hereby granted, provided that the above copyright notice
- and this permission notice appear in all copies.
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
- THIS SOFTWARE.
- */
- #include "mapbox/earcut.hpp"
- #include "clipper2/CPP/Clipper2Lib/include/clipper2/clipper.h"
- extern "C" {
- #include "brl.mod/blitz.mod/blitz.h"
- struct SVec2I {
- int x;
- int y;
- };
- struct SVec2F {
- float x;
- float y;
- };
- BBArray * bmx_polygon_tri_svec2i(struct SVec2I * p, int size);
- BBArray * bmx_polygon_tri_svec2f(struct SVec2F * p, int size);
- }
- namespace mapbox {
- namespace util {
- template <>
- struct nth<0, struct SVec2I> {
- inline static int get(const struct SVec2I &v) {
- return v.x;
- };
- };
- template <>
- struct nth<1, struct SVec2I> {
- inline static int get(const struct SVec2I &v) {
- return v.y;
- };
- };
- template <>
- struct nth<0, struct SVec2F> {
- inline static float get(const struct SVec2F &v) {
- return v.x;
- };
- };
- template <>
- struct nth<1, struct SVec2F> {
- inline static float get(const struct SVec2F &v) {
- return v.y;
- };
- };
- } // namespace util
- } // namespace mapbox
- BBArray * bmx_polygon_tri_svec2i(struct SVec2I * p, int size) {
- std::vector<struct SVec2I> points(p, p + size);
- std::vector<std::vector<struct SVec2I>> polygon;
- polygon.push_back(points);
- std::vector<int> indices = mapbox::earcut<int>(polygon);
- BBArray *arr = bbArrayNew1DNoInit("i", indices.size());
- int *s = (int*)BBARRAYDATA(arr,arr->dims);
- std::copy(indices.begin(), indices.end(), s);
- return arr;
- }
- BBArray * bmx_polygon_tri_svec2f(struct SVec2F * p, int size) {
- std::vector<struct SVec2F> points(p, p + size);
- std::vector<std::vector<struct SVec2F>> polygon;
- polygon.push_back(points);
- std::vector<int> indices = mapbox::earcut<int>(polygon);
- BBArray *arr = bbArrayNew1DNoInit("f", indices.size());
- int *s = (int*)BBARRAYDATA(arr,arr->dims);
- std::copy(indices.begin(), indices.end(), s);
- return arr;
- }
- using PathI = Clipper2Lib::Path<int>;
- using PathF = Clipper2Lib::Path<float>;
- using PathsI = std::vector<PathI>;
- using PathsF = std::vector<PathF>;
|