Pasar a C

Pasar a C

Postby Manuel Valdenebro » Tue Dec 24, 2013 9:45 am

Felices fiestas para todos,

Algun alma caritativa podría pasarme esta función a "C" con Pragma Begindump. Lo he intentado yo solito, pero no funciona.


int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy)
{
int i, j, c = 0;
for (i = 0, j = nvert-1; i < nvert; j = i++) {
if ( ((verty[i]>testy) != (verty[j]>testy)) &&
(testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
c = !c;
}
return c;
}


Muchas gracias
Un saludo

Manuel
User avatar
Manuel Valdenebro
 
Posts: 706
Joined: Thu Oct 06, 2005 9:57 pm
Location: Málaga-España

Re: Pasar a C

Postby Antonio Linares » Tue Dec 24, 2013 1:39 pm

Manuel,

Que error te aparece ? Aqui compila bien
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Pasar a C

Postby Manuel Valdenebro » Tue Dec 24, 2013 4:08 pm

Antonio Linares wrote:Manuel,

Que error te aparece ? Aqui compila bien


Gracias Antonio por contestar. Yo tengo puesto este código:
#pragma BEGINDUMP

#include <windows.h>
#include <hbapi.h>

HB_FUNC( PNPOLY )

int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy) // AQUI DA EL ERROR
{
int i, j, c = 0;
for (i = 0, j = nvert-1; i < nvert; j = i++) {
if ( ((verty[i]>testy) != (verty[j]>testy)) &&
(testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
c = !c;
}
return c;
}

#pragma ENDDUMP


Seguro que el "añadido" para que funciones en xHarbour no es correcto. El errorlo da al compilar en la linea que señalo: Error 2141 Declaration Syntax Error

Muchas gracias y feliz Navidad
Un saludo

Manuel
User avatar
Manuel Valdenebro
 
Posts: 706
Joined: Thu Oct 06, 2005 9:57 pm
Location: Málaga-España

Re: Pasar a C

Postby carlos vargas » Tue Dec 24, 2013 11:51 pm

Code: Select all  Expand view


function Main()
?PNPPOLY(/*aca van parametros*/)
return nil

#pragma BEGINDUMP

#include <windows.h>
#include <hbapi.h>

HB_FUNC( PNPOLY )
{
 int iReturn;

 iReturn = pnpoly( /*aca debes poner los parameros de la funcion, desconosco si los pasaras desde prg o c*/ );
}

int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy)
{
  int i, j, c = 0;
  for (i = 0, j = nvert-1; i < nvert; j = i++)
  {
     if ( ((verty[i]>testy) != (verty[j]>testy)) && (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
     {
        c = !c;
      }
   }
}
 
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1683
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: Pasar a C

Postby Manuel Valdenebro » Wed Dec 25, 2013 6:20 am

Gracias Carlos por tu ayuda.

Los parámetros los pasaría desde un prg, logicamente con los mismos parámetros que tiene la función en C.

pnpoly ( nVert, aVertX, aVertY, nTestX, nTestY) donde nvert es un número entero, aVertY y AvertX array y nTestX - nTestY número con 6 decimales.

He incluido los parámetros en el código reformado opor tí pero me sigue dando errores. ¿tengo que ponerle el tipo?

{
int iReturn;

iReturn = pnpoly( nVert, vertx, verty, testx, testy );
}


La función debería devolver el valor de C. ¿No debería ponerse C en lugar de iReturn?

Muchas gracias de nuevo.
Un saludo

Manuel
User avatar
Manuel Valdenebro
 
Posts: 706
Joined: Thu Oct 06, 2005 9:57 pm
Location: Málaga-España

Re: Pasar a C

Postby Antonio Linares » Wed Dec 25, 2013 10:21 am

Manuel,

Prueba asi:

Code: Select all  Expand view


function Main()
? PNPPOLY(/*aca van parametros*/)
return nil

#pragma BEGINDUMP

#include <windows.h>
#include <hbapi.h>

int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy)
{
  int i, j, c = 0;
  for (i = 0, j = nvert-1; i < nvert; j = i++)
  {
     if ( ((verty[i]>testy) != (verty[j]>testy)) && (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
     {
        c = !c;
      }
   }
}

HB_FUNC( PNPOLY )
{
   float vertx = hb_parnd( 2 );
   float verty = hb_parnd( 3 );

   hb_retnl( pnpoly( hb_parnl( 1 ), &vertx, &verty, hb_parnd( 4 ), hb_parnd( 5 ) ) );
}

#pragma ENDDUMP

 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Pasar a C

Postby Manuel Valdenebro » Wed Dec 25, 2013 3:56 pm

Ahora ha funcionado.

Muchiiiiiiiisimas gracias
Un saludo

Manuel
User avatar
Manuel Valdenebro
 
Posts: 706
Joined: Thu Oct 06, 2005 9:57 pm
Location: Málaga-España


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 60 guests