Path: PR6497 move return statement to new line

This commit is contained in:
Chris Hennes
2022-03-29 12:37:49 -05:00
parent 6f230d7404
commit 5f31fb74f6
18 changed files with 411 additions and 204 deletions

View File

@@ -265,8 +265,10 @@ static bool getShapePlane(const TopoDS_Shape &shape, gp_Pln &pln) {
}
bool Area::isCoplanar(const TopoDS_Shape &s1, const TopoDS_Shape &s2) {
if(s1.IsNull() || s2.IsNull()) return false;
if(s1.IsSame(s2)) return true;
if(s1.IsNull() || s2.IsNull())
return false;
if(s1.IsSame(s2))
return true;
gp_Pln pln1,pln2;
if(!getShapePlane(s1,pln1) || !getShapePlane(s2,pln2))
return false;
@@ -290,7 +292,8 @@ int Area::addShape(CArea &area, const TopoDS_Shape &shape, const gp_Trsf *trsf,
addWire(area,TopoDS::Wire(it.Current()),trsf,deflection);
}
if(haveShape) return skipped;
if(haveShape)
return skipped;
CArea _area;
CArea _areaOpen;
@@ -1052,7 +1055,8 @@ void Area::explode(const TopoDS_Shape &shape) {
TopoDS::Edge(xp.Current())).Wire(),&myTrsf,myParams.Deflection,true);
}
}
if(haveShape) return;
if(haveShape)
return;
for(TopExp_Explorer it(shape, TopAbs_EDGE); it.More(); it.Next()) {
if(myParams.Coplanar!=CoplanarNone && !isCoplanar(it.Current(),plane)){
++mySkippedShapes;
@@ -1616,7 +1620,8 @@ std::list<Area::Shape> Area::getProjectedShapes(const gp_Trsf &trsf, bool invers
}
void Area::build() {
if(isBuilt()) return;
if(isBuilt())
return;
if(myShapes.empty())
throw Base::ValueError("no shape added");
@@ -1773,9 +1778,11 @@ TopoDS_Shape Area::getShape(int index) {
build();
AREA_SECTION(getShape,index);
if(myShapeDone) return myShape;
if(myShapeDone)
return myShape;
if(!myArea) return TopoDS_Shape();
if(!myArea)
return TopoDS_Shape();
CAreaConfig conf(myParams);
@@ -2270,7 +2277,8 @@ TopoDS_Shape Area::toShape(const CArea &area, bool fill, const gp_Trsf *trsf, in
builder.Add(compound,wire);
}
TopExp_Explorer xp(compound,TopAbs_EDGE);
if(!xp.More()) return TopoDS_Shape();
if(!xp.More())
return TopoDS_Shape();
if(fill) {
try{
FC_TIME_INIT(t);
@@ -2750,7 +2758,8 @@ struct ShapeInfoBuilder {
if(type == TopAbs_EDGE) {
BRepAdaptor_Curve curve(TopoDS::Edge(shape));
if(curve.GetType()!=GeomAbs_Circle) return;
if(curve.GetType()!=GeomAbs_Circle)
return;
}else{
bool found = false;
for(TopExp_Explorer it(shape,TopAbs_EDGE);it.More();it.Next()) {
@@ -2760,7 +2769,8 @@ struct ShapeInfoBuilder {
break;
}
}
if(!found) return;
if(!found)
return;
}
gp_Ax3 pos = myList.back().myPln.Position();
if(!pos.Direct()) pos = gp_Ax3(pos.Ax2());
@@ -2788,15 +2798,21 @@ struct ShapeInfoBuilder {
myArcPlaneFound = true;
return;
}case Area::ArcPlaneXY:
if(x0&&y0) {myArcPlaneFound=true;return;}
if(x0&&y0) {myArcPlaneFound=true;
return;
}
dstPos = gp_Ax3(pos.Location(),gp_Dir(0,0,1));
break;
case Area::ArcPlaneZX:
if(x0&&z0) {myArcPlaneFound=true;return;}
if(x0&&z0) {myArcPlaneFound=true;
return;
}
dstPos = gp_Ax3(pos.Location(),gp_Dir(0,1,0));
break;
case Area::ArcPlaneYZ:
if(z0&&y0) {myArcPlaneFound=true;return;}
if(z0&&y0) {myArcPlaneFound=true;
return;
}
dstPos = gp_Ax3(pos.Location(),gp_Dir(1,0,0));
break;
default:
@@ -2873,7 +2889,8 @@ std::list<TopoDS_Shape> Area::sortWires(const std::list<TopoDS_Shape> &shapes,
{
std::list<TopoDS_Shape> wires;
if(shapes.empty()) return wires;
if(shapes.empty())
return wires;
AxisGetter getter;
AxisSetter setter;

View File

@@ -174,7 +174,8 @@ FeatureAreaView::FeatureAreaView()
std::list<TopoDS_Shape> FeatureAreaView::getShapes() {
std::list<TopoDS_Shape> shapes;
App::DocumentObject* pObj = Source.getValue();
if (!pObj) return shapes;
if (!pObj)
return shapes;
if(!pObj->isDerivedFrom(FeatureArea::getClassTypeId()))
return shapes;
@@ -186,7 +187,8 @@ std::list<TopoDS_Shape> FeatureAreaView::getShapes() {
int index=SectionIndex.getValue(),count=SectionCount.getValue();
if(index<0) {
index += ((int)all_shapes.size());
if(index<0) return shapes;
if(index<0)
return shapes;
if(count<=0 || index+1-count<0) {
count = index+1;
index = 0;

View File

@@ -338,7 +338,8 @@ SoDetail* ViewProviderPath::getDetail(const char* subelement) const
void ViewProviderPath::onChanged(const App::Property* prop)
{
if(blockPropertyChange) return;
if(blockPropertyChange)
return;
if (prop == &LineWidth) {
pcDrawStyle->lineWidth = LineWidth.getValue();
@@ -648,7 +649,8 @@ void ViewProviderPath::updateVisual(bool rebuild) {
for(i=StartIndex.getValue();i<(int)command2Edge.size();++i)
if((edgeStart=command2Edge[i])>=0) break;
if(edgeStart<0) return;
if(edgeStart<0)
return;
if(i!=StartIndex.getValue() && StartIndex.getValue()!=0) {
blockPropertyChange = true;

View File

@@ -53,8 +53,10 @@ bool CArc::AlmostALine()const
Point CArc::MidParam(double param)const {
/// returns a point which is 0-1 along arc
if(fabs(param) < 0.00000000000001)return m_s;
if(fabs(param - 1.0) < 0.00000000000001)return m_e;
if(fabs(param) < 0.00000000000001)
return m_s;
if(fabs(param - 1.0) < 0.00000000000001)
return m_e;
Point p;
Point v = m_s - m_c;

View File

@@ -88,7 +88,8 @@ void CArea::ChangeStartToNearest(const Point *point, double min_dist)
m_curves.erase(It);
}
if(m_curves.empty()) return;
if(m_curves.empty())
return;
std::list<CCurve> curves;
Point p;
@@ -521,7 +522,8 @@ static void zigzag(const CArea &input_a)
Point null_point(0, 0);
rightward_for_zigs = true;
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
double step_percent_increment = 0.8 * CArea::m_single_area_processing_length / num_steps;
@@ -544,7 +546,8 @@ static void zigzag(const CArea &input_a)
a2.Intersect(a);
make_zig(a2, y0, y);
rightward_for_zigs = !rightward_for_zigs;
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
CArea::m_processing_done += step_percent_increment;
}
@@ -566,7 +569,8 @@ void CArea::SplitAndMakePocketToolpath(std::list<CCurve> &curve_list, const CAre
CArea::m_processing_done = m_split_processing_length;
CArea::m_units = save_units;
if(areas.size() == 0)return;
if(areas.size() == 0)
return;
double single_area_length = 50.0 / areas.size();
@@ -601,7 +605,8 @@ void CArea::MakePocketToolpath(std::list<CCurve> &curve_list, const CAreaPocketP
{
std::list<CArea> m_areas;
a_offset.Split(m_areas);
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
if(m_areas.size() == 0)
{
CArea::m_processing_done += CArea::m_single_area_processing_length;
@@ -644,7 +649,8 @@ void CArea::Split(std::list<CArea> &m_areas)const
CArea a = *this;
a.Reorder();
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
for(std::list<CCurve>::const_iterator It = a.m_curves.begin(); It != a.m_curves.end(); It++)
{
@@ -732,7 +738,8 @@ bool IsInside(const Point& p, const CArea& a)
c.m_vertices.emplace_back(Point(p.x - 0.01, p.y - 0.01));
a2.m_curves.push_back(c);
a2.Intersect(a);
if(fabs(a2.GetArea()) < 0.0004)return false;
if(fabs(a2.GetArea()) < 0.0004)
return false;
return true;
}

View File

@@ -303,7 +303,8 @@ static void MakePoly(const CCurve& curve, TPolygon &p, bool reverse = false)
pts_for_AddVertex.clear();
const CVertex* prev_vertex = NULL;
if(!curve.m_vertices.size()) return;
if(!curve.m_vertices.size())
return;
if(!curve.IsClosed()) AddVertex(curve.m_vertices.front(),NULL);
for (std::list<CVertex>::const_iterator It2 = curve.m_vertices.begin(); It2 != curve.m_vertices.end(); It2++)

View File

@@ -85,7 +85,8 @@ void GetCurveItem::GetCurve(CCurve& output)
// then add a line from the inner's point_on_parent to inner's start point, then GetCurve from inner
// add start point
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
output.m_vertices.insert(this->EndIt, CVertex(curve_tree->curve.m_vertices.front()));
std::list<CurveTree*> inners_to_visit;
@@ -118,10 +119,12 @@ void GetCurveItem::GetCurve(CCurve& output)
{
It2++;
}
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
}
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
for(std::multimap<double, CurveTree*>::iterator It2 = ordered_inners.begin(); It2 != ordered_inners.end(); It2++)
{
CurveTree& inner = *(It2->second);
@@ -129,7 +132,8 @@ void GetCurveItem::GetCurve(CCurve& output)
{
output.m_vertices.insert(this->EndIt, CVertex(vertex.m_type, inner.point_on_parent, vertex.m_c));
}
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
// vertex add after GetCurve
std::list<CVertex>::iterator VIt = output.m_vertices.insert(this->EndIt, CVertex(inner.point_on_parent));
@@ -143,7 +147,8 @@ void GetCurveItem::GetCurve(CCurve& output)
prev_vertex = &vertex;
}
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
for(std::list<CurveTree*>::iterator It2 = inners_to_visit.begin(); It2 != inners_to_visit.end(); It2++)
{
CurveTree &inner = *(*It2);
@@ -151,7 +156,8 @@ void GetCurveItem::GetCurve(CCurve& output)
{
output.m_vertices.insert(this->EndIt, CVertex(inner.point_on_parent));
}
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
// vertex add after GetCurve
std::list<CVertex>::iterator VIt = output.m_vertices.insert(this->EndIt, CVertex(inner.point_on_parent));
@@ -196,12 +202,14 @@ void CurveTree::MakeOffsets2()
{
// make offsets
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
CArea smaller;
smaller.m_curves.push_back(curve);
smaller.Offset(pocket_params->stepover);
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
// test islands
for(std::list<const IslandAndOffset*>::iterator It = offset_islands.begin(); It != offset_islands.end();)
@@ -215,11 +223,14 @@ void CurveTree::MakeOffsets2()
inners.push_back(new CurveTree(*island_and_offset->island));
islands_added.push_back(inners.back());
inners.back()->point_on_parent = curve.NearestPoint(*island_and_offset->island);
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
Point island_point = island_and_offset->island->NearestPoint(inners.back()->point_on_parent);
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
inners.back()->curve.ChangeStart(island_point);
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
// add the island offset's inner curves
for(std::list<CCurve>::const_iterator It2 = island_and_offset->island_inners.begin(); It2 != island_and_offset->island_inners.end(); It2++)
@@ -227,12 +238,15 @@ void CurveTree::MakeOffsets2()
const CCurve& island_inner = *It2;
inners.back()->inners.push_back(new CurveTree(island_inner));
inners.back()->inners.back()->point_on_parent = inners.back()->curve.NearestPoint(island_inner);
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
Point island_point = island_inner.NearestPoint(inners.back()->inners.back()->point_on_parent);
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
inners.back()->inners.back()->curve.ChangeStart(island_point);
to_do_list_for_MakeOffsets.push_back(inners.back()->inners.back()); // do it later, in a while loop
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
}
smaller.Subtract(island_and_offset->offset);
@@ -264,12 +278,15 @@ void CurveTree::MakeOffsets2()
const CCurve& island_inner = *It2;
touching.add_to->inners.back()->inners.push_back(new CurveTree(island_inner));
touching.add_to->inners.back()->inners.back()->point_on_parent = touching.add_to->inners.back()->curve.NearestPoint(island_inner);
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
Point island_point = island_inner.NearestPoint(touching.add_to->inners.back()->inners.back()->point_on_parent);
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
touching.add_to->inners.back()->inners.back()->curve.ChangeStart(island_point);
to_do_list_for_MakeOffsets.push_back(touching.add_to->inners.back()->inners.back()); // do it later, in a while loop
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
}
for(std::list<IslandAndOffset*>::const_iterator It2 = touching.island_and_offset->touching_offsets.begin(); It2 != touching.island_and_offset->touching_offsets.end(); It2++)
@@ -282,7 +299,8 @@ void CurveTree::MakeOffsets2()
}
}
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
It = offset_islands.erase(It);
for(std::set<const IslandAndOffset*>::iterator It2 = added.begin(); It2 != added.end(); It2++)
@@ -301,7 +319,8 @@ void CurveTree::MakeOffsets2()
std::list<CArea> separate_areas;
smaller.Split(separate_areas);
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
for(std::list<CArea>::iterator It = separate_areas.begin(); It != separate_areas.end(); It++)
{
CArea& separate_area = *It;
@@ -317,18 +336,23 @@ void CurveTree::MakeOffsets2()
const IslandAndOffset* island_and_offset = *It;
if(GetOverlapType(island_and_offset->offset, separate_area) == eInside)
nearest_curve_tree->inners.back()->offset_islands.push_back(island_and_offset);
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
}
nearest_curve_tree->inners.back()->point_on_parent = near_point;
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
Point first_curve_point = first_curve.NearestPoint(nearest_curve_tree->inners.back()->point_on_parent);
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
nearest_curve_tree->inners.back()->curve.ChangeStart(first_curve_point);
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
to_do_list_for_MakeOffsets.push_back(nearest_curve_tree->inners.back()); // do it later, in a while loop
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
}
}
@@ -423,7 +447,8 @@ void MarkOverlappingOffsetIslands(std::list<IslandAndOffset> &offset_islands)
void CArea::MakeOnePocketCurve(std::list<CCurve> &curve_list, const CAreaPocketParams &params)const
{
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
#if 0 // simple offsets with feed or rapid joins
CArea area_for_feed_possible = *this;
@@ -484,7 +509,8 @@ void CArea::MakeOnePocketCurve(std::list<CCurve> &curve_list, const CAreaPocketP
IslandAndOffset island_and_offset(&c);
offset_islands.push_back(island_and_offset);
top_level.offset_islands.push_back(&(offset_islands.back()));
if(m_please_abort)return;
if(m_please_abort)
return;
}
}
@@ -498,7 +524,8 @@ void CArea::MakeOnePocketCurve(std::list<CCurve> &curve_list, const CAreaPocketP
CArea::m_MakeOffsets_increment = MakeOffsets_processing_length / guess_num_offsets;
top_level.MakeOffsets();
if(CArea::m_please_abort)return;
if(CArea::m_please_abort)
return;
CArea::m_processing_done = CArea::m_after_MakeOffsets_length;
curve_list.emplace_back();

View File

@@ -93,11 +93,14 @@ bool Circle::LineIsOn(const Point& p0, const Point& p1, double accuracy)
{
// checks the points are on the arc, to the given accuracy, and the mid point of the line.
if(!PointIsOn(p0, accuracy))return false;
if(!PointIsOn(p1, accuracy))return false;
if(!PointIsOn(p0, accuracy))
return false;
if(!PointIsOn(p1, accuracy))
return false;
Point mid = Point((p0 + p1)/2);
if(!PointIsOn(mid, accuracy))return false;
if(!PointIsOn(mid, accuracy))
return false;
return true;
}

View File

@@ -65,7 +65,8 @@ bool CCurve::CheckForArc(const CVertex& prev_vt, std::list<const CVertex*>& migh
// this examines the vertices in might_be_an_arc
// if they do fit an arc, set arc to be the arc that they fit and return true
// returns true, if arc added
if(might_be_an_arc.size() < 2)return false;
if(might_be_an_arc.size() < 2)
return false;
// find middle point
std::size_t num = might_be_an_arc.size();
@@ -125,7 +126,8 @@ bool CCurve::CheckForArc(const CVertex& prev_vt, std::list<const CVertex*>& migh
if(angs < ange)angs += 6.2831853071795864;
}
if(arc.IncludedAngle() >= 3.15)return false; // We don't want full arcs, so limit to about 180 degrees
if(arc.IncludedAngle() >= 3.15) // We don't want full arcs, so limit to about 180 degrees
return false;
for(std::list<const CVertex*>::iterator It = might_be_an_arc.begin(); It != might_be_an_arc.end(); It++)
{
@@ -135,13 +137,15 @@ bool CCurve::CheckForArc(const CVertex& prev_vt, std::list<const CVertex*>& migh
{
// make sure angp > angs
if(angp < angs)angp += 6.2831853071795864;
if(angp > ange)return false;
if(angp > ange)
return false;
}
else
{
// make sure angp > ange
if(angp < ange)angp += 6.2831853071795864;
if(angp > angs)return false;
if(angp > angs)
return false;
}
}
@@ -489,7 +493,8 @@ double CCurve::GetArea()const
bool CCurve::IsClosed()const
{
if(m_vertices.size() == 0)return false;
if(m_vertices.size() == 0)
return false;
return m_vertices.front().m_p == m_vertices.back().m_p;
}
@@ -911,7 +916,8 @@ double CCurve::Perim()const
Point CCurve::PerimToPoint(double perim)const
{
if(m_vertices.size() == 0)return Point(0, 0);
if(m_vertices.size() == 0)
return Point(0, 0);
const Point *prev_p = NULL;
double kperim = 0.0;
@@ -1037,7 +1043,8 @@ Point Span::NearestPointNotOnSpan(const Point& p)const
{
double radius = m_p.dist(m_v.m_c);
double r = p.dist(m_v.m_c);
if(r < Point::tolerance)return m_p;
if(r < Point::tolerance)
return m_p;
Point vc = (m_v.m_c - p);
return p + vc * ((r - radius) / r);
}
@@ -1047,12 +1054,14 @@ Point Span::NearestPoint(const Point& p)const
{
Point np = NearestPointNotOnSpan(p);
double t = Parameter(np);
if(t >= 0.0 && t <= 1.0)return np;
if(t >= 0.0 && t <= 1.0)
return np;
double d1 = p.dist(this->m_p);
double d2 = p.dist(this->m_v.m_p);
if(d1 < d2)return this->m_p;
if(d1 < d2)
return this->m_p;
else return m_v.m_p;
}
@@ -1075,8 +1084,10 @@ Point Span::MidPerim(double d)const {
Point Span::MidParam(double param)const {
/// returns a point which is 0-1 along span
if(fabs(param) < 0.00000000000001)return m_p;
if(fabs(param - 1.0) < 0.00000000000001)return m_v.m_p;
if(fabs(param) < 0.00000000000001)
return m_p;
if(fabs(param - 1.0) < 0.00000000000001)
return m_v.m_p;
Point p;
if(m_v.m_type == 0) {
@@ -1189,7 +1200,8 @@ void Span::GetBox(CBox2D &box)
double IncludedAngle(const Point& v0, const Point& v1, int dir) {
// returns the absolute included angle between 2 vectors in the direction of dir ( 1=acw -1=cw)
double inc_ang = v0 * v1;
if(inc_ang > 1. - 1.0e-10) return 0;
if(inc_ang > 1. - 1.0e-10)
return 0;
if(inc_ang < -1. + 1.0e-10)
inc_ang = PI;
else { // dot product, v1 . v2 = cos ang
@@ -1264,7 +1276,8 @@ double Span::Parameter(const Point& p)const
bool Span::On(const Point& p, double* t)const
{
if(p != NearestPoint(p))return false;
if(p != NearestPoint(p))
return false;
if(t)*t = Parameter(p);
return true;
}

View File

@@ -204,7 +204,8 @@ boost::python::list getCurveSpans(const CCurve& c)
Span getFirstCurveSpan(const CCurve& c)
{
if(c.m_vertices.size() < 2)return Span();
if(c.m_vertices.size() < 2)
return Span();
std::list<CVertex>::const_iterator VIt = c.m_vertices.begin();
const Point &p = (*VIt).m_p;
@@ -214,7 +215,8 @@ Span getFirstCurveSpan(const CCurve& c)
Span getLastCurveSpan(const CCurve& c)
{
if(c.m_vertices.size() < 2)return Span();
if(c.m_vertices.size() < 2)
return Span();
std::list<CVertex>::const_reverse_iterator VIt = c.m_vertices.rbegin();
const CVertex &v = (*VIt);

View File

@@ -134,7 +134,8 @@ struct LocMinSorter
inline cInt Round(double val)
{
if ((val < 0)) return static_cast<cInt>(val - 0.5);
if ((val < 0))
return static_cast<cInt>(val - 0.5);
else return static_cast<cInt>(val + 0.5);
}
//------------------------------------------------------------------------------
@@ -337,7 +338,8 @@ class Int128
const double shift64 = 18446744073709551616.0; //2^64
if (hi < 0)
{
if (lo == 0) return (double)hi * shift64;
if (lo == 0)
return (double)hi * shift64;
else return -(double)(~lo + ~hi * shift64);
}
else
@@ -394,7 +396,8 @@ bool Orientation(const Path &poly)
double Area(const Path &poly)
{
int size = (int)poly.size();
if (size < 3) return 0;
if (size < 3)
return 0;
double a = 0;
for (int i = 0, j = size -1; i < size; ++i)
@@ -409,7 +412,8 @@ double Area(const Path &poly)
double Area(const OutRec &outRec)
{
OutPt *op = outRec.Pts;
if (!op) return 0;
if (!op)
return 0;
double a = 0;
do {
a += (double)(op->Prev->Pt.X + op->Pt.X) * (double)(op->Prev->Pt.Y - op->Pt.Y);
@@ -424,7 +428,8 @@ bool PointIsVertex(const IntPoint &Pt, OutPt *pp)
OutPt *pp2 = pp;
do
{
if (pp2->Pt == Pt) return true;
if (pp2->Pt == Pt)
return true;
pp2 = pp2->Next;
}
while (pp2 != pp);
@@ -439,7 +444,8 @@ int PointInPolygon (const IntPoint &pt, const Path &path)
//http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.88.5498&rep=rep1&type=pdf
int result = 0;
size_t cnt = path.size();
if (cnt < 3) return 0;
if (cnt < 3)
return 0;
IntPoint ip = path[0];
for(size_t i = 1; i <= cnt; ++i)
{
@@ -458,7 +464,8 @@ int PointInPolygon (const IntPoint &pt, const Path &path)
{
double d = (double)(ip.X - pt.X) * (ipNext.Y - pt.Y) -
(double)(ipNext.X - pt.X) * (ip.Y - pt.Y);
if (!d) return -1;
if (!d)
return -1;
if ((d > 0) == (ipNext.Y > ip.Y)) result = 1 - result;
}
} else
@@ -467,7 +474,8 @@ int PointInPolygon (const IntPoint &pt, const Path &path)
{
double d = (double)(ip.X - pt.X) * (ipNext.Y - pt.Y) -
(double)(ipNext.X - pt.X) * (ip.Y - pt.Y);
if (!d) return -1;
if (!d)
return -1;
if ((d > 0) == (ipNext.Y > ip.Y)) result = 1 - result;
}
}
@@ -499,7 +507,8 @@ int PointInPolygon (const IntPoint &pt, OutPt *op)
{
double d = (double)(op->Pt.X - pt.X) * (op->Next->Pt.Y - pt.Y) -
(double)(op->Next->Pt.X - pt.X) * (op->Pt.Y - pt.Y);
if (!d) return -1;
if (!d)
return -1;
if ((d > 0) == (op->Next->Pt.Y > op->Pt.Y)) result = 1 - result;
}
} else
@@ -508,7 +517,8 @@ int PointInPolygon (const IntPoint &pt, OutPt *op)
{
double d = (double)(op->Pt.X - pt.X) * (op->Next->Pt.Y - pt.Y) -
(double)(op->Next->Pt.X - pt.X) * (op->Pt.Y - pt.Y);
if (!d) return -1;
if (!d)
return -1;
if ((d > 0) == (op->Next->Pt.Y > op->Pt.Y)) result = 1 - result;
}
}
@@ -527,7 +537,8 @@ bool Poly2ContainsPoly1(OutPt *OutPt1, OutPt *OutPt2)
{
//nb: PointInPolygon returns 0 if false, +1 if true, -1 if pt on polygon
int res = PointInPolygon(op->Pt, OutPt2);
if (res >= 0) return res > 0;
if (res >= 0)
return res > 0;
op = op->Next;
}
while (op != OutPt1);
@@ -688,7 +699,8 @@ void IntersectPoint(TEdge &Edge1, TEdge &Edge2, IntPoint &ip)
void ReversePolyPtLinks(OutPt *pp)
{
if (!pp) return;
if (!pp)
return;
OutPt *pp1, *pp2;
pp1 = pp;
do {
@@ -702,7 +714,8 @@ void ReversePolyPtLinks(OutPt *pp)
void DisposeOutPts(OutPt*& pp)
{
if (pp == 0) return;
if (pp == 0)
return;
pp->Prev->Next = 0;
while( pp )
{
@@ -1058,7 +1071,8 @@ bool ClipperBase::AddPath(const Path &pg, PolyType PolyTyp, bool Closed)
int highI = (int)pg.size() -1;
if (Closed) while (highI > 0 && (pg[highI] == pg[0])) --highI;
while (highI > 0 && (pg[highI] == pg[highI -1])) --highI;
if ((Closed && highI < 2) || (!Closed && highI < 1)) return false;
if ((Closed && highI < 2) || (!Closed && highI < 1))
return false;
//create a new edge array ...
TEdge *edges = new TEdge [highI +1];
@@ -1254,7 +1268,8 @@ void ClipperBase::Clear()
void ClipperBase::Reset()
{
m_CurrentLM = m_MinimaList.begin();
if (m_CurrentLM == m_MinimaList.end()) return; //ie nothing to process
if (m_CurrentLM == m_MinimaList.end()) //ie nothing to process
return;
std::sort(m_MinimaList.begin(), m_MinimaList.end(), LocMinSorter());
//reset all edges ...
@@ -1288,7 +1303,8 @@ void ClipperBase::DisposeLocalMinimaList()
void ClipperBase::PopLocalMinima()
{
if (m_CurrentLM == m_MinimaList.end()) return;
if (m_CurrentLM == m_MinimaList.end())
return;
++m_CurrentLM;
}
//------------------------------------------------------------------------------
@@ -1383,7 +1399,8 @@ void Clipper::Reset()
bool Clipper::Execute(ClipType clipType, Paths &solution,
PolyFillType subjFillType, PolyFillType clipFillType)
{
if( m_ExecuteLocked ) return false;
if( m_ExecuteLocked )
return false;
if (m_HasOpenPaths)
throw clipperException("Error: PolyTree struct is need for open path clipping.");
m_ExecuteLocked = true;
@@ -1403,7 +1420,8 @@ bool Clipper::Execute(ClipType clipType, Paths &solution,
bool Clipper::Execute(ClipType clipType, PolyTree& polytree,
PolyFillType subjFillType, PolyFillType clipFillType)
{
if( m_ExecuteLocked ) return false;
if( m_ExecuteLocked )
return false;
m_ExecuteLocked = true;
m_SubjFillType = subjFillType;
m_ClipFillType = clipFillType;
@@ -1437,7 +1455,8 @@ bool Clipper::ExecuteInternal()
bool succeeded = true;
try {
Reset();
if (m_CurrentLM == m_MinimaList.end()) return true;
if (m_CurrentLM == m_MinimaList.end())
return true;
cInt botY = PopScanbeam();
do {
InsertLocalMinimaIntoAEL(botY);
@@ -1646,16 +1665,20 @@ bool Clipper::IsContributing(const TEdge& edge) const
{
case pftEvenOdd:
//return false if a subj line has been flagged as inside a subj polygon
if (edge.WindDelta == 0 && edge.WindCnt != 1) return false;
if (edge.WindDelta == 0 && edge.WindCnt != 1)
return false;
break;
case pftNonZero:
if (Abs(edge.WindCnt) != 1) return false;
if (Abs(edge.WindCnt) != 1)
return false;
break;
case pftPositive:
if (edge.WindCnt != 1) return false;
if (edge.WindCnt != 1)
return false;
break;
default: //pftNegative
if (edge.WindCnt != -1) return false;
if (edge.WindCnt != -1)
return false;
}
switch(m_ClipType)
@@ -1954,7 +1977,8 @@ void Clipper::DeleteFromAEL(TEdge *e)
{
TEdge* AelPrev = e->PrevInAEL;
TEdge* AelNext = e->NextInAEL;
if( !AelPrev && !AelNext && (e != m_ActiveEdges) ) return; //already deleted
if( !AelPrev && !AelNext && (e != m_ActiveEdges) ) //already deleted
return;
if( AelPrev ) AelPrev->NextInAEL = AelNext;
else m_ActiveEdges = AelNext;
if( AelNext ) AelNext->PrevInAEL = AelPrev;
@@ -1967,7 +1991,8 @@ void Clipper::DeleteFromSEL(TEdge *e)
{
TEdge* SelPrev = e->PrevInSEL;
TEdge* SelNext = e->NextInSEL;
if( !SelPrev && !SelNext && (e != m_SortedEdges) ) return; //already deleted
if( !SelPrev && !SelNext && (e != m_SortedEdges) ) //already deleted
return;
if( SelPrev ) SelPrev->NextInSEL = SelNext;
else m_SortedEdges = SelNext;
if( SelNext ) SelNext->PrevInSEL = SelPrev;
@@ -1979,7 +2004,8 @@ void Clipper::DeleteFromSEL(TEdge *e)
#ifdef use_xyz
void Clipper::SetZ(IntPoint& pt, TEdge& e1, TEdge& e2)
{
if (pt.Z != 0 || !m_ZFill) return;
if (pt.Z != 0 || !m_ZFill)
return;
else if (pt == e1.Bot) pt.Z = e1.Bot.Z;
else if (pt == e1.Top) pt.Z = e1.Top.Z;
else if (pt == e2.Bot) pt.Z = e2.Bot.Z;
@@ -2004,7 +2030,8 @@ void Clipper::IntersectEdges(TEdge *e1, TEdge *e2, IntPoint &Pt)
{
//ignore subject-subject open path intersections UNLESS they
//are both open paths, AND they are both 'contributing maximas' ...
if (e1->WindDelta == 0 && e2->WindDelta == 0) return;
if (e1->WindDelta == 0 && e2->WindDelta == 0)
return;
//if intersecting a subj line with a subj poly ...
else if (e1->PolyTyp == e2->PolyTyp &&
@@ -2211,7 +2238,8 @@ OutRec* GetLowermostRec(OutRec *outRec1, OutRec *outRec2)
outRec2->BottomPt = GetBottomPt(outRec2->Pts);
OutPt *OutPt1 = outRec1->BottomPt;
OutPt *OutPt2 = outRec2->BottomPt;
if (OutPt1->Pt.Y > OutPt2->Pt.Y) return outRec1;
if (OutPt1->Pt.Y > OutPt2->Pt.Y)
return outRec1;
else if (OutPt1->Pt.Y < OutPt2->Pt.Y) return outRec2;
else if (OutPt1->Pt.X < OutPt2->Pt.X) return outRec1;
else if (OutPt1->Pt.X > OutPt2->Pt.X) return outRec2;
@@ -2227,7 +2255,8 @@ bool Param1RightOfParam2(OutRec* outRec1, OutRec* outRec2)
do
{
outRec1 = outRec1->FirstLeft;
if (outRec1 == outRec2) return true;
if (outRec1 == outRec2)
return true;
} while (outRec1);
return false;
}
@@ -2379,7 +2408,8 @@ OutPt* Clipper::AddOutPt(TEdge *e, const IntPoint &pt)
//OutRec.Pts is the 'Left-most' point & OutRec.Pts.Prev is the 'Right-most'
OutPt* op = outRec->Pts;
if (ToFront && (pt == op->Pt)) return op;
if (ToFront && (pt == op->Pt))
return op;
else if (!ToFront && (pt == op->Prev->Pt)) return op->Prev;
OutPt* newOp = new OutPt;
@@ -2490,8 +2520,10 @@ void Clipper::SwapPositionsInAEL(TEdge *Edge1, TEdge *Edge2)
void Clipper::SwapPositionsInSEL(TEdge *Edge1, TEdge *Edge2)
{
if( !( Edge1->NextInSEL ) && !( Edge1->PrevInSEL ) ) return;
if( !( Edge2->NextInSEL ) && !( Edge2->PrevInSEL ) ) return;
if( !( Edge1->NextInSEL ) && !( Edge1->PrevInSEL ) )
return;
if( !( Edge2->NextInSEL ) && !( Edge2->PrevInSEL ) )
return;
if( Edge1->NextInSEL == Edge2 )
{
@@ -2655,7 +2687,8 @@ void Clipper::ProcessHorizontal(TEdge *horzEdge, bool isTopOfScanbeam)
OutPt* op1 = AddOutPt( horzEdge, horzEdge->Top);
if (isTopOfScanbeam) AddGhostJoin(op1, horzEdge->Bot);
UpdateEdgeIntoAEL(horzEdge);
if (horzEdge->WindDelta == 0) return;
if (horzEdge->WindDelta == 0)
return;
//nb: HorzEdge is no longer horizontal here
TEdge* ePrev = horzEdge->PrevInAEL;
TEdge* eNext = horzEdge->NextInAEL;
@@ -2712,11 +2745,13 @@ void Clipper::UpdateEdgeIntoAEL(TEdge *&e)
bool Clipper::ProcessIntersections(const cInt topY)
{
if( !m_ActiveEdges ) return true;
if( !m_ActiveEdges )
return true;
try {
BuildIntersectList(topY);
size_t IlSize = m_IntersectList.size();
if (IlSize == 0) return true;
if (IlSize == 0)
return true;
if (IlSize == 1 || FixupIntersectionOrder()) ProcessIntersectList();
else return false;
}
@@ -2741,7 +2776,8 @@ void Clipper::DisposeIntersectNodes()
void Clipper::BuildIntersectList(const cInt topY)
{
if ( !m_ActiveEdges ) return;
if ( !m_ActiveEdges )
return;
//prepare for sorting ...
TEdge* e = m_ActiveEdges;
@@ -2830,7 +2866,8 @@ bool Clipper::FixupIntersectionOrder()
{
size_t j = i + 1;
while (j < cnt && !EdgesAdjacent(*m_IntersectList[j])) j++;
if (j == cnt) return false;
if (j == cnt)
return false;
std::swap(m_IntersectList[i], m_IntersectList[j]);
}
SwapPositionsInSEL(m_IntersectList[i]->Edge1, m_IntersectList[i]->Edge2);
@@ -3033,7 +3070,8 @@ void Clipper::FixupOutPolygon(OutRec &outrec)
int PointCount(OutPt *Pts)
{
if (!Pts) return 0;
if (!Pts)
return 0;
int result = 0;
OutPt* p = Pts;
do
@@ -3223,7 +3261,8 @@ bool JoinHorz(OutPt* op1, OutPt* op1b, OutPt* op2, OutPt* op2b,
{
Direction Dir1 = (op1->Pt.X > op1b->Pt.X ? dRightToLeft : dLeftToRight);
Direction Dir2 = (op2->Pt.X > op2b->Pt.X ? dRightToLeft : dLeftToRight);
if (Dir1 == Dir2) return false;
if (Dir1 == Dir2)
return false;
//When DiscardLeft, we want Op1b to be on the Left of Op1, otherwise we
//want Op1b to be on the Right. (And likewise with Op2 and Op2b.)
@@ -3323,7 +3362,8 @@ bool Clipper::JoinPoints(Join *j, OutRec* outRec1, OutRec* outRec2)
(j->OffPt == j->OutPt2->Pt))
{
//Strictly Simple join ...
if (outRec1 != outRec2) return false;
if (outRec1 != outRec2)
return false;
op1b = j->OutPt1->Next;
while (op1b != op1 && (op1b->Pt == j->OffPt))
op1b = op1b->Next;
@@ -3332,7 +3372,8 @@ bool Clipper::JoinPoints(Join *j, OutRec* outRec1, OutRec* outRec2)
while (op2b != op2 && (op2b->Pt == j->OffPt))
op2b = op2b->Next;
bool reverse2 = (op2b->Pt.Y > j->OffPt.Y);
if (reverse1 == reverse2) return false;
if (reverse1 == reverse2)
return false;
if (reverse1)
{
op1b = DupOutPt(op1, false);
@@ -3367,14 +3408,16 @@ bool Clipper::JoinPoints(Join *j, OutRec* outRec1, OutRec* outRec2)
op1 = op1->Prev;
while (op1b->Next->Pt.Y == op1b->Pt.Y && op1b->Next != op1 && op1b->Next != op2)
op1b = op1b->Next;
if (op1b->Next == op1 || op1b->Next == op2) return false; //a flat 'polygon'
if (op1b->Next == op1 || op1b->Next == op2) //a flat 'polygon'
return false;
op2b = op2;
while (op2->Prev->Pt.Y == op2->Pt.Y && op2->Prev != op2b && op2->Prev != op1b)
op2 = op2->Prev;
while (op2b->Next->Pt.Y == op2b->Pt.Y && op2b->Next != op2 && op2b->Next != op1)
op2b = op2b->Next;
if (op2b->Next == op2 || op2b->Next == op1) return false; //a flat 'polygon'
if (op2b->Next == op2 || op2b->Next == op1) //a flat 'polygon'
return false;
cInt Left, Right;
//Op1 --> Op1b & Op2 --> Op2b are the extremites of the horizontal edges
@@ -3653,7 +3696,8 @@ void ClipperOffset::Clear()
void ClipperOffset::AddPath(const Path& path, JoinType joinType, EndType endType)
{
int highI = (int)path.size() - 1;
if (highI < 0) return;
if (highI < 0)
return;
PolyNode* newNode = new PolyNode();
newNode->m_jointype = joinType;
newNode->m_endtype = endType;
@@ -3681,7 +3725,8 @@ void ClipperOffset::AddPath(const Path& path, JoinType joinType, EndType endType
m_polyNodes.AddChild(*newNode);
//if this path's lowest pt is lower than all the others then update m_lowest
if (endType != etClosedPolygon) return;
if (endType != etClosedPolygon)
return;
if (m_lowest.X < 0)
m_lowest = IntPoint(m_polyNodes.ChildCount() - 1, k);
else
@@ -4450,7 +4495,8 @@ std::ostream& operator <<(std::ostream &s, const IntPoint &p)
std::ostream& operator <<(std::ostream &s, const Path &p)
{
if (p.empty()) return s;
if (p.empty())
return s;
Path::size_type last = p.size() -1;
for (Path::size_type i = 0; i < last; i++)
s << "(" << p[i].X << "," << p[i].Y << "), ";

View File

@@ -1047,7 +1047,8 @@ bool CDxfRead::ReadLwPolyLine()
case 70:
// flags
get_line();
if(sscanf(m_str, "%d", &flags) != 1)return false;
if(sscanf(m_str, "%d", &flags) != 1)
return false;
closed = ((flags & 1) != 0);
break;
case 62:
@@ -1207,7 +1208,8 @@ bool CDxfRead::ReadPolyLine()
case 70:
// flags
get_line();
if(sscanf(m_str, "%d", &flags) != 1)return false;
if(sscanf(m_str, "%d", &flags) != 1)
return false;
closed = ((flags & 1) != 0);
break;
case 62:
@@ -1452,7 +1454,8 @@ bool CDxfRead::ReadLayer()
case 62:
// layer color ; if negative, layer is off
get_line();
if(sscanf(m_str, "%d", &aci) != 1)return false;
if(sscanf(m_str, "%d", &aci) != 1)
return false;
break;
case 6: // linetype name
@@ -1476,14 +1479,16 @@ bool CDxfRead::ReadLayer()
void CDxfRead::DoRead(const bool ignore_errors /* = false */ )
{
m_ignore_errors = ignore_errors;
if(m_fail)return;
if(m_fail)
return;
get_line();
while(!((*m_ifs).eof()))
{
if (!strcmp( m_str, "$INSUNITS" )){
if (!ReadUnits())return;
if (!ReadUnits())
return;
continue;
} // End if - then

View File

@@ -150,7 +150,8 @@ namespace geoff_geometry {
bool Point3d::operator==(const Point3d &p)const{
// p1 == p2 (uses TOLERANCE)
if(FNE(this->x, p.x, TOLERANCE) || FNE(this->y, p.y, TOLERANCE) || FNE(this->z, p.z, TOLERANCE)) return false;
if(FNE(this->x, p.x, TOLERANCE) || FNE(this->y, p.y, TOLERANCE) || FNE(this->z, p.z, TOLERANCE))
return false;
return true;
}
@@ -179,7 +180,8 @@ namespace geoff_geometry {
bool Point::operator==(const Point &p) const{
// p1 == p2 (uses TOLERANCE)
if(FNE(this->x, p.x, TOLERANCE) || FNE(this->y, p.y, TOLERANCE)) return false;
if(FNE(this->x, p.x, TOLERANCE) || FNE(this->y, p.y, TOLERANCE))
return false;
return true;
}
@@ -504,12 +506,15 @@ namespace geoff_geometry {
intof = s.Intof(normal);
double d = intof.Dist(c.pc);
if(fabs(d - c.radius) < TOLERANCE) return intof; // tangent (near enough for non-large radius I suppose?)
if(fabs(d - c.radius) < TOLERANCE) // tangent (near enough for non-large radius I suppose?)
return intof;
if(d > c.radius + TOLERANCE) return INVALID_POINT; // no intersection
if(d > c.radius + TOLERANCE) // no intersection
return INVALID_POINT;
double q = (c.radius - d) * (c.radius + d);
if(q < 0) return intof; // line inside tolerance
if(q < 0) // line inside tolerance
return intof;
return Along(s, -(double)NF * sqrt(q), intof); // 2 intersections (return near/far case)
}
@@ -545,20 +550,24 @@ namespace geoff_geometry {
// returns the number of intersctions
Vector2d v(c0.pc, c1.pc);
double d = v.normalise();
if(d < TOLERANCE) return 0; // co-incident circles
if(d < TOLERANCE) // co-incident circles
return 0;
double sum = fabs(c0.radius) + fabs(c1.radius);
double diff = fabs(fabs(c0.radius) - fabs(c1.radius));
if(d > sum + TOLERANCE || d < diff - TOLERANCE) return 0;
if(d > sum + TOLERANCE || d < diff - TOLERANCE)
return 0;
// dist from centre of this circle to mid intersection
double d0 = 0.5 * (d + (c0.radius + c1.radius) * (c0.radius - c1.radius) / d);
if(d0 - c0.radius > TOLERANCE) return 0; // circles don't intersect
if(d0 - c0.radius > TOLERANCE) // circles don't intersect
return 0;
double h = (c0.radius - d0) * (c0.radius + d0); // half distance between intersects squared
if(h < 0) d0 = c0.radius; // tangent
pLeft = v * d0 + c0.pc; // mid-point of intersects
if(h < TOLERANCE_SQ) return 1; // tangent
if(h < TOLERANCE_SQ) // tangent
return 1;
h = sqrt(h);
v = ~v; // calculate 2 intersects
@@ -571,7 +580,8 @@ namespace geoff_geometry {
Circle Tanto(int NF, CLine& s0, Point& p, double rad) {
// circle tanto a CLine thro' a point
double d = s0.Dist(p);
if(fabs(d) > rad + TOLERANCE) return INVALID_CIRCLE; // point too far from line
if(fabs(d) > rad + TOLERANCE) // point too far from line
return INVALID_CIRCLE;
CLine s0offset = Parallel(RIGHTINT, s0, rad);
return Circle(Intof(NF, s0offset, Circle(p, rad)), rad);
@@ -590,11 +600,13 @@ namespace geoff_geometry {
double d = s1.v.gety() * (AT2 * s3.v.getx() - AT3 * s2.v.getx())
+ s2.v.gety() * (AT3 * s1.v.getx() - AT1 * s3.v.getx())
+ s3.v.gety() * (AT1 * s2.v.getx() - AT2 * s1.v.getx());
if(fabs(d) < UNIT_VECTOR_TOLERANCE) return INVALID_CIRCLE;
if(fabs(d) < UNIT_VECTOR_TOLERANCE)
return INVALID_CIRCLE;
double radius = (s1.v.gety() * (s2.v.getx() * s3c - s3.v.getx() * s2c)
+ s2.v.gety() * (s3.v.getx() * s1c - s1.v.getx() * s3c)
+ s3.v.gety() * (s1.v.getx() * s2c - s2.v.getx() * s1c)) / d ;
if(radius < TOLERANCE) return INVALID_CIRCLE;
if(radius < TOLERANCE)
return INVALID_CIRCLE;
CLine Offs1 = Parallel(AT1, s1, radius);
CLine Offs2 = Parallel(AT2, s2, radius);
@@ -603,7 +615,8 @@ namespace geoff_geometry {
if(!p.ok) {
CLine Offs3 = Parallel(AT3, s3, radius); // s1 & s2 parallel
p = Intof(Offs1, Offs3);
if(!p.ok) return INVALID_CIRCLE; // 3 parallel lines
if(!p.ok) // 3 parallel lines
return INVALID_CIRCLE;
}
return Circle(p, radius);
}
@@ -614,7 +627,8 @@ namespace geoff_geometry {
double d = 0.5 * p0.Dist(p1);
Point pm = Mid(p0, p1);
if(d > rad + TOLERANCE) return INVALID_CIRCLE;
if(d > rad + TOLERANCE)
return INVALID_CIRCLE;
else if(d > rad - TOLERANCE) {
// within tolerance of centre of 2 points
return Circle(pm, d);
@@ -634,13 +648,16 @@ namespace geoff_geometry {
Circle Thro(const Point& p0, const Point& p1, const Point& p2) {
// circle thro 3 points
CLine s0(p0, p1);
if(!s0.ok) return Thro(p1,p2); // p0 & p1 coincident
if(!s0.ok) // p0 & p1 coincident
return Thro(p1,p2);
CLine s1(p0, p2);
if(!s1.ok) return Thro(p0, p1); // p0 & p2 coincident
if(!s1.ok) // p0 & p2 coincident
return Thro(p0, p1);
CLine s2(p2, p1);
if(!s2.ok) return Thro(p0, p2); // p1 & p2 coincident
if(!s2.ok) // p1 & p2 coincident
return Thro(p0, p2);
Point p = Intof(Normal(s0, Mid(p0, p1)), Normal(s1, Mid(p0, p2)));
return (p.ok)? Circle(p, p0.Dist(p)) : INVALID_CIRCLE;
@@ -707,7 +724,8 @@ namespace geoff_geometry {
double IncludedAngle(const Vector2d& v0, const Vector2d& v1, int dir) {
// returns the absolute included angle between 2 vectors in the direction of dir ( 1=acw -1=cw)
double inc_ang = v0 * v1;
if(inc_ang > 1. - UNIT_VECTOR_TOLERANCE) return 0;
if(inc_ang > 1. - UNIT_VECTOR_TOLERANCE)
return 0;
if(inc_ang < -1. + UNIT_VECTOR_TOLERANCE)
inc_ang = PI;
else { // dot product, v1 . v2 = cos ang
@@ -740,7 +758,8 @@ namespace geoff_geometry {
// 1 (LEFT) = left turn
// -1 (RIGHT) = right turn
double cp = v0 ^ v1;
if(fabs(cp) < cpTol) return TANGENT;
if(fabs(cp) < cpTol)
return TANGENT;
return (cp > 0)?GEOFF_LEFT : GEOFF_RIGHT;
}
@@ -752,14 +771,16 @@ namespace geoff_geometry {
double epsilon = (geoff_geometry::UNITS == METRES)?1.0e-09 : 1.0e-06;
double epsilonsq = epsilon * epsilon;
if(fabs(a) < epsilon) {
if(fabs(b) < epsilon) return 0; // invalid
if(fabs(b) < epsilon) // invalid
return 0;
x0 = - c / b;
return 1;
}
b /= a;
c /= a;
double s = b * b - 4 * c;
if(s < -epsilon) return 0; // imaginary roots
if(s < -epsilon) // imaginary roots
return 0;
x0 = - 0.5 * b;
if(s > epsilonsq) {
s = 0.5 * sqrt(s);
@@ -810,7 +831,8 @@ namespace geoff_geometry {
// output intof
// method returns true for valid intersection
double den = l.v * this->normal;
if(fabs(den) < UNIT_VECTOR_TOLERANCE) return false; // line is parallel to the plane, return false, even if the line lies on the plane
if(fabs(den) < UNIT_VECTOR_TOLERANCE) // line is parallel to the plane, return false, even if the line lies on the plane
return false;
t = -(normal * Vector3d(l.p0) + d) / den;
intof = l.v * t + l.p0;
@@ -822,7 +844,8 @@ namespace geoff_geometry {
Vector3d d = this->normal ^ pl.normal;
d.normalise();
intof.ok = false;
if(d == NULL_VECTOR) return false; // parallel planes
if(d == NULL_VECTOR) // parallel planes
return false;
intof.v = d;
intof.length = 1;

View File

@@ -18,7 +18,8 @@ namespace geoff_geometry {
int Intof(const Span& sp0, const Span& sp1, Point& p0, Point& p1, double t[4])
{
// returns the number of intersects (lying within spans sp0, sp1)
if(sp0.box.outside(sp1.box) == true) return 0;
if(sp0.box.outside(sp1.box) == true)
return 0;
if(!sp0.dir) {
if(!sp1.dir) {
// line line
@@ -64,9 +65,11 @@ namespace geoff_geometry {
double toler = geoff_geometry::TOLERANCE / sp0.length; // calc a parametric tolerance
t[1] = (v0 ^ v2) / cp;
if(t[0] < -toler || t[0] > 1 + toler) return 0; // intersection on first?
if(t[0] < -toler || t[0] > 1 + toler) // intersection on first?
return 0;
toler = geoff_geometry::TOLERANCE / sp1.length; // calc a parametric tolerance
if(t[1] < -toler || t[1] > 1 + toler) return 0; // intersection on second?
if(t[1] < -toler || t[1] > 1 + toler) // intersection on second?
return 0;
return 1;
}
@@ -237,7 +240,8 @@ namespace geoff_geometry {
bool Line::atZ(double z, Point3d& p)const {
// returns p at z on line
if(FEQZ(this->v.getz())) return false;
if(FEQZ(this->v.getz()))
return false;
double t = (z - this->p0.z) / this->v.getz();
p = Point3d(this->p0.x + t * this->v.getx(), this->p0.y + t * this->v.gety(), z);
return true;
@@ -259,7 +263,8 @@ namespace geoff_geometry {
*/
Vector3d v13(l2.p0, this->p0);
if(this->ok == false || l2.ok == false) return false;
if(this->ok == false || l2.ok == false)
return false;
double d1343 = v13 * l2.v; // dot products
double d4321 = l2.v * this->v;
@@ -268,7 +273,8 @@ namespace geoff_geometry {
double d2121 = this->v * this->v;
double denom = d2121 * d4343 - d4321 * d4321;
if(fabs(denom) < 1.0e-09) return false;
if(fabs(denom) < 1.0e-09)
return false;
double numer = d1343 * d4321 - d1321 * d4343;
t1 = numer / denom;
@@ -308,7 +314,8 @@ namespace geoff_geometry {
c = Vector3d(l1, l0)
*/
// Vector3d a = l0.v;
if(l0.box.outside(l1.box) == true) return 0;
if(l0.box.outside(l1.box) == true)
return 0;
Vector3d b = -l1.v;
Vector3d c = Vector3d(l1.p0, l0.p0);
Vector3d det = l0.v ^ b;
@@ -331,17 +338,20 @@ namespace geoff_geometry {
}
}
if(fabs(d) < 1.0e-06) return 0;
if(fabs(d) < 1.0e-06)
return 0;
t0 /= d;
intof = l0.v * t0 + l0.p0;
Point3d other;
double t1;
if(Dist(l1, intof, other, t1) > geoff_geometry::TOLERANCE) return 0;
if(Dist(l1, intof, other, t1) > geoff_geometry::TOLERANCE)
return 0;
t0 *= l0.length;
if( t0 < -geoff_geometry::TOLERANCE || t0 > l0.length + geoff_geometry::TOLERANCE || t1 < -geoff_geometry::TOLERANCE || t1 > l1.length + geoff_geometry::TOLERANCE ) return 0;
if( t0 < -geoff_geometry::TOLERANCE || t0 > l0.length + geoff_geometry::TOLERANCE || t1 < -geoff_geometry::TOLERANCE || t1 > l1.length + geoff_geometry::TOLERANCE )
return 0;
return 1;
}
@@ -419,7 +429,8 @@ namespace geoff_geometry {
pnear = v * (sp.radius / radiusp) + sp.pc;
// check if projected point is on the arc
if(sp.OnSpan(pnear)) return fabs(radiusp - sp.radius);
if(sp.OnSpan(pnear))
return fabs(radiusp - sp.radius);
// double h1 = pnear.x - sp.p0.x ;
// double v1 = pnear.y - sp.p0.y ;
// double h2 = sp.p1.x - pnear.x ;
@@ -455,7 +466,8 @@ namespace geoff_geometry {
if(sp.dir) {
// arc
if(fabs(p.Dist(sp.pc) - sp.radius) > geoff_geometry::TOLERANCE) {
if(!nearPoints) return false;
if(!nearPoints)
return false;
}
pNear = On(Circle(sp.pc, sp.radius), p);
@@ -472,7 +484,8 @@ namespace geoff_geometry {
else {
// straight
if(fabs(CLine(sp.p0, sp.vs).Dist(p)) > geoff_geometry::TOLERANCE) {
if(!nearPoints) return false;
if(!nearPoints)
return false;
}
Vector2d v(sp.p0, p);
double t = v * sp.vs;
@@ -513,7 +526,8 @@ namespace geoff_geometry {
// function returns true for intersection, false for no intersection
// method based on Möller & Trumbore(1997) (Barycentric coordinates)
// based on incorrect Pseudo code from "Geometric Tools for Computer Graphics" p.487
if(box.outside(l.box) == true) return false;
if(box.outside(l.box) == true)
return false;
Vector3d line(l.v);
line.normalise();
@@ -521,19 +535,23 @@ namespace geoff_geometry {
Vector3d p = line ^ v1; // cross product
double tmp = p * v0; // dot product
if(FEQZ(tmp)) return false;
if(FEQZ(tmp))
return false;
tmp = 1 / tmp;
Vector3d s(vert1, l.p0);
double u = tmp * (s * p); // barycentric coordinate
if(u < 0 || u > 1) return false; // not inside triangle
if(u < 0 || u > 1) // not inside triangle
return false;
Vector3d q = s ^ v0;
double v = tmp * (line * q); // barycentric coordinate
if(v < 0 || v > 1) return false; // not inside triangle
if(v < 0 || v > 1) // not inside triangle
return false;
if( u + v > 1) return false; // not inside triangle
if( u + v > 1) // not inside triangle
return false;
double t = tmp * (v1 * q);
intof = line * t + l.p0;
@@ -544,11 +562,16 @@ namespace geoff_geometry {
// box class
bool Box::outside(const Box& b)const {
// returns true if this box is outside b
if(b.ok == false || this->ok == false) return false; // no box set
if(this->max.x < b.min.x) return true;
if(this->max.y < b.min.y) return true;
if(this->min.x > b.max.x) return true;
if(this->min.y > b.max.y) return true;
if(b.ok == false || this->ok == false) // no box set
return false;
if(this->max.x < b.min.x)
return true;
if(this->max.y < b.min.y)
return true;
if(this->min.x > b.max.x)
return true;
if(this->min.y > b.max.y)
return true;
return false;
}
@@ -570,24 +593,33 @@ namespace geoff_geometry {
bool Box3d::outside(const Box3d& b) const{
// returns true if this box is outside b
if(b.ok == false || this->ok == false) return false; // no box set
if(this->max.x < b.min.x) return true;
if(this->max.y < b.min.y) return true;
if(this->max.z < b.min.z) return true;
if(this->min.x > b.max.x) return true;
if(this->min.y > b.max.y) return true;
if(this->min.z > b.max.z) return true;
if(b.ok == false || this->ok == false) // no box set
return false;
if(this->max.x < b.min.x)
return true;
if(this->max.y < b.min.y)
return true;
if(this->max.z < b.min.z)
return true;
if(this->min.x > b.max.x)
return true;
if(this->min.y > b.max.y)
return true;
if(this->min.z > b.max.z)
return true;
return false;
}
#if 0
Span3d IsPtsSpan3d(const double* a, int n, double tolerance, double* deviation) {
// returns a span3d if all points are within tolerance
int np = n / 3; // number of points
if(np < 2) return Span3d(); // Invalid span3d
if(np < 2) // Invalid span3d
return Span3d();
Point3d sp = Point3d(&a[0]);
Point3d ep = Point3d(&a[n-3]);
Line line = IsPtsLine(a, n, tolerance, deviation);
if(line.ok) return Span3d(sp, ep); // it's a line
if(line.ok) // it's a line
return Span3d(sp, ep);
*deviation = 0; // cumulative deviation
Point3d mp = Point3d(&a[np / 2 * 3]); // mid point
@@ -632,7 +664,8 @@ double tolerance = 10.0 * 1.0e-6;
// deviation is returned as the sum of all deviations of interior points to line(sp,ep)
int np = n / 3; // number of points
*deviation = 0; // cumulative deviation
if(np < 2) return Line(); // Invalid line
if(np < 2) // Invalid line
return Line();
Point3d sp(&a[0]);
Point3d ep(&a[n-3]);

View File

@@ -36,9 +36,11 @@ namespace geoff_geometry {
bool Matrix::operator==(const Matrix &m)const{
// m1 == m2
if(this->m_unit != m.m_unit || this->m_mirrored != m.m_mirrored) return false;
if(this->m_unit != m.m_unit || this->m_mirrored != m.m_mirrored)
return false;
for(int i = 0; i < 16; i++)
if(FEQ(this->e[i], m.e[i], TIGHT_TOLERANCE) == false) return false;
if(FEQ(this->e[i], m.e[i], TIGHT_TOLERANCE) == false)
return false;
return true;
}
@@ -227,10 +229,12 @@ namespace geoff_geometry {
// returns true if unit matrix
for(int i = 0; i < 16; i++) {
if(i == 0 || i == 5 || i == 10 || i == 15) {
if(e[i] != 1) return m_unit = false;
if(e[i] != 1)
return m_unit = false;
}
else {
if(e[i] != 0) return m_unit = false;
if(e[i] != 0)
return m_unit = false;
}
}
m_mirrored = false;
@@ -343,7 +347,8 @@ namespace geoff_geometry {
Matrix a = *this;
int l[4], m[4];
if(a.m_unit) return a; // unit matrix
if(a.m_unit) // unit matrix
return a;
// search for largest element
nk = - n ;

View File

@@ -186,7 +186,8 @@ namespace geoff_geometry {
}
#endif
static int Split(double tolerance, double angle, double radius, int dir) {
if(dir == LINEAR) return 0; // straight span
if(dir == LINEAR) // straight span
return 0;
double cosa = 1 - tolerance / radius;
if(cosa > NEARLY_ONE) cosa = NEARLY_ONE;
cosa = 2 * cosa * cosa - 1 ; /* double angle */
@@ -327,7 +328,8 @@ namespace geoff_geometry {
return this->vs * t + this->p0;
} else {
double r = p.Dist(this->pc);
if(r < geoff_geometry::TOLERANCE) return (p.Dist(this->p0) < p.Dist(this->p1))?this->p0 : this->p1;
if(r < geoff_geometry::TOLERANCE)
return (p.Dist(this->p0) < p.Dist(this->p1))?this->p0 : this->p1;
return(p.Mid(this->pc, (r - this->radius) / r));
}
}
@@ -335,7 +337,8 @@ namespace geoff_geometry {
// returns the near point to span from p - returned point is always on the span
Point pn;
pn = Near(p);
if(this->OnSpan(pn) == true) return pn;
if(this->OnSpan(pn) == true)
return pn;
// return nearest endpoint
return (pn.Dist(p0) < pn.Dist(p1))?p0 : p1;
@@ -390,8 +393,10 @@ namespace geoff_geometry {
Point Span::MidParam(double param)const {
/// returns a point which is 0-1 along span
if(fabs(param) < 0.00000000000001)return p0;
if(fabs(param - 1.0) < 0.00000000000001)return p1;
if(fabs(param) < 0.00000000000001)
return p0;
if(fabs(param - 1.0) < 0.00000000000001)
return p1;
return MidPerim(param * this->length);
}
@@ -589,7 +594,8 @@ return;
Point pv, pcc;
Get(m_nVertices - 1, pv, pcc);
if(pv.Dist(p0) < geoff_geometry::TOLERANCE) {
if(!AddNullSpans)return false;
if(!AddNullSpans)
return false;
span_type = LINEAR; // linear span
}
}
@@ -758,7 +764,8 @@ return;
int Kurve::Get(int spannumber, Span& sp, bool returnSpanProperties, bool transform) const {
// returns span data and optional properties - the function returns as the span type
if(spannumber < 1 || spannumber > m_nVertices) FAILURE(getMessage(L"Kurve::Get - vertexNumber out of range"));
if(m_nVertices < 2) return -99;
if(m_nVertices < 2)
return -99;
int spanVertexNumber = spannumber - 1;
if(m_isReversed) spanVertexNumber = m_nVertices - 1 - spanVertexNumber;
@@ -784,7 +791,8 @@ return;
int Kurve::Get(int spannumber, Span3d& sp, bool returnSpanProperties, bool transform) const {
// returns span data and optional properties - the function returns as the span type
if(spannumber < 1 || spannumber > m_nVertices) FAILURE(getMessage(L"Kurve::Get - vertexNumber out of range"));
if(m_nVertices < 2) return -99;
if(m_nVertices < 2)
return -99;
int spanVertexNumber = spannumber - 1;
SpanVertex* p = (SpanVertex*)m_spans[spanVertexNumber / SPANSTORAGE];
@@ -974,12 +982,14 @@ return;
if(startSpanno == 1) {
Span spFirst;
this->Get(1, spFirst, false, true);
if(spFirst.p0 == *pNewStart) return;
if(spFirst.p0 == *pNewStart)
return;
}
else if(startSpanno == this->nSpans()) {
Span spLast;
this->Get(this->nSpans(), spLast, false, true);
if(spLast.p1 == *pNewStart) return;
if(spLast.p1 == *pNewStart)
return;
}
Kurve temp;
@@ -1018,12 +1028,14 @@ return;
if(endSpanno == 1) {
Span spFirst;
this->Get(1, spFirst, false, true);
if(spFirst.p0 == *pNewEnd) return;
if(spFirst.p0 == *pNewEnd)
return;
}
else if(endSpanno == this->nSpans()) {
Span spLast;
this->Get(this->nSpans(), spLast, false, true);
if(spLast.p1 == *pNewEnd) return;
if(spLast.p1 == *pNewEnd)
return;
}
Kurve temp;
@@ -1089,12 +1101,14 @@ return;
bool Kurve::operator==(const Kurve &k)const{
// k = kk (vertex check)
if(nSpans() != k.nSpans()) return false;
if(nSpans() != k.nSpans())
return false;
spVertex thisvertex, vertex;
for(int i = 0; i <= nSpans(); i++) {
this->Get(i, thisvertex);
k.Get(i, vertex);
if(thisvertex != vertex) return false;
if(thisvertex != vertex)
return false;
}
return true;
}
@@ -1250,7 +1264,8 @@ return;
void Kurve::Reverse() {
// reverse the direction of a kurve
int nSwaps = (m_nVertices - 1) / 2;
if(nSwaps == 0) return;
if(nSwaps == 0)
return;
Point p0, pc0; // near
Point pend, pcend; // far
@@ -1313,7 +1328,8 @@ return;
int Kurve::Reduce(double tolerance) {
// remove spans that lie within tolerance
// returns the number of spans removed
if(nSpans() <= 2) return 0; // too few spans for this method
if(nSpans() <= 2) // too few spans for this method
return 0;
Kurve kReduced;
kReduced = Matrix(*this);

View File

@@ -273,7 +273,8 @@ namespace geoff_geometry {
sp.dir = k.Get(kCheckVertex++, sp.p1, sp.pc);
sp.SetProperties(true);
// check for interference
if(Dist(sp, pInt, dummy) < offset) return true;
if(Dist(sp, pInt, dummy) < offset)
return true;
sp.p0 = sp.p1;
}
return false; // intersection is ok

View File

@@ -165,7 +165,8 @@ py::list getCurveSpans(const CCurve& c)
Span getFirstCurveSpan(const CCurve& c)
{
if(c.m_vertices.size() < 2)return Span();
if(c.m_vertices.size() < 2)
return Span();
std::list<CVertex>::const_iterator VIt = c.m_vertices.begin();
const Point &p = (*VIt).m_p;
@@ -175,7 +176,8 @@ Span getFirstCurveSpan(const CCurve& c)
Span getLastCurveSpan(const CCurve& c)
{
if(c.m_vertices.size() < 2)return Span();
if(c.m_vertices.size() < 2)
return Span();
std::list<CVertex>::const_reverse_iterator VIt = c.m_vertices.rbegin();
const CVertex &v = (*VIt);