LINEVECTOR *read_linevector (char *filename, short print) {
	/*!
	 * \author Emanuele Cordano
	 * \date May 2009
	 *
	 *\param filename (char *) - name of the file where to read line_information
	 *\param print (short)
	 *
	 *
	 *\brief It creates and reads a linevector from the following options:
	 *\brief index{1}
	 *  FILE CONTAINIG NECESSARY INFORMATION FOR LINES
			x    y    line_index    lenght2d    x_P1    y_P1    x_P2   y_P2

			1: double matrix lines information  {55550,8}
	 */

	FILE *fd;
	DOUBLEMATRIX *ldata;
	LINEVECTOR *lines;
	POINT *P1,*P2;
	long index,j,ja;

	int ix=1; /*! x coordinate of the middle point */
	int iy=ix+1; /*! y coordinate of the midddele point */
	int iline_index=iy+1; /*! iline_index of the line */
	int ilength2d=iline_index+1; /*! lenght of the line */
	int iP1_x=ilength2d+1; /*! P1 x coordinate */
	int iP1_y=iP1_x+1; /*! P1 y coordinate */
	int iP2_x=iP1_y+1; /*! P2 x coordinate */
	int iP2_y=iP2_x+1; /*! P2 y coordinate */
	int indata=iP2_y; /* number of data */

	fd=t_fopen(filename,"r");
	index=(long)read_index(fd,no_PRINT);
	ldata=read_doublematrix(fd,"a",no_PRINT);
	if (ldata->nch!=indata) printf("Warning in read_linevector: inconstancy on number of columns (data) : %ld %d \n",ldata->nch,indata);
	//if (ldata->nrh!=index)  printf("Error in read_linevector: inconstancy on number of lines : %ld %ld",ldata->nrh,index);
	lines=new_linevector(ldata->nrh);
	for (j=lines->nl;j<=lines->nh;j++) {
		ja=(long)ldata->element[j][iline_index];
		if (j!=ja) printf("Error in read_linevector (line %ld of %ld): inconstancy on line index : %ld %ld \n",j,lines->nh,j,ja);
		P1=new_point(j-1,ldata->element[j][iP1_x],ldata->element[j][iP1_y],NULL_ELEVATION);
		P2=new_point(j,ldata->element[j][iP2_x],ldata->element[j][iP2_y],NULL_ELEVATION);
		lines->element[j]=new_line_from_points(j,P1,P2);
		free_point(P1);
		free_point(P2);

	}

	free_doublematrix(ldata);
	if (print==1) printf("Function read_linevector (number of lines %ld) was successfully executed!! \n",lines->nh);

	return lines;

}
LINE *get_line(DOUBLEVECTOR *vertex_x_coord, DOUBLEVECTOR *vertex_y_coord, long line_index, char *number_strings, short print){
	/*!
	 * \param vertex_x_coord - (DOUBLEVECTOR *) vector of x coordinates
	 * \param vertex_y_coord - (DOUBLEVECTOR *) vector of y coordinates
	 *
	 * \param line_index     - (long int) index of the line
	 * \param number_string  - (char *) string containing the number of two vertex points
	 * \param print          - (short) if activated it prints error or warning messages
	 * \author Emanuele Cordano
	 * \date November 2008
	 *
	 */
	POINT *P1, *P2;
	//long index1,index2,
	long j;
	LONGVECTOR *lvertices;
	LINE *li;

	lvertices=read_longarray_from_string(number_strings,DELIMITERS,MAX_POINTS,0);

    if (lvertices->nh<2) printf("Error:: line %s (%ld) cannot be created, there no vertices!!\n",number_strings,line_index);
    for (j=lvertices->nl;j<=2;j++){
    	if ((lvertices->element[j]>vertex_x_coord->nh) || (lvertices->element[j]>vertex_y_coord->nh)) {
    		printf ("Error:: line %s (%ld) cannot be created, point %ld has no coordinates or no atributes!!\n",number_strings,line_index,j);
    	}
    }

    j=1;
    P1=new_point(lvertices->element[j],vertex_x_coord->element[lvertices->element[j]],vertex_y_coord->element[lvertices->element[j]],NO_ELEVATION);

    j=2;
    P2=new_point(lvertices->element[j],vertex_x_coord->element[lvertices->element[j]],vertex_y_coord->element[lvertices->element[j]],NO_ELEVATION);

    if (print==1) printf ("The two vertices %ld (x=%lf,y=%lf) and %ld (x=%lf,y=%lf) of line %s (%ld) were succesfully created!!\n",P1->index,P1->x,P1->y,P2->index,P2->x,P2->y,number_strings,line_index);

    li=new_line_from_points(line_index, P1,P2);


    free_point(P1);
    free_point(P2);
    free_longvector(lvertices);


    return li;



}
Exemple #3
0
int main()
{
	point_t *p1, *p2, *mid_p;
	double dist;

	p1 = new_point(1,2);
	p2 = new_point(3,4);

	print_point(p1);
	print_point(p2);

	dist = distance_between(p1, p2);
	printf("Distance between p1 and p2: %f\n", dist);

	mid_p = midpoint(p1, p2);
	print_point(mid_p);

	free_point(&p1);
	free_point(&p2);
	return 0;
}
int main(int argc, char *argv[]) {
    void *myso = dlopen("./libpoints.dylib", RTLD_NOW);
    
    _make_point *make_point = dlsym(myso, "make_point");
    _free_point *free_point = dlsym(myso, "free_point");

    _get_distance *get_distance = dlsym(myso, "get_distance");


    struct Point*  a = make_point(10,10);
    struct Point*  b = make_point(20,20);
    double d = get_distance(a,b);
    printf("distance: %f\n", d);

    free_point(a);
    free_point(b);

    dlclose(myso);

    return 0;

}
POLYGON *get_polygon(long index,double x, double y, double z, char *edge_index_string,LINEVECTOR *all_lines, short print) {
	/*!
	 * \author Emanuele Cordano
	 * \date November 2008
	 *
	 * \param index - (long) index of the centroid and the polygons
	 * \param x  - (double) x of the centroid
	 * \param y  - (double) y of the centroid
	 * \param z  - (double) z of the centroid
	 *
	 * \param edge_line_index - (char *) string containing the edge indices
	 *
	 * \param all_lines       -  (LINEVECTOR *) vector of all lines
	 * \param print   - (short)
	 *
	 * \return a polygon (Attributes are not allocated!!)
	 *
	 */

	LINEVECTOR *edges;
	POLYGON *PO;
	LONGVECTOR *ledges;
	POINT *centroid;

	centroid=new_point(index,x,y,z);
	ledges=read_longarray_from_string(edge_index_string,DELIMITERS,MAX_POINTS,0);
	edges=extract_linvector_from_linevector(ledges,all_lines);
	PO=new_polygon_from_a_linevector(edges,centroid);

	free_point(centroid);
	free_longvector(ledges);
	free_linevector(edges);

	return PO;


}