diff options
Diffstat (limited to 'geometry.c')
-rw-r--r-- | geometry.c | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -44,7 +44,6 @@ double vertexDistance(const VERTEX *v1, const VERTEX *v2) { return sqrt(vertexDistanceSquare(v1, v2)); } - int vertexInRect(const VERTEX *v, const RECTANGLE *rect) { int ret = EDGE_NONE; @@ -133,6 +132,26 @@ gboolean vertexInPolygon(const VERTEX *v, const POLYGON *p) { return (d == 0) ? FALSE : TRUE; } +double polygonPerimeter(const POLYGON *p) { + int i; + double d = 0.0; + + for(i = 0; i < p->nVertices; i++) + d += vertexDistance(&p->vertices[i], &p->vertices[(i+1)%p->nVertices]); + + return d; +} + +double polygonArea(const POLYGON *p) { + int i; + double d = 0.0; + + for(i = 0; i < p->nVertices; i++) + d += (p->vertices[(i+1)%p->nVertices].x+p->vertices[i].x)*(p->vertices[(i+1)%p->nVertices].y-p->vertices[i].y); + + return d/2; +} + int lineIntersection(const LINE *la, const LINE *lb, VERTEX *v) { double xa1 = la->v1.x, ya1 = la->v1.y; double xa2 = la->v2.x, ya2 = la->v2.y; |