Retakes on dllexport/dllimport

This commit is contained in:
Pierre Dejoue 2022-04-17 14:12:01 +02:00
parent ad184c3810
commit 7f5846b72d
3 changed files with 120 additions and 100 deletions

View File

@ -0,0 +1,56 @@
/*
* Poly2Tri Copyright (c) 2009-2022, Poly2Tri Contributors
* https://github.com/jhasse/poly2tri
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Poly2Tri nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef DLL_SYMBOL_H
#define DLL_SYMBOL_H
#if defined(_WIN32)
# define P2T_COMPILER_DLLEXPORT __declspec(dllexport)
# define P2T_COMPILER_DLLIMPORT __declspec(dllimport)
#elif defined(__GNUC__)
# define P2T_COMPILER_DLLEXPORT __attribute__ ((visibility ("default")))
# define P2T_COMPILER_DLLIMPORT __attribute__ ((visibility ("default")))
#else
# define P2T_COMPILER_DLLEXPORT
# define P2T_COMPILER_DLLIMPORT
#endif
#ifndef P2T_DLL_SYMBOL
# if defined(P2T_STATIC_EXPORTS)
# define P2T_DLL_SYMBOL
# elif defined(P2T_SHARED_EXPORTS)
# define P2T_DLL_SYMBOL P2T_COMPILER_DLLEXPORT
# else
# define P2T_DLL_SYMBOL P2T_COMPILER_DLLIMPORT
# endif
#endif
#endif

View File

@ -33,25 +33,7 @@
#ifndef SHAPES_H #ifndef SHAPES_H
#define SHAPES_H #define SHAPES_H
#if defined(_WIN32) #include "dll_symbol.h"
# define COMPILER_DLLEXPORT __declspec(dllexport)
# define COMPILER_DLLIMPORT __declspec(dllimport)
#else
# define COMPILER_DLLEXPORT __attribute__ ((visibility ("default")))
# define COMPILER_DLLIMPORT __attribute__ ((visibility ("default")))
#endif
#ifndef P2T_EXPORT
# if defined(P2T_DLL_EXPORTS) && defined(P2T_DLL_IMPORTS)
# error "Only P2T_DLL_EXPORTS or P2T_DLL_IMPORTS can be defined, not both."
# elif defined(P2T_DLL_EXPORTS)
# define P2T_EXPORT COMPILER_DLLEXPORT
# elif defined(P2T_DLL_IMPORTS)
# define P2T_EXPORT COMPILER_DLLIMPORT
# else
# define P2T_EXPORT
# endif
#endif
#include <cmath> #include <cmath>
#include <cstddef> #include <cstddef>
@ -62,12 +44,12 @@ namespace p2t {
struct Edge; struct Edge;
struct Point { struct P2T_DLL_SYMBOL Point {
double x, y; double x, y;
/// Default constructor does nothing (for performance). /// Default constructor does nothing (for performance).
P2T_EXPORT Point() Point()
{ {
x = 0.0; x = 0.0;
y = 0.0; y = 0.0;
@ -80,21 +62,21 @@ struct Point {
Point(double x, double y); Point(double x, double y);
/// Set this point to all zeros. /// Set this point to all zeros.
P2T_EXPORT void set_zero() void set_zero()
{ {
x = 0.0; x = 0.0;
y = 0.0; y = 0.0;
} }
/// Set this point to some specified coordinates. /// Set this point to some specified coordinates.
P2T_EXPORT void set(double x_, double y_) void set(double x_, double y_)
{ {
x = x_; x = x_;
y = y_; y = y_;
} }
/// Negate this point. /// Negate this point.
P2T_EXPORT Point operator -() const Point operator -() const
{ {
Point v; Point v;
v.set(-x, -y); v.set(-x, -y);
@ -102,34 +84,34 @@ struct Point {
} }
/// Add a point to this point. /// Add a point to this point.
P2T_EXPORT void operator +=(const Point& v) void operator +=(const Point& v)
{ {
x += v.x; x += v.x;
y += v.y; y += v.y;
} }
/// Subtract a point from this point. /// Subtract a point from this point.
P2T_EXPORT void operator -=(const Point& v) void operator -=(const Point& v)
{ {
x -= v.x; x -= v.x;
y -= v.y; y -= v.y;
} }
/// Multiply this point by a scalar. /// Multiply this point by a scalar.
P2T_EXPORT void operator *=(double a) void operator *=(double a)
{ {
x *= a; x *= a;
y *= a; y *= a;
} }
/// Get the length of this point (the norm). /// Get the length of this point (the norm).
P2T_EXPORT double Length() const double Length() const
{ {
return sqrt(x * x + y * y); return sqrt(x * x + y * y);
} }
/// Convert this point into a unit point. Returns the Length. /// Convert this point into a unit point. Returns the Length.
P2T_EXPORT double Normalize() double Normalize()
{ {
const double len = Length(); const double len = Length();
x /= len; x /= len;
@ -139,15 +121,15 @@ struct Point {
}; };
std::ostream& operator<<(std::ostream&, const Point&); P2T_DLL_SYMBOL std::ostream& operator<<(std::ostream&, const Point&);
// Represents a simple polygon's edge // Represents a simple polygon's edge
struct Edge { struct P2T_DLL_SYMBOL Edge {
Point* p, *q; Point* p, *q;
/// Constructor /// Constructor
P2T_EXPORT Edge(Point& p1, Point& p2) : p(&p1), q(&p2) Edge(Point& p1, Point& p2) : p(&p1), q(&p2)
{ {
if (p1.y > p2.y) { if (p1.y > p2.y) {
q = &p1; q = &p1;
@ -169,68 +151,68 @@ struct Edge {
// Triangle-based data structures are know to have better performance than quad-edge structures // Triangle-based data structures are know to have better performance than quad-edge structures
// See: J. Shewchuk, "Triangle: Engineering a 2D Quality Mesh Generator and Delaunay Triangulator" // See: J. Shewchuk, "Triangle: Engineering a 2D Quality Mesh Generator and Delaunay Triangulator"
// "Triangulations in CGAL" // "Triangulations in CGAL"
class Triangle { class P2T_DLL_SYMBOL Triangle {
public: public:
/// Constructor /// Constructor
P2T_EXPORT Triangle(Point& a, Point& b, Point& c); Triangle(Point& a, Point& b, Point& c);
/// Flags to determine if an edge is a Constrained edge /// Flags to determine if an edge is a Constrained edge
bool constrained_edge[3]; bool constrained_edge[3];
/// Flags to determine if an edge is a Delauney edge /// Flags to determine if an edge is a Delauney edge
bool delaunay_edge[3]; bool delaunay_edge[3];
P2T_EXPORT Point* GetPoint(int index); Point* GetPoint(int index);
P2T_EXPORT Point* PointCW(const Point& point); Point* PointCW(const Point& point);
P2T_EXPORT Point* PointCCW(const Point& point); Point* PointCCW(const Point& point);
P2T_EXPORT Point* OppositePoint(Triangle& t, const Point& p); Point* OppositePoint(Triangle& t, const Point& p);
P2T_EXPORT Triangle* GetNeighbor(int index); Triangle* GetNeighbor(int index);
P2T_EXPORT void MarkNeighbor(Point* p1, Point* p2, Triangle* t); void MarkNeighbor(Point* p1, Point* p2, Triangle* t);
P2T_EXPORT void MarkNeighbor(Triangle& t); void MarkNeighbor(Triangle& t);
P2T_EXPORT void MarkConstrainedEdge(int index); void MarkConstrainedEdge(int index);
P2T_EXPORT void MarkConstrainedEdge(Edge& edge); void MarkConstrainedEdge(Edge& edge);
P2T_EXPORT void MarkConstrainedEdge(Point* p, Point* q); void MarkConstrainedEdge(Point* p, Point* q);
P2T_EXPORT int Index(const Point* p); int Index(const Point* p);
P2T_EXPORT int EdgeIndex(const Point* p1, const Point* p2); int EdgeIndex(const Point* p1, const Point* p2);
P2T_EXPORT Triangle* NeighborAcross(const Point& point); Triangle* NeighborAcross(const Point& point);
P2T_EXPORT Triangle* NeighborCW(const Point& point); Triangle* NeighborCW(const Point& point);
P2T_EXPORT Triangle* NeighborCCW(const Point& point); Triangle* NeighborCCW(const Point& point);
P2T_EXPORT bool GetConstrainedEdgeCCW(const Point& p); bool GetConstrainedEdgeCCW(const Point& p);
P2T_EXPORT bool GetConstrainedEdgeCW(const Point& p); bool GetConstrainedEdgeCW(const Point& p);
P2T_EXPORT void SetConstrainedEdgeCCW(const Point& p, bool ce); void SetConstrainedEdgeCCW(const Point& p, bool ce);
P2T_EXPORT void SetConstrainedEdgeCW(const Point& p, bool ce); void SetConstrainedEdgeCW(const Point& p, bool ce);
P2T_EXPORT bool GetDelunayEdgeCCW(const Point& p); bool GetDelunayEdgeCCW(const Point& p);
P2T_EXPORT bool GetDelunayEdgeCW(const Point& p); bool GetDelunayEdgeCW(const Point& p);
P2T_EXPORT void SetDelunayEdgeCCW(const Point& p, bool e); void SetDelunayEdgeCCW(const Point& p, bool e);
P2T_EXPORT void SetDelunayEdgeCW(const Point& p, bool e); void SetDelunayEdgeCW(const Point& p, bool e);
P2T_EXPORT bool Contains(const Point* p); bool Contains(const Point* p);
P2T_EXPORT bool Contains(const Edge& e); bool Contains(const Edge& e);
P2T_EXPORT bool Contains(const Point* p, const Point* q); bool Contains(const Point* p, const Point* q);
P2T_EXPORT void Legalize(Point& point); void Legalize(Point& point);
P2T_EXPORT void Legalize(Point& opoint, Point& npoint); void Legalize(Point& opoint, Point& npoint);
/** /**
* Clears all references to all other triangles and points * Clears all references to all other triangles and points
*/ */
P2T_EXPORT void Clear(); void Clear();
P2T_EXPORT void ClearNeighbor(const Triangle *triangle); void ClearNeighbor(const Triangle *triangle);
P2T_EXPORT void ClearNeighbors(); void ClearNeighbors();
P2T_EXPORT void ClearDelunayEdges(); void ClearDelunayEdges();
P2T_EXPORT inline bool IsInterior(); inline bool IsInterior();
P2T_EXPORT inline void IsInterior(bool b); inline void IsInterior(bool b);
P2T_EXPORT void DebugPrint(); void DebugPrint();
P2T_EXPORT bool CircumcicleContains(const Point&) const; bool CircumcicleContains(const Point&) const;
private: private:
P2T_EXPORT bool IsCounterClockwise() const; bool IsCounterClockwise() const;
/// Triangle points /// Triangle points
Point* points_[3]; Point* points_[3];
@ -344,7 +326,7 @@ inline void Triangle::IsInterior(bool b)
} }
/// Is this set a valid delaunay triangulation? /// Is this set a valid delaunay triangulation?
bool IsDelaunay(const std::vector<p2t::Triangle*>&); P2T_DLL_SYMBOL bool IsDelaunay(const std::vector<p2t::Triangle*>&);
} }

View File

@ -32,30 +32,12 @@
#ifndef CDT_H #ifndef CDT_H
#define CDT_H #define CDT_H
#if defined(_WIN32)
# define COMPILER_DLLEXPORT __declspec(dllexport)
# define COMPILER_DLLIMPORT __declspec(dllimport)
#else
# define COMPILER_DLLEXPORT __attribute__ ((visibility ("default")))
# define COMPILER_DLLIMPORT __attribute__ ((visibility ("default")))
#endif
#ifndef P2T_EXPORT
# if defined(P2T_DLL_EXPORTS) && defined(P2T_DLL_IMPORTS)
# error "Only P2T_DLL_EXPORTS or P2T_DLL_IMPORTS can be defined, not both."
# elif defined(P2T_DLL_EXPORTS)
# define P2T_EXPORT COMPILER_DLLEXPORT
# elif defined(P2T_DLL_IMPORTS)
# define P2T_EXPORT COMPILER_DLLIMPORT
# else
# define P2T_EXPORT
# endif
#endif
#include "advancing_front.h" #include "advancing_front.h"
#include "sweep_context.h" #include "sweep_context.h"
#include "sweep.h" #include "sweep.h"
#include "../common/dll_symbol.h"
/** /**
* *
* @author Mason Green <mason.green@gmail.com> * @author Mason Green <mason.green@gmail.com>
@ -64,7 +46,7 @@
namespace p2t { namespace p2t {
class CDT class P2T_DLL_SYMBOL CDT
{ {
public: public:
@ -73,41 +55,41 @@ public:
* *
* @param polyline * @param polyline
*/ */
P2T_EXPORT CDT(const std::vector<Point*>& polyline); CDT(const std::vector<Point*>& polyline);
/** /**
* Destructor - clean up memory * Destructor - clean up memory
*/ */
P2T_EXPORT ~CDT(); ~CDT();
/** /**
* Add a hole * Add a hole
* *
* @param polyline * @param polyline
*/ */
P2T_EXPORT void AddHole(const std::vector<Point*>& polyline); void AddHole(const std::vector<Point*>& polyline);
/** /**
* Add a steiner point * Add a steiner point
* *
* @param point * @param point
*/ */
P2T_EXPORT void AddPoint(Point* point); void AddPoint(Point* point);
/** /**
* Triangulate - do this AFTER you've added the polyline, holes, and Steiner points * Triangulate - do this AFTER you've added the polyline, holes, and Steiner points
*/ */
P2T_EXPORT void Triangulate(); void Triangulate();
/** /**
* Get CDT triangles * Get CDT triangles
*/ */
P2T_EXPORT std::vector<Triangle*> GetTriangles(); std::vector<Triangle*> GetTriangles();
/** /**
* Get triangle map * Get triangle map
*/ */
P2T_EXPORT std::list<Triangle*> GetMap(); std::list<Triangle*> GetMap();
private: private: