Commit bfc19a03 authored by raffaele's avatar raffaele

reorganized source code and Makefile with test target

parent 25c95b4d
*/*.o
*.o
point-polygon-test
CC=gcc
CFLAGS=`pkg-config --cflags --libs check glib-2.0 json-glib-1.0`
run-test: clean
gcc -Wall test/point-polygon-test.c -o point-polygon-test $(CFLAGS)
test: point-polygon-test
./point-polygon-test
compile-debug: clean
gcc -Wall -g test/point-polygon-test.c -o point-polygon-test $(CFLAGS)
point-polygon-test: point-polygon-test.o point-polygon.o
$(CC) -Wall point-polygon-test.o point-polygon.o -o point-polygon-test $(CFLAGS)
point-polygon-test.o: test/point-polygon-test.c
$(CC) -Wall $(CFLAGS) -g -c test/point-polygon-test.c
point-polygon.o: point-polygon.c point-polygon.h
$(CC) -Wall $(CFLAGS) -g -c point-polygon.c
clean:
rm -f point-polygon-test
rm -f *.o point-polygon-test
......@@ -22,10 +22,7 @@
#include "point-polygon.h"
/*
* Return the abscissa projection value of point p into segment with vertext v1 and v2.
*/
static double abscissa_projection(
double abscissa_projection(
double p_y,
double v1_x,
double v1_y,
......@@ -37,14 +34,7 @@ static double abscissa_projection(
/(v2_y - v1_y));
}
/*
* Return the quandrant of point p(x2, y2) relative to p(x2, y2), -1 if the are the same.
* 0 if [0,pi/2)
* 1 if [pi/2,pi)
* 2 if [pi,3pi/4)
* 3 if [3pi/4,2pi)
*/
static int quadrant(double x1, double y1, double x2, double y2)
int quadrant(double x1, double y1, double x2, double y2)
{
if(x2 > x1 && y2 >= y1){
return 0;
......@@ -59,11 +49,7 @@ static int quadrant(double x1, double y1, double x2, double y2)
}
}
/*
* Calculate the integer counterclockwise movement in quadrants from last-point to next-point.
* Return 9 if p is on the border of the segment with last-point and next-point as vertex.
*/
static int calculate_increment(
int calculate_increment(
double p_x,
double p_y,
double last_x,
......@@ -161,10 +147,6 @@ static int is_inside_or_border_rec (
);
}
/*
* Tell if point p is inside or in the border of polygon. The coordinates of the first element
* and the last element of the polygon must be equal.
*/
int is_inside_or_border(
double p_x,
double p_y,
......
......@@ -22,6 +22,41 @@
#include <stddef.h>
/*
* Return the abscissa projection value of point p into segment with vertext v1 and v2.
*/
double abscissa_projection(
double p_y,
double v1_x,
double v1_y,
double v2_x,
double v2_y);
/*
* Return the quandrant of point p(x2, y2) relative to p(x2, y2), -1 if the are the same.
* 0 if [0,pi/2)
* 1 if [pi/2,pi)
* 2 if [pi,3pi/4)
* 3 if [3pi/4,2pi)
*/
int quadrant(double x1, double y1, double x2, double y2);
/*
* Calculate the integer counterclockwise movement in quadrants from last-point to next-point.
* Return 9 if p is on the border of the segment with last-point and next-point as vertex.
*/
int calculate_increment(
double p_x,
double p_y,
double last_x,
double last_y,
double next_x,
double next_y);
/*
* Tell if point p is inside or in the border of polygon. The coordinates of the first element
* and the last element of the polygon must be equal.
*/
int is_inside_or_border(
double p_x,
double p_y,
......
......@@ -24,7 +24,7 @@
#include <check.h>
#include <glib-object.h>
#include <json-glib/json-glib.h>
#include "../src/point-polygon.c"
#include "../point-polygon.h"
START_TEST(quadrant_test)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment