forked from arnholm/xcsg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
260 changed files
with
57,973 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.layout | ||
*.depend | ||
*.pdb | ||
*.exe | ||
.cmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> | ||
<CodeBlocks_workspace_file> | ||
<Workspace title="XCSG"> | ||
<Project filename="qhull/qhull.cbp" /> | ||
<Project filename="dmesh/dmesh.cbp" /> | ||
<Project filename="xcsg/xcsg.cbp"> | ||
<Depends filename="qhull/qhull.cbp" /> | ||
<Depends filename="dmesh/dmesh.cbp" /> | ||
</Project> | ||
</Workspace> | ||
</CodeBlocks_workspace_file> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// BeginLicense: | ||
// Part of: dmesh - Delaunay mesh library | ||
// Copyright (C) 2017 Carsten Arnholm | ||
// All rights reserved | ||
// | ||
// This file may be used under the terms of either the GNU General | ||
// Public License version 2 or 3 (at your option) as published by the | ||
// Free Software Foundation and appearing in the files LICENSE.GPL2 | ||
// and LICENSE.GPL3 included in the packaging of this file. | ||
// | ||
// This file is provided "AS IS" with NO WARRANTY OF ANY KIND, | ||
// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE. ALL COPIES OF THIS FILE MUST INCLUDE THIS LICENSE. | ||
// EndLicense: | ||
|
||
// dbox2d.cpp: implementation of the dbox2d class. | ||
// | ||
////////////////////////////////////////////////////////////////////// | ||
|
||
#include "dbox2d.h" | ||
#include <algorithm> | ||
using namespace std; | ||
|
||
dbox2d::dbox2d(bool initialised) | ||
: m_p1(0,0),m_p2(0,0),m_initialised(initialised) | ||
{} | ||
|
||
dbox2d::dbox2d(const dpos2d& pos1, const dpos2d& pos2) | ||
:m_initialised(true) | ||
{ | ||
setBox(pos1,pos2); | ||
} | ||
|
||
dbox2d::~dbox2d() | ||
{ | ||
} | ||
|
||
dbox2d& dbox2d::operator =(const dbox2d& box) | ||
{ | ||
if(this!=&box) { | ||
m_p1 = box.m_p1; | ||
m_p2 = box.m_p2; | ||
m_initialised = box.m_initialised; | ||
} | ||
return *this; | ||
} | ||
|
||
|
||
void dbox2d::setBox(const dpos2d& pos1, const dpos2d& pos2) | ||
{ | ||
if (!m_initialised) { | ||
m_p1 = pos1; | ||
m_p2 = m_p1; | ||
m_initialised = true; | ||
} | ||
|
||
double lminx = min(pos1.x(),pos2.x()); | ||
double lmaxx = max(pos1.x(),pos2.x()); | ||
double lminy = min(pos1.y(),pos2.y()); | ||
double lmaxy = max(pos1.y(),pos2.y()); | ||
|
||
m_p1 = dpos2d(lminx,lminy); | ||
m_p2 = dpos2d(lmaxx,lmaxy); | ||
} | ||
|
||
void dbox2d::enclose(const dpos2d& pos1,double tolerance) | ||
{ | ||
if (!m_initialised) { | ||
m_p1 = pos1; | ||
m_p2 = m_p1; | ||
m_initialised = true; | ||
} | ||
// recalculate boundaries | ||
double lminx = min(m_p1.x(),pos1.x()-tolerance); | ||
double lmaxx = max(m_p2.x(),pos1.x()+tolerance); | ||
double lminy = min(m_p1.y(),pos1.y()-tolerance); | ||
double lmaxy = max(m_p2.y(),pos1.y()+tolerance); | ||
|
||
// reset points | ||
m_p1 = dpos2d(lminx,lminy); | ||
m_p2 = dpos2d(lmaxx,lmaxy); | ||
} | ||
|
||
|
||
|
||
const dpos2d& dbox2d::p1() const | ||
{ | ||
return m_p1; | ||
} | ||
|
||
const dpos2d& dbox2d::p2() const | ||
{ | ||
return m_p2; | ||
} | ||
|
||
bool dbox2d::initialised() const | ||
{ | ||
return m_initialised; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// BeginLicense: | ||
// Part of: dmesh - Delaunay mesh library | ||
// Copyright (C) 2017 Carsten Arnholm | ||
// All rights reserved | ||
// | ||
// This file may be used under the terms of either the GNU General | ||
// Public License version 2 or 3 (at your option) as published by the | ||
// Free Software Foundation and appearing in the files LICENSE.GPL2 | ||
// and LICENSE.GPL3 included in the packaging of this file. | ||
// | ||
// This file is provided "AS IS" with NO WARRANTY OF ANY KIND, | ||
// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE. ALL COPIES OF THIS FILE MUST INCLUDE THIS LICENSE. | ||
// EndLicense: | ||
|
||
#ifndef DBOX2D_H | ||
#define DBOX2D_H | ||
|
||
#include "dpos2d.h" | ||
|
||
// a dbox2d is a utility for computing a 2d bounding box | ||
|
||
class dbox2d { | ||
public: | ||
dbox2d(bool initialised = false); | ||
dbox2d(const dpos2d& pos1, const dpos2d& pos2); | ||
virtual ~dbox2d(); | ||
|
||
bool initialised() const; | ||
|
||
dbox2d& operator =(const dbox2d& box); | ||
|
||
void enclose(const dpos2d& pos1, double tolerance=0.0); | ||
|
||
const dpos2d& p1() const; | ||
const dpos2d& p2() const; | ||
|
||
private: | ||
void setBox(const dpos2d& pos1, const dpos2d& pos2); | ||
|
||
private: | ||
dpos2d m_p1; | ||
dpos2d m_p2; | ||
bool m_initialised; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// BeginLicense: | ||
// Part of: dmesh - Delaunay mesh library | ||
// Copyright (C) 2017 Carsten Arnholm | ||
// All rights reserved | ||
// | ||
// This file may be used under the terms of either the GNU General | ||
// Public License version 2 or 3 (at your option) as published by the | ||
// Free Software Foundation and appearing in the files LICENSE.GPL2 | ||
// and LICENSE.GPL3 included in the packaging of this file. | ||
// | ||
// This file is provided "AS IS" with NO WARRANTY OF ANY KIND, | ||
// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE. ALL COPIES OF THIS FILE MUST INCLUDE THIS LICENSE. | ||
// EndLicense: | ||
|
||
#include "dcircle.h" | ||
#include "dvec2d.h" | ||
|
||
dcircle::dcircle(const dpos2d& center, double radius) | ||
: m_center(center) | ||
, m_radius(radius) | ||
{} | ||
|
||
|
||
dcircle::dcircle(const dpos2d& p1, const dpos2d& p2,const dpos2d& p3) | ||
{ | ||
circum_circle(p1,p2,p3,m_center,m_radius); | ||
} | ||
|
||
dcircle::~dcircle() | ||
{ | ||
} | ||
|
||
void dcircle::circum_circle(const dpos2d& p1, const dpos2d& p2,const dpos2d& p3, dpos2d& center, double& radius) | ||
{ | ||
// https://en.wikipedia.org/wiki/Circumscribed_circle#Cartesian_coordinates_from_cross-_and_dot-products | ||
|
||
dvec2d p1p2(p2,p1); | ||
dvec2d p2p3(p3,p2); | ||
dvec2d p3p1(p1,p3); | ||
|
||
dvec2d p1p3(p3,p1); | ||
dvec2d p2p1(p1,p2); | ||
dvec2d p3p2(p2,p3); | ||
|
||
double dp1p2 = p1p2.length(); | ||
double dp2p3 = p2p3.length(); | ||
double dp3p1 = p3p1.length(); | ||
double dp1p3 = dp3p1; | ||
|
||
radius = 0.5*(dp1p2*dp2p3*dp3p1)/p1p2.cross(p2p3); | ||
|
||
double cross = p1p2.cross(p2p3); | ||
double denom = 2.0* cross*cross; | ||
|
||
double alpha = dp2p3*dp2p3*p1p2.dot(p1p3)/denom; | ||
double beta = dp1p3*dp1p3*p2p1.dot(p2p3)/denom; | ||
double gamma = dp1p2*dp1p2*p3p1.dot(p3p2)/denom; | ||
|
||
double x = alpha*p1.x() + beta*p2.x() + gamma*p3.x(); | ||
double y = alpha*p1.y() + beta*p2.y() + gamma*p3.y(); | ||
|
||
center = dpos2d(x,y); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// BeginLicense: | ||
// Part of: dmesh - Delaunay mesh library | ||
// Copyright (C) 2017 Carsten Arnholm | ||
// All rights reserved | ||
// | ||
// This file may be used under the terms of either the GNU General | ||
// Public License version 2 or 3 (at your option) as published by the | ||
// Free Software Foundation and appearing in the files LICENSE.GPL2 | ||
// and LICENSE.GPL3 included in the packaging of this file. | ||
// | ||
// This file is provided "AS IS" with NO WARRANTY OF ANY KIND, | ||
// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE. ALL COPIES OF THIS FILE MUST INCLUDE THIS LICENSE. | ||
// EndLicense: | ||
|
||
#ifndef DCIRCLE_H | ||
#define DCIRCLE_H | ||
|
||
#include "dpos2d.h" | ||
|
||
// a dcircle is mainly used for representing the circumcircle of a triangle in Delaunay meshing | ||
|
||
class dcircle { | ||
public: | ||
|
||
// construct from centre and radius | ||
dcircle(const dpos2d& center, double radius); | ||
|
||
// construct circumcircle from triangle points | ||
dcircle(const dpos2d& p1, const dpos2d& p2,const dpos2d& p3); | ||
|
||
virtual ~dcircle(); | ||
|
||
// compute the circumcircle centre and radius from the 3 points | ||
static void circum_circle(const dpos2d& p1, const dpos2d& p2,const dpos2d& p3, dpos2d& center, double& radius); | ||
|
||
// return center and radius of circle | ||
const dpos2d& center() const { return m_center; } | ||
double radius() const { return m_radius; } | ||
|
||
// check if position is inside circle | ||
bool pos_inside(const dpos2d& p) { return (m_center.dist(p) <= m_radius); } | ||
|
||
private: | ||
dpos2d m_center; | ||
double m_radius; | ||
}; | ||
|
||
#endif // DCIRCLE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// BeginLicense: | ||
// Part of: dmesh - Delaunay mesh library | ||
// Copyright (C) 2017 Carsten Arnholm | ||
// All rights reserved | ||
// | ||
// This file may be used under the terms of either the GNU General | ||
// Public License version 2 or 3 (at your option) as published by the | ||
// Free Software Foundation and appearing in the files LICENSE.GPL2 | ||
// and LICENSE.GPL3 included in the packaging of this file. | ||
// | ||
// This file is provided "AS IS" with NO WARRANTY OF ANY KIND, | ||
// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE. ALL COPIES OF THIS FILE MUST INCLUDE THIS LICENSE. | ||
// EndLicense: | ||
|
||
#include "dcoedge.h" | ||
#include "dedge.h" | ||
|
||
dcoedge::dcoedge(dentity* parent, dedge* edge, bool fwd) | ||
: m_parent(parent) | ||
, m_edge(edge) | ||
, m_fwd(fwd) | ||
{ | ||
m_edge->addref(this); | ||
} | ||
|
||
dcoedge::~dcoedge() | ||
{ | ||
m_edge->release(this); | ||
} | ||
|
||
dcoedge* dcoedge::clone(dentity* parent) | ||
{ | ||
return new dcoedge(parent,m_edge,m_fwd); | ||
} | ||
|
||
|
||
size_t dcoedge::vertex1() const | ||
{ | ||
return (m_fwd)? m_edge->vertex1() : m_edge->vertex2(); | ||
} | ||
|
||
size_t dcoedge::vertex2() const | ||
{ | ||
return (m_fwd)? m_edge->vertex2() : m_edge->vertex1(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// BeginLicense: | ||
// Part of: dmesh - Delaunay mesh library | ||
// Copyright (C) 2017 Carsten Arnholm | ||
// All rights reserved | ||
// | ||
// This file may be used under the terms of either the GNU General | ||
// Public License version 2 or 3 (at your option) as published by the | ||
// Free Software Foundation and appearing in the files LICENSE.GPL2 | ||
// and LICENSE.GPL3 included in the packaging of this file. | ||
// | ||
// This file is provided "AS IS" with NO WARRANTY OF ANY KIND, | ||
// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE. ALL COPIES OF THIS FILE MUST INCLUDE THIS LICENSE. | ||
// EndLicense: | ||
|
||
#ifndef DCOEDGE_H | ||
#define DCOEDGE_H | ||
|
||
#include <cstddef> | ||
|
||
class dentity; | ||
class dedge; | ||
class dtriangle; | ||
|
||
// Topology | ||
// ======== | ||
// A dcoedge refers to a dedge. It carries a flag indicating the direction of the coedge relative to the dedge. | ||
// a dcoedge is uniquely owned by its parent. | ||
|
||
class dcoedge { | ||
public: | ||
friend class dtriangle; | ||
friend class dloop; | ||
friend class dprofile; | ||
|
||
// return the parent object | ||
const dentity* parent() const { return m_parent; } | ||
dentity* parent() { return m_parent; } | ||
|
||
// return the dcoedge oriented vertex1 | ||
size_t vertex1() const; | ||
|
||
// return the dcoedge oriented vertex2 | ||
size_t vertex2() const; | ||
|
||
// return the forward flag | ||
bool fwd() const { return m_fwd; } | ||
|
||
// reverse orientation of coedge | ||
void reverse() { m_fwd = !m_fwd; } | ||
|
||
// return underlying edge | ||
dedge* edge() { return m_edge; } | ||
const dedge* edge() const { return m_edge; } | ||
|
||
// return a clone of this coedge, but with specified parent | ||
dcoedge* clone(dentity* parent); | ||
|
||
protected: | ||
dcoedge(dentity* parent, dedge* edge, bool fwd); | ||
virtual ~dcoedge(); | ||
|
||
private: | ||
dentity* m_parent; // parent can be dtriangle or dloop | ||
dedge* m_edge; // the edge referred to from this coedge | ||
bool m_fwd; // true when dcoedge has same dir as dedge | ||
}; | ||
|
||
#endif // DCOEDGE_H |
Oops, something went wrong.