Fix for compiling with VS2013

This commit is contained in:
kreso-t
2018-08-21 10:55:36 +02:00
committed by wmayer
parent 337db65af6
commit 2c6d65e808
2 changed files with 63 additions and 47 deletions

View File

@@ -27,8 +27,8 @@ namespace AdaptivePath {
double dy = ((double)pt2.Y - pt1.Y);
double l=sqrt(Dx*Dx + dy*dy);
if(l>0.0) {
pt2.X = pt1.X + new_length * Dx/l;
pt2.Y = pt1.Y + new_length * dy/l;
pt2.X = long( pt1.X + new_length * Dx/l);
pt2.Y = long(pt1.Y + new_length * dy/l);
return true;
}
return false;
@@ -93,8 +93,8 @@ namespace AdaptivePath {
else if(parameter>lsegLenSqr) parameter=lsegLenSqr;
}
// point on line at parameter
closestPoint.X = p1.X + parameter*D21X/lsegLenSqr;
closestPoint.Y = p1.Y + parameter*D21Y/lsegLenSqr;
closestPoint.X = long(p1.X + parameter*D21X/lsegLenSqr);
closestPoint.Y = long(p1.Y + parameter*D21Y/lsegLenSqr);
// calculate distance from point on line to pt
double DX=double(pt.X-closestPoint.X);
double DY=double(pt.Y-closestPoint.Y);
@@ -161,7 +161,7 @@ namespace AdaptivePath {
}
inline double PointSideOfLine(const IntPoint& p1, const IntPoint& p2,const IntPoint& pt) {
return (pt.X - p1.X)*(p2.Y-p1.Y) - (pt.Y - p2.Y)*(p2.X-p1.X);
return double((pt.X - p1.X)*(p2.Y-p1.Y) - (pt.Y - p2.Y)*(p2.X-p1.X));
}
inline double Angle3Points(const DoublePoint & p1,const DoublePoint& p2, const DoublePoint& p3) {
@@ -201,7 +201,7 @@ namespace AdaptivePath {
// calculate center point of polygon
IntPoint Compute2DPolygonCentroid(const Path &vertices)
{
IntPoint centroid(0,0);
DoublePoint centroid(0,0);
double signedArea = 0.0;
double x0 = 0.0; // Current vertex X
double y0 = 0.0; // Current vertex Y
@@ -214,10 +214,10 @@ namespace AdaptivePath {
Path::size_type size = vertices.size();
for (i=0; i<size; ++i)
{
x0 = vertices[i].X;
y0 = vertices[i].Y;
x1 = vertices[(i+1) % size].X;
y1 = vertices[(i+1) % size].Y;
x0 = double(vertices[i].X);
y0 = double(vertices[i].Y);
x1 = double(vertices[(i+1) % size].X);
y1 = double(vertices[(i+1) % size].Y);
a = x0*y1 - x1*y0;
signedArea += a;
centroid.X += (x0 + x1)*a;
@@ -227,7 +227,7 @@ namespace AdaptivePath {
signedArea *= 0.5;
centroid.X /= (6.0*signedArea);
centroid.Y /= (6.0*signedArea);
return centroid;
return IntPoint(long(centroid.X),long(centroid.Y));
}
// point must be within first path (boundary) and must not be within all other paths (holes)
@@ -265,7 +265,7 @@ namespace AdaptivePath {
p1d<0 || p1d>d || p2d<0 || p2d>d
)) return true; // intersection not within segment2
double t=p1d/d;
intersection=IntPoint(s1p1.X + S1DX*t, s1p1.Y + S1DY*t);
intersection=IntPoint(long(s1p1.X + S1DX*t), long(s1p1.Y + S1DY*t));
return true;
}
@@ -297,7 +297,7 @@ namespace AdaptivePath {
p1d<0 || p1d>d || p2d<0 || p2d>d
)) continue; // intersection not within segment
double t=p1d/d;
intersection=IntPoint(p1.X + LDX*t, p1.Y + LDY*t);
intersection=IntPoint(long(p1.X + LDX*t), long(p1.Y + LDY*t));
return true;
}
}
@@ -473,7 +473,7 @@ namespace AdaptivePath {
const IntPoint * p1=&pth->at(currentSegmentIndex>0?currentSegmentIndex-1:pth->size()-1);
const IntPoint * p2=&pth->at(currentSegmentIndex);
double segLength =sqrt(DistanceSqrd(*p1,*p2));
return IntPoint(p1->X + segmentPos*double(p2->X-p1->X)/segLength,p1->Y + segmentPos*double(p2->Y-p1->Y)/segLength);
return IntPoint(long(p1->X + segmentPos*double(p2->X-p1->X)/segLength),long(p1->Y + segmentPos*double(p2->Y-p1->Y)/segLength));
}
DoublePoint getCurrentDir() {
@@ -585,7 +585,7 @@ namespace AdaptivePath {
// step 2: iterate throuh path from starting point and find the part of the path inside the c2
size_t prevPtIndex = curPtIndex;
Path *interPath;
Path *interPath=NULL;
bool prev_inside=false;
const IntPoint *p1=&path[prevPtIndex];
@@ -601,9 +601,9 @@ namespace AdaptivePath {
interPath=&interPaths.back();
// current segment inside c2, prev point outside, find intersection:
if(Line2CircleIntersect(c2,toolRadiusScaled,*p1,*p2,inters)) {
interPath->push_back(IntPoint(inters[0].X,inters[0].Y));
interPath->push_back(IntPoint(long(inters[0].X),long(inters[0].Y)));
if(inters.size()>1) {
interPath->push_back(IntPoint(inters[1].X,inters[1].Y));
interPath->push_back(IntPoint(long(inters[1].X),long(inters[1].Y)));
prev_inside=false;
} else {
interPath->push_back(IntPoint(*p2));
@@ -613,15 +613,16 @@ namespace AdaptivePath {
interPath->push_back(IntPoint(*p2));
}
}
} else { // state: inside
}
else if (interPath!=NULL) { // state: inside
if( (DistanceSqrd(c2,*p2) <= rsqrd)) { // next point still inside, add it and continue, no state change
interPath->push_back(IntPoint(*p2));
} else { // prev point inside, current point outside, find instersection
if(Line2CircleIntersect(c2,toolRadiusScaled,*p1,*p2,inters)) {
if(inters.size()>1) {
interPath->push_back(IntPoint(inters[1].X,inters[1].Y));
interPath->push_back(IntPoint(long(inters[1].X),long(inters[1].Y)));
} else {
interPath->push_back(IntPoint(inters[0].X,inters[0].Y));
interPath->push_back(IntPoint(long(inters[0].X),long(inters[0].Y)));
}
}
prev_inside=false;
@@ -661,7 +662,7 @@ namespace AdaptivePath {
// detect conventional mode cut - we want only climb mode
if(interPathLen>=RESOLUTION_FACTOR && !IsPointWithinCutRegion(cleared_paths,c2)) {
if(PointSideOfLine(fpc2,lpc2,c2)<0) {
IntPoint midPoint(c2.X + toolRadiusScaled*cos(0.5*(maxFi+minFi)),c2.Y + toolRadiusScaled*sin(0.5*(maxFi+minFi)));
IntPoint midPoint(long(c2.X + toolRadiusScaled*cos(0.5*(maxFi+minFi))),long(c2.Y + toolRadiusScaled*sin(0.5*(maxFi+minFi))));
if(PointSideOfLine(fpc2,lpc2,midPoint)>0) {
area = __DBL_MAX__;
Perf_CalcCutArea.Stop();
@@ -694,9 +695,9 @@ namespace AdaptivePath {
}
double dx=double(cpt->X-prevPt->X);
double dy=double(cpt->Y-prevPt->Y);
IntPoint segPoint(prevPt->X + dx*pos/segLen, prevPt->Y + dy*pos/segLen);
IntPoint scanPoint(c2.X + scanDistance*cos(minFi + distance*(maxFi-minFi)/interPathLen),
c2.Y + scanDistance*sin(minFi + distance*(maxFi-minFi)/interPathLen));
IntPoint segPoint(long(prevPt->X + dx*pos/segLen),long( prevPt->Y + dy*pos/segLen));
IntPoint scanPoint(long(c2.X + scanDistance*cos(minFi + distance*(maxFi-minFi)/interPathLen)),
long(c2.Y + scanDistance*sin(minFi + distance*(maxFi-minFi)/interPathLen)));
IntPoint intersC2(segPoint.X,segPoint.Y);
IntPoint intersC1(segPoint.X,segPoint.Y);
@@ -704,11 +705,11 @@ namespace AdaptivePath {
// there should be intersection with C2
if(Line2CircleIntersect(c2,toolRadiusScaled,segPoint,scanPoint,inters)) {
if(inters.size()>1) {
intersC2.X = inters[1].X;
intersC2.Y = inters[1].Y;
intersC2.X = long(inters[1].X);
intersC2.Y = long(inters[1].Y);
} else {
intersC2.X = inters[0].X;
intersC2.Y = inters[0].Y;
intersC2.X = long(inters[0].X);
intersC2.Y = long(inters[0].Y);
}
} else {
pthToSubtract.push_back(segPoint);
@@ -716,11 +717,11 @@ namespace AdaptivePath {
if(Line2CircleIntersect(c1,toolRadiusScaled,segPoint,scanPoint,inters)) {
if(inters.size()>1) {
intersC1.X = inters[1].X;
intersC1.Y = inters[1].Y;
intersC1.X = long(inters[1].X);
intersC1.Y = long(inters[1].Y);
} else {
intersC1.X = inters[0].X;
intersC1.Y = inters[0].Y;
intersC1.X = long(inters[0].X);
intersC1.Y = long(inters[0].Y);
}
if(DistanceSqrd(segPoint,intersC2)<DistanceSqrd(segPoint,intersC1)) {
pthToSubtract.push_back(intersC2);
@@ -787,8 +788,8 @@ namespace AdaptivePath {
if(tolerance>0.2) tolerance=0.2;
scaleFactor = RESOLUTION_FACTOR/tolerance;
toolRadiusScaled = toolDiameter*scaleFactor/2;
bbox_size =toolDiameter*scaleFactor;
toolRadiusScaled = long(toolDiameter*scaleFactor/2);
bbox_size =long(toolDiameter*scaleFactor);
progressCallback = &progressCallbackFn;
lastProgressTime=clock();
stopProcessing=false;
@@ -796,8 +797,8 @@ namespace AdaptivePath {
if(helixRampDiameter>toolDiameter) helixRampDiameter = toolDiameter;
if(helixRampDiameter<toolDiameter/8) helixRampDiameter = toolDiameter/8;
helixRampRadiusScaled=helixRampDiameter*scaleFactor/2;
finishPassOffsetScaled=tolerance*scaleFactor/2;
helixRampRadiusScaled=long(helixRampDiameter*scaleFactor/2);
finishPassOffsetScaled=long(tolerance*scaleFactor/2);
ClipperOffset clipof;
@@ -833,7 +834,7 @@ namespace AdaptivePath {
Path cpth;
for(size_t j=0;j<paths[i].size();j++) {
std::pair<double,double> pt = paths[i][j];
cpth.push_back(IntPoint(pt.first*scaleFactor,pt.second*scaleFactor));
cpth.push_back(IntPoint(long(pt.first*scaleFactor),long(pt.second*scaleFactor)));
}
inputPaths.push_back(cpth);
}
@@ -1042,7 +1043,7 @@ namespace AdaptivePath {
if(output.AdaptivePaths.size()>0 && output.AdaptivePaths.back().second.size()>0) { // if there is a previous path
auto & lastTPath = output.AdaptivePaths.back();
auto & lastTPoint = lastTPath.second.back();
IntPoint lastPoint(lastTPoint.first*scaleFactor,lastTPoint.second*scaleFactor);
IntPoint lastPoint(long(lastTPoint.first*scaleFactor),long(lastTPoint.second*scaleFactor));
bool clear = CheckCollision(lastPoint,nextPoint,cleared);
// add linking move
TPath linkPath;
@@ -1111,7 +1112,7 @@ namespace AdaptivePath {
output.HelixCenterPoint.first = double(entryPoint.X)/scaleFactor;
output.HelixCenterPoint.second =double(entryPoint.Y)/scaleFactor;
long stepScaled = RESOLUTION_FACTOR;
long stepScaled = long(RESOLUTION_FACTOR);
IntPoint engagePoint;
IntPoint toolPos;
@@ -1181,7 +1182,7 @@ namespace AdaptivePath {
progressPaths.push_back(TPath());
}
angle = M_PI_4; // initial pass angle
angle = M_PI/4; // initial pass angle
bool reachedBoundary = false;
double cumulativeCutArea=0;
// init gyro
@@ -1212,20 +1213,20 @@ namespace AdaptivePath {
// set the step size
double slowDownDistance = max(double(toolRadiusScaled)/4,RESOLUTION_FACTOR*8);
if(distanceToBoundary<slowDownDistance || distanceToEngage<slowDownDistance) {
stepScaled = RESOLUTION_FACTOR;
stepScaled = long(RESOLUTION_FACTOR);
} else if(fabs(angle)>1e-5) {
stepScaled = RESOLUTION_FACTOR/fabs(angle);
stepScaled = long(RESOLUTION_FACTOR/fabs(angle));
} else {
stepScaled = RESOLUTION_FACTOR*4 ;
stepScaled = long(RESOLUTION_FACTOR*4);
}
// clamp the step size - for stability
if(stepScaled>min(double(toolRadiusScaled/4), double(RESOLUTION_FACTOR*8)))
stepScaled=min(double(toolRadiusScaled/4), double(RESOLUTION_FACTOR*8));
if(stepScaled<RESOLUTION_FACTOR) stepScaled=RESOLUTION_FACTOR;
if(stepScaled>min(long(toolRadiusScaled/4), long(RESOLUTION_FACTOR*8)))
stepScaled=min(long(toolRadiusScaled/4), long(RESOLUTION_FACTOR*8));
if(stepScaled<RESOLUTION_FACTOR) stepScaled=long(RESOLUTION_FACTOR);
//stepScaled=RESOLUTION_FACTOR;
@@ -1251,7 +1252,7 @@ namespace AdaptivePath {
angle=interp.clampAngle(angle);
newToolDir = rotate(toolDir,angle);
newToolPos = IntPoint(toolPos.X + newToolDir.X * stepScaled, toolPos.Y + newToolDir.Y * stepScaled);
newToolPos = IntPoint(long(toolPos.X + newToolDir.X * stepScaled), long(toolPos.Y + newToolDir.Y * stepScaled));
area = CalcCutArea(clip, toolPos,newToolPos, cleared);
areaPD = area/double(stepScaled); // area per distance

View File

@@ -1,10 +1,25 @@
#include "clipper.hpp"
#include <vector>
#include <list>
#include <time.h>
#ifndef ADAPTIVE_HPP
#define ADAPTIVE_HPP
#ifndef __DBL_MAX__
#define __DBL_MAX__ 1.7976931348623158e+308
#endif
#ifndef __LONG_MAX__
#define __LONG_MAX__ 2147483647
#endif
#ifndef M_PI
#define M_PI 3.141592653589793238
#endif
//#define DEV_MODE
#define NTOL 1.0e-7 // numeric tolerance