/* $Id$ * * Copyright (c) 2010 Anders Wallin (anders.e.e.wallin "at" gmail.com). * * This file is part of OpenCAMlib * (see https://github.com/aewallin/opencamlib). * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 2.1 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include #include // for fabs() #include #include "numeric.hpp" #include "point.hpp" #ifdef _WIN32 // Windows platform problem: error C3861: 'isnan': identifier not found, use the Boost version instead #include // isnan #endif namespace ocl { #define TOLERANCE 0.0000001 double xyVectorToDiangle(double x, double y) { double diangle; if (y >= 0) diangle = (x >= 0 ? y/(x+y) : 1-x/(-x+y)); else diangle = (x < 0 ? 2-y/(-x-y) : 3+x/(x-y)); #ifdef _WIN32 if ((boost::math::isnan)(diangle)) { // Use the Boost version #else if (std::isnan(diangle) ) { // Use the std version #endif std::cout << "numeric::xyVectorToDiangle() error (x,y)= ("<< x << " , " << y << " ) and diangle=" << diangle << "\n"; assert(0); } return diangle; } double sign(double x) { if (x<0.0) return -1; else return 1; } bool isPositive(double x) { if (x > 0.0 ) return true; else return false; } bool isNegative(double x) { if ( x < 0.0 ) return true; else return false; } bool isZero_tol(double x) { if (fabs(x) // [ (p2-p1).x -(p4-p3).x ] [ v ] = [ (p3-p1).x ] // [ (p2-p1).y -(p4-p3).y ] [ t ] = [ (p3-p1).y ] return two_by_two_solver(p2.x - p1.x, -(p4.x - p3.x), p2.y - p1.y, -(p4.y - p3.y), (p3.x - p1.x), p3.y - p1.y, v, t); } } // end namespace // end file numeric.cpp