Include :

- portata versione richiesta alla chiave per le librerie a 19
- eliminati Complex e sostituiti da std::complex<double>
- aggiunta gestione parametri std::complex<double> in lua.
This commit is contained in:
Dario Sassi
2018-08-08 11:10:48 +00:00
parent 2239ec8e6a
commit c59482460e
6 changed files with 125 additions and 362 deletions
-2
View File
@@ -22,8 +22,6 @@
#include "/EgtDev/Include/EGkSelection.h" #include "/EgtDev/Include/EGkSelection.h"
#include "/EgtDev/Include/EgnLuaAux.h" #include "/EgtDev/Include/EgnLuaAux.h"
using namespace std ;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
inline bool inline bool
LuaGetParam( lua_State* L, int nInd, Vector3d& vtPar) LuaGetParam( lua_State* L, int nInd, Vector3d& vtPar)
-348
View File
@@ -1,348 +0,0 @@
//----------------------------------------------------------------------------
// EgalTech 2013-2014
//----------------------------------------------------------------------------
// File : ENkComplex.h Data : 08.01.14 Versione : 1.5a1
// Contenuto : Dichiarazione classe dei numeri complessi.
//
//
//
// Modifiche : 08.01.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
#pragma once
//----------------------- Macro per import/export ----------------------------
#undef ENK_EXPORT
#if defined( I_AM_ENK) // da definirsi solo nella DLL
#define ENK_EXPORT __declspec( dllexport)
#else
#define ENK_EXPORT __declspec( dllimport)
#endif
//---------------------------Include------------------------------------------
#include <math.h>
#include <float.h>
//---------------------------- Class Complex ---------------------------------
class ENK_EXPORT Complex
{
public :
Complex( double x, double y) : re( x), im( x) {}
Complex( double x) : re( x), im( 0) {}
Complex( void) : re( 0), im( 0) {}
void Set( double x, double y) { re = x ; im = y ; }
public :
Complex operator +=( double dVal) ;
Complex operator +=( Complex& cVal) ;
Complex operator -=( double dVal) ;
Complex operator -=( Complex& cVal) ;
Complex operator *=( double dVal) ;
Complex operator *=( Complex& cVal) ;
Complex operator /=( double dVal) ;
Complex operator /=( Complex& cVal) ;
Complex operator >>=( int n) ;
Complex operator <<=( int n) ;
public :
double re ;
double im ;
} ;
//------------------------------ Functions -----------------------------------
ENK_EXPORT Complex sqrt( Complex& cVal) ;
ENK_EXPORT Complex log( Complex& cVal) ;
ENK_EXPORT Complex exp( Complex & cVal) ;
ENK_EXPORT Complex cosh( Complex& cVal) ;
ENK_EXPORT Complex sinh( Complex& cVal) ;
ENK_EXPORT Complex tanh( Complex& cVal) ;
ENK_EXPORT Complex cos( Complex& cVal) ;
ENK_EXPORT Complex isin( Complex& cVal) ;
ENK_EXPORT Complex sin( Complex& cVal) ;
ENK_EXPORT Complex itan( Complex& cVal) ;
ENK_EXPORT Complex tan( Complex& cVal) ;
ENK_EXPORT Complex acosh( Complex& cVal) ;
ENK_EXPORT Complex asinh( Complex& cVal) ;
ENK_EXPORT Complex atanh( Complex& cVal) ;
ENK_EXPORT Complex acos( Complex& cVal) ;
ENK_EXPORT Complex asin( Complex& cVal) ;
ENK_EXPORT Complex atan( Complex& cVal) ;
//------------------------------ Functions inline -----------------------------------
// !z and !!z to use as boolean
inline int
operator !( Complex& cVal)
{
return ( ( cVal.re || cVal.im) ? 0 : 1) ;
}
//----------------------------------------------------------------------------
// ~z = z
inline Complex
operator ~( Complex& cVal)
{
Complex cRes ;
cRes.re = cVal.re ;
cRes.im = - cVal.im ;
return cRes ;
}
//----------------------------------------------------------------------------
inline double
Re( Complex& cVal)
{
return cVal.re ;
}
//----------------------------------------------------------------------------
inline double
Im( Complex& cVal)
{
return cVal.im ;
}
//----------------------------------------------------------------------------
// negation
inline Complex
operator -( Complex& cVal)
{
Complex cRes ;
cRes.re = - cVal.re ;
cRes.im = - cVal.im ;
return cRes ;
}
//----------------------------------------------------------------------------
inline Complex
operator -( Complex& cVal1, Complex& cVal2)
{
Complex cRes ;
cRes.re = cVal1.re - cVal2.re ;
cRes.im = cVal1.im - cVal2.im ;
return cRes ;
}
//----------------------------------------------------------------------------
inline Complex
operator -( double dVal1, Complex& cVal2)
{
Complex cRes ;
cRes.re = dVal1 - cVal2.re ;
cRes.im = - cVal2.im ;
return cRes ;
}
//----------------------------------------------------------------------------
inline Complex
operator -( Complex& cVal1, double dVal2)
{
Complex cRes ;
cRes.re = cVal1.re - dVal2 ;
cRes.im = cVal1.im ;
return cRes ;
}
//----------------------------------------------------------------------------
// addition
inline Complex
operator +( Complex& cVal)
{
return cVal ;
}
//----------------------------------------------------------------------------
inline Complex
operator +( double dVal1, Complex& cVal2)
{
Complex cRes ;
cRes.re = dVal1 + cVal2.re ;
cRes.im = cVal2.im ;
return cRes ;
}
//----------------------------------------------------------------------------
inline Complex
operator +( Complex& cVal1, double dVal2)
{
Complex cRes ;
cRes.re = cVal1.re + dVal2 ;
cRes.im = cVal1.im ;
return cRes ;
}
//----------------------------------------------------------------------------
inline Complex
operator +( Complex& cVal1, Complex& cVal2)
{
Complex cRes ;
cRes.re = cVal1.re + cVal2.re ;
cRes.im = cVal1.im + cVal2.im ;
return cRes ;
}
//----------------------------------------------------------------------------
// multiplication
inline Complex
operator *( Complex& cVal1, Complex& cVal2)
{
Complex cRes ;
cRes.re = cVal1.re * cVal2.re - cVal1.im * cVal2.im ;
cRes.im = cVal1.re * cVal2.im + cVal1.im * cVal2.re ;
return cRes ;
}
//----------------------------------------------------------------------------
inline Complex
operator *( double dVal1, Complex& cVal2)
{
Complex cRes ;
cRes.re = dVal1 * cVal2.re ;
cRes.im = dVal1 * cVal2.im ;
return cRes ;
}
//----------------------------------------------------------------------------
inline Complex
operator *( Complex& cVal1, double dVal2)
{
Complex cRes ;
cRes.re = cVal1.re * dVal2 ;
cRes.im = cVal1.im * dVal2 ;
return cRes ;
}
//----------------------------------------------------------------------------
// 2
// m2(z) = |z|...(used by / )
inline double
m2( Complex& cVal)
{
return ( cVal.re * cVal.re + cVal.im * cVal.im) ;
}
//----------------------------------------------------------------------------
// mod(z) = |z|..............
inline double
mod( Complex& cVal)
{
if ( fabs( cVal.im) < DBL_EPSILON)
return fabs( cVal.re) ;
if ( fabs( cVal.re) < DBL_EPSILON)
return fabs( cVal.im) ;
return sqrt( m2( cVal)) ;
}
//----------------------------------------------------------------------------
inline Complex
operator /( Complex& cVal1, double dVal2)
{
double dInv ;
Complex cRes ;
dInv = 1.0 / dVal2 ;
cRes.re = cVal1.re * dInv ;
cRes.im = cVal1.im * dInv ;
return cRes ;
}
//----------------------------------------------------------------------------
// inversion
inline Complex
inv( Complex& cVal)
{
return ( ~ cVal / m2( cVal)) ;
}
//----------------------------------------------------------------------------
// division as mult for inv
inline Complex
operator /( Complex& cVal1, Complex& cVal2)
{
if ( fabs( cVal2.im) < DBL_EPSILON)
return ( cVal1 / cVal2.re) ;
return ( cVal1 * inv( cVal2)) ;
}
//----------------------------------------------------------------------------
// fast multiply by +i
inline Complex
itimes( Complex& cVal)
{
Complex cRes ;
cRes.re = - cVal.im ;
cRes.im = cVal.re ;
return cRes ;
}
//----------------------------------------------------------------------------
// right shift
inline Complex
operator >>( Complex& cVal, int n)
{
Complex cRes ;
cRes.re = ldexp( cVal.re, -n) ;
cRes.im = ldexp( cVal.im, -n) ;
return cRes ;
}
//----------------------------------------------------------------------------
// left shift
inline Complex
operator <<( Complex& cVal, int n)
{
Complex cRes ;
cRes.re = ldexp( cVal.re, +n) ;
cRes.im = ldexp( cVal.im, +n) ;
return cRes ;
}
+7 -7
View File
@@ -1,23 +1,23 @@
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// EgalTech 2013-2014 // EgalTech 2013-2018
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// File : ENkCplxCollection.h Data : 02.04.14 Versione : 1.5d1 // File : ENkCplxCollection.h Data : 07.08.18 Versione : 1.9h1
// Contenuto : Raccolte di oggetti numerici complessi. // Contenuto : Raccolte di oggetti numerici complessi.
// //
// //
// //
// Modifiche : 17.12.13 DS Creazione modulo. // Modifiche : 17.12.13 DS Creazione modulo.
// // 07.08.18 DS passaggio ai complex di STL.
// //
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
#pragma once #pragma once
#include "/EgtDev/Include/EgtNumCollection.h" #include "/EgtDev/Include/EgtNumCollection.h"
#include "/EgtDev/Include/ENkComplex.h" #include <complex>
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// Raccolte di Complex // Raccolte di complex
typedef std::vector<Complex> CPLXVECTOR ; // vettore di Complex typedef std::vector<std::complex<double>> CPLXVECTOR ; // vettore di complex
typedef std::list<Complex> CPLXLIST ; // lista di Complex typedef std::list<std::complex<double>> CPLXLIST ; // lista di complex
+2 -2
View File
@@ -32,7 +32,7 @@
// vdRoot = vector degli zeri // vdRoot = vector degli zeri
// pnIter = numero di iterazioni // pnIter = numero di iterazioni
// valore di ritorno = numero di zeri trovati // valore di ritorno = numero di zeri trovati
ENK_EXPORT int PolynomialRoots( int nDegree, DBLVECTOR& vdPoly, DBLVECTOR& vdRoot, int* pnIter = NULL) ; ENK_EXPORT int PolynomialRoots( int nDegree, DBLVECTOR& vdPoly, DBLVECTOR& vdRoot, int* pnIter = nullptr) ;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// Calcola gli zeri di un polinomio a coefficienti complessi // Calcola gli zeri di un polinomio a coefficienti complessi
@@ -41,4 +41,4 @@ ENK_EXPORT int PolynomialRoots( int nDegree, DBLVECTOR& vdPoly, DBLVECTOR& vdRoo
// acRoot = array degli zeri // acRoot = array degli zeri
// pnIter = numero di iterazioni // pnIter = numero di iterazioni
// valore di ritorno = numero di zeri trovati // valore di ritorno = numero di zeri trovati
ENK_EXPORT int PolynomialRoots( int nDegree, CPLXVECTOR& vcPoly, CPLXVECTOR& vcRoot, int* pnIter = NULL) ; ENK_EXPORT int PolynomialRoots( int nDegree, CPLXVECTOR& vcPoly, CPLXVECTOR& vcRoot, int* pnIter = nullptr) ;
+112
View File
@@ -0,0 +1,112 @@
//----------------------------------------------------------------------------
// EgalTech 2018-2018
//----------------------------------------------------------------------------
// File : ENmLuaAux.h Data : 07.08.18 Versione : 1.9h1
// Contenuto : Funzioni per gestione parametri generali con LUA.
//
//
//
// Modifiche : 07.08.18 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
#pragma once
#include "/EgtDev/Include/ENkCplxCollection.h"
#include "/EgtDev/Include/EgnLuaAux.h"
//----------------------------------------------------------------------------
inline bool
LuaGetParam( lua_State* L, int nInd, std::complex<double>& cpPar)
{
if ( lua_isnumber( L, nInd)) {
double dVal = lua_tonumber( L, nInd) ;
cpPar = std::complex<double>( dVal, 0.) ;
return true ;
}
double dVal[2] ;
if ( LuaGetParam( L, nInd, dVal)) {
cpPar = std::complex<double>( dVal[0], dVal[1]) ;
return true ;
}
return false ;
}
//----------------------------------------------------------------------------
inline bool
LuaGetParam( lua_State* L, int nInd, CPLXVECTOR& vPar)
{
vPar.clear() ;
std::complex<double> cpVal ;
if ( LuaGetParam( L, nInd, cpVal)) {
vPar.push_back( cpVal) ;
return true ;
}
else if ( lua_istable( L, nInd)) {
// lunghezza della tavola
lua_len( L, nInd) ;
if ( ! lua_isnumber( L, -1))
return false ;
int nLen = int( lua_tointeger( L, -1)) ;
lua_pop( L, 1) ;
vPar.reserve( nLen) ;
for ( int i = 1 ; i <= nLen ; ++ i) {
lua_rawgeti( L, nInd, i) ;
std::complex<double> cpVal ;
if ( ! LuaGetParam( L, -1, cpVal))
return false ;
vPar.push_back( cpVal) ;
lua_pop( L, 1) ;
}
return true ;
}
else
return false ;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
inline bool
LuaSetParam( lua_State* L, const std::complex<double>& cpPar)
{
try {
lua_createtable( L, 2, 0) ;
lua_pushnumber( L, std::real( cpPar)) ;
lua_rawseti( L, -2, 1) ;
lua_pushnumber( L, std::imag( cpPar)) ;
lua_rawseti( L, -2, 2) ;
}
catch( ...) {
return false ;
}
return true ;
}
//-------------------------------------------------------------------------------
inline bool
LuaSetParam( lua_State* L, const CPLXVECTOR& vPar)
{
try {
// recupero dimensione
int nDim = int( vPar.size()) ;
// creo tavola per vSel
lua_createtable( L, nDim, 0) ;
// creo e inserisco tavola per ogni componente
for ( int i = 1 ; i <= nDim ; ++ i) {
// creo tavola
lua_createtable( L, 2, 0) ;
lua_pushnumber( L, std::real( vPar[i-1])) ;
lua_rawseti( L, -2, 1) ;
lua_pushnumber( L, std::imag( vPar[i-1])) ;
lua_rawseti( L, -2, 2) ;
// la metto nel vettore
lua_rawseti( L, -2, i) ;
}
}
catch( ...) {
return false ;
}
return true ;
}
+4 -3
View File
@@ -1,7 +1,7 @@
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// EgalTech 2015-2016 // EgalTech 2015-2018
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// File : EgtKeyCodes.h Data : 11.07.16 Versione : 1.6s3 // File : EgtKeyCodes.h Data : 07.08.18 Versione : 1.9h1
// Contenuto : Costanti per codici di protezione librerie di base. // Contenuto : Costanti per codici di protezione librerie di base.
// //
// //
@@ -10,6 +10,7 @@
// 11.07.16 DS Portata chiave librerie base da 1231 a 207 // 11.07.16 DS Portata chiave librerie base da 1231 a 207
// per liberare bit per i prodotti (207 contenuto in 1231). // per liberare bit per i prodotti (207 contenuto in 1231).
// 18.08.17 DS Portato a 18 KEY_BASELIB_VER. // 18.08.17 DS Portato a 18 KEY_BASELIB_VER.
// 07.08.18 DS Portato a 19 KEY_BASELIB_VER.
// //
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@@ -17,7 +18,7 @@
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
const int KEY_BASELIB_PROD = 207 ; const int KEY_BASELIB_PROD = 207 ;
const int KEY_BASELIB_VER = 18 ; const int KEY_BASELIB_VER = 19 ;
const int KEY_BASELIB_LEV = 1 ; const int KEY_BASELIB_LEV = 1 ;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------