mirror of
https://git.osgeo.org/gitea/postgis/postgis
synced 2024-10-24 17:12:35 +00:00
Related to #1553. Add missing free in cu_surface cunit to be valgrind clean. As TGEOM was not used as storage serialization, i purely remove TGEOM for now, and kept only the TIN/POLYHEDRALSURFACE lwgeom expression (will see in future if we really need to have a 3D topological storage PostGIS side)
git-svn-id: http://svn.osgeo.org/postgis/trunk@11205 b70326c6-7e19-0410-871a-916f4a2858ee
This commit is contained in:
parent
2850a26027
commit
f7c7517971
|
@ -76,7 +76,6 @@ SA_OBJS = \
|
|||
lwgeodetic.o \
|
||||
lwgeodetic_tree.o \
|
||||
lwtree.o \
|
||||
libtgeom.o \
|
||||
lwout_gml.o \
|
||||
lwout_kml.o \
|
||||
lwout_geojson.o \
|
||||
|
@ -99,7 +98,6 @@ LT_OBJS = $(LT_SA_OBJS) $(LT_NM_OBJS)
|
|||
SA_HEADERS = \
|
||||
liblwgeom.h \
|
||||
liblwgeom_internal.h \
|
||||
libtgeom.h \
|
||||
lwgeom_log.h \
|
||||
lwgeom_geos.h
|
||||
|
||||
|
|
|
@ -85,7 +85,9 @@ void triangle_parse(void)
|
|||
geom = lwgeom_from_wkt("TRIANGLE EMPTY", LW_PARSER_CHECK_NONE);
|
||||
CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
|
||||
CU_ASSERT_EQUAL(geom->type, TRIANGLETYPE);
|
||||
CU_ASSERT_STRING_EQUAL("TRIANGLE EMPTY", lwgeom_to_wkt(geom, LW_PARSER_CHECK_NONE, 0, 0));
|
||||
tmp = lwgeom_to_wkt(geom, LW_PARSER_CHECK_NONE, 0, 0);
|
||||
CU_ASSERT_STRING_EQUAL("TRIANGLE EMPTY", tmp);
|
||||
lwfree(tmp);
|
||||
lwgeom_free(geom);
|
||||
|
||||
/* explicit SRID */
|
||||
|
@ -121,6 +123,7 @@ void tin_parse(void)
|
|||
CU_ASSERT_EQUAL(geom->type, TINTYPE);
|
||||
tmp = lwgeom_to_ewkt(geom);
|
||||
CU_ASSERT_STRING_EQUAL("TIN EMPTY", tmp);
|
||||
lwfree(tmp);
|
||||
lwgeom_free(geom);
|
||||
|
||||
/* 2 dims */
|
||||
|
@ -187,7 +190,9 @@ void tin_parse(void)
|
|||
geom = lwgeom_from_wkt("TIN EMPTY", LW_PARSER_CHECK_NONE);
|
||||
CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
|
||||
CU_ASSERT_EQUAL(geom->type, TINTYPE);
|
||||
CU_ASSERT_STRING_EQUAL("TIN EMPTY", lwgeom_to_ewkt(geom));
|
||||
tmp = lwgeom_to_ewkt(geom);
|
||||
CU_ASSERT_STRING_EQUAL("TIN EMPTY", tmp);
|
||||
lwfree(tmp);
|
||||
lwgeom_free(geom);
|
||||
|
||||
/* A simple tetrahedron */
|
||||
|
@ -230,80 +235,6 @@ void tin_parse(void)
|
|||
}
|
||||
|
||||
|
||||
static void
|
||||
check_tgeom(char *ewkt, int type, uint32_t srid, int is_solid)
|
||||
{
|
||||
LWGEOM *g1, *g2;
|
||||
TGEOM *tgeom, *tgeom2;
|
||||
TSERIALIZED *tser;
|
||||
|
||||
g1 = lwgeom_from_wkt(ewkt, LW_PARSER_CHECK_NONE);
|
||||
if (strlen(cu_error_msg)) printf("\n[%s], %s\n", ewkt, cu_error_msg);
|
||||
CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
|
||||
|
||||
if (g1->type != type)
|
||||
printf("\n[%s], TYPE %s\n", ewkt, lwtype_name(g1->type));
|
||||
CU_ASSERT_EQUAL(g1->type, type);
|
||||
tgeom = tgeom_from_lwgeom(g1);
|
||||
|
||||
if (srid != tgeom->srid)
|
||||
printf("\n[%s], srid %i / %i\n", ewkt, srid, tgeom->srid);
|
||||
CU_ASSERT_EQUAL(srid, tgeom->srid);
|
||||
|
||||
if (FLAGS_GET_SOLID(tgeom->flags) != is_solid)
|
||||
printf("\n[%s], solid %i / %i\n", ewkt,
|
||||
FLAGS_GET_SOLID(tgeom->flags), is_solid);
|
||||
CU_ASSERT_EQUAL(FLAGS_GET_SOLID(tgeom->flags), is_solid);
|
||||
|
||||
g2 = lwgeom_from_tgeom(tgeom);
|
||||
if (!lwgeom_same(g1, g2))
|
||||
{
|
||||
printf("\n[%s]\nlwgeom_same I\n", ewkt);
|
||||
printTGEOM(tgeom);
|
||||
if (type == TINTYPE)
|
||||
{
|
||||
printLWTIN((LWTIN *)g1);
|
||||
printLWTIN((LWTIN *)g2);
|
||||
}
|
||||
else
|
||||
{
|
||||
printLWPSURFACE((LWPSURFACE *)g1);
|
||||
printLWPSURFACE((LWPSURFACE *)g2);
|
||||
}
|
||||
}
|
||||
CU_ASSERT(lwgeom_same(g1, g2));
|
||||
|
||||
lwgeom_free(g2);
|
||||
tser = tgeom_serialize(tgeom);
|
||||
tgeom2 = tgeom_deserialize(tser);
|
||||
lwfree(tser);
|
||||
g2 = lwgeom_from_tgeom(tgeom2);
|
||||
tgeom_free(tgeom2);
|
||||
|
||||
if (!lwgeom_same(g1, g2))
|
||||
{
|
||||
printf("\n[%s]\n, lwgeom_same II\n", ewkt);
|
||||
printTGEOM(tgeom);
|
||||
printTGEOM(tgeom2);
|
||||
if (type == TINTYPE)
|
||||
{
|
||||
printLWTIN((LWTIN *)g1);
|
||||
printLWTIN((LWTIN *)g2);
|
||||
}
|
||||
else
|
||||
{
|
||||
printLWPSURFACE((LWPSURFACE *)g1);
|
||||
printLWPSURFACE((LWPSURFACE *)g2);
|
||||
}
|
||||
}
|
||||
CU_ASSERT(lwgeom_same(g1, g2));
|
||||
|
||||
lwgeom_free(g1);
|
||||
lwgeom_free(g2);
|
||||
tgeom_free(tgeom);
|
||||
}
|
||||
|
||||
|
||||
void polyhedralsurface_parse(void)
|
||||
{
|
||||
LWGEOM *geom;
|
||||
|
@ -382,8 +313,12 @@ void polyhedralsurface_parse(void)
|
|||
geom = lwgeom_from_wkt("POLYHEDRALSURFACE EMPTY", LW_PARSER_CHECK_NONE);
|
||||
CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
|
||||
CU_ASSERT_EQUAL(geom->type, POLYHEDRALSURFACETYPE);
|
||||
CU_ASSERT_STRING_EQUAL("010F00000000000000", lwgeom_to_wkb(geom, WKB_HEX | WKB_ISO | WKB_NDR, 0));
|
||||
CU_ASSERT_STRING_EQUAL("POLYHEDRALSURFACE EMPTY", lwgeom_to_ewkt(geom));
|
||||
tmp = lwgeom_to_wkb(geom, WKB_HEX | WKB_ISO | WKB_NDR, 0);
|
||||
CU_ASSERT_STRING_EQUAL("010F00000000000000", tmp);
|
||||
lwfree(tmp);
|
||||
tmp = lwgeom_to_ewkt(geom);
|
||||
CU_ASSERT_STRING_EQUAL("POLYHEDRALSURFACE EMPTY", tmp);
|
||||
lwfree(tmp);
|
||||
lwgeom_free(geom);
|
||||
|
||||
/* A simple tetrahedron */
|
||||
|
@ -436,63 +371,6 @@ void polyhedralsurface_parse(void)
|
|||
lwfree(g);
|
||||
}
|
||||
|
||||
void
|
||||
tin_tgeom(void)
|
||||
{
|
||||
/* EMPTY TIN */
|
||||
check_tgeom("TIN EMPTY", TINTYPE, 0, 0);
|
||||
|
||||
/* 2D a single face */
|
||||
check_tgeom("TIN(((0 0,0 1,1 1,0 0)))", TINTYPE, 0, 0);
|
||||
|
||||
/* 3DM a single face */
|
||||
check_tgeom("TINM(((0 1 2,3 4 5,6 7 8,0 1 2)))", TINTYPE, 0, 0);
|
||||
|
||||
/* 4D a single face */
|
||||
check_tgeom("TIN(((0 1 2 3,4 5 6 7,8 9 10 11,0 1 2 3)))", TINTYPE, 0, 0);
|
||||
|
||||
/* 3D a simple polyhedron */
|
||||
check_tgeom("TIN(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", TINTYPE, 0, 1);
|
||||
|
||||
/* 3D a simple polyhedron with SRID */
|
||||
check_tgeom("SRID=4326;TIN(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", TINTYPE, 4326, 1);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
psurface_tgeom(void)
|
||||
{
|
||||
/* EMPTY POLYHEDRALSURFACE */
|
||||
check_tgeom("POLYHEDRALSURFACE EMPTY", POLYHEDRALSURFACETYPE, 0, 0);
|
||||
|
||||
/* 2D a single face */
|
||||
check_tgeom("POLYHEDRALSURFACE(((0 0,0 1,1 1,0 0)))", POLYHEDRALSURFACETYPE, 0, 0);
|
||||
|
||||
/* 3DM a single face */
|
||||
check_tgeom("POLYHEDRALSURFACEM(((0 1 2,3 4 5,6 7 8,0 1 2)))", POLYHEDRALSURFACETYPE, 0, 0);
|
||||
|
||||
/* 4D a single face */
|
||||
check_tgeom("POLYHEDRALSURFACE(((0 1 2 3,4 5 6 7,8 9 10 11,0 1 2 3)))", POLYHEDRALSURFACETYPE, 0, 0);
|
||||
|
||||
/* 3D a simple polyhedron */
|
||||
check_tgeom("POLYHEDRALSURFACE(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", POLYHEDRALSURFACETYPE, 0, 1);
|
||||
|
||||
/* 3D a simple polyhedron with SRID */
|
||||
check_tgeom("SRID=4326;POLYHEDRALSURFACE(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", POLYHEDRALSURFACETYPE, 4326, 1);
|
||||
|
||||
/* 4D a simple polyhedron */
|
||||
check_tgeom("POLYHEDRALSURFACE(((0 0 0 1,0 0 1 2,0 1 0 3,0 0 0 1)),((0 0 0 4,0 1 0 5,1 0 0 6,0 0 0 4)),((0 0 0 7,1 0 0 8,0 0 1 9,0 0 0 7)),((1 0 0 10,0 1 0 11,0 0 1 12,1 0 0 10)))", POLYHEDRALSURFACETYPE, 0, 0);
|
||||
|
||||
/* 2D single face with one internal ring */
|
||||
check_tgeom("POLYHEDRALSURFACE(((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7)))", POLYHEDRALSURFACETYPE, 0, 0);
|
||||
|
||||
/* 2D single face with two internal rings */
|
||||
check_tgeom("POLYHEDRALSURFACE(((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7),(12 13,14 15,16 17,12 13)))", POLYHEDRALSURFACETYPE, 0, 0);
|
||||
|
||||
/* 4D single face with two internal rings */
|
||||
check_tgeom("POLYHEDRALSURFACE(((0 1 2 3,4 5 6 7,8 9 10 11,0 1 2 3),(12 13 14 15,16 17 18 19,20 21 22 23,12 13 14 15),(16 17 18 19,20 21 22 23,24 25 26 27,16 17 18 19)))", POLYHEDRALSURFACETYPE, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
check_dimension(char *ewkt, int dim)
|
||||
|
@ -522,40 +400,6 @@ surface_dimension(void)
|
|||
}
|
||||
|
||||
|
||||
static void
|
||||
check_perimeter(char *ewkt, int dim, double p)
|
||||
{
|
||||
LWGEOM *geom;
|
||||
TGEOM *tgeom;
|
||||
|
||||
geom = lwgeom_from_wkt(ewkt, LW_PARSER_CHECK_NONE);
|
||||
CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
|
||||
tgeom = tgeom_from_lwgeom(geom);
|
||||
|
||||
if (dim == 2) CU_ASSERT_DOUBLE_EQUAL(tgeom_perimeter2d(tgeom), p, 0.01);
|
||||
if (dim == 3) CU_ASSERT_DOUBLE_EQUAL(tgeom_perimeter(tgeom), p, 0.01);
|
||||
|
||||
tgeom_free(tgeom);
|
||||
lwgeom_free(geom);
|
||||
}
|
||||
|
||||
void
|
||||
surface_perimeter(void)
|
||||
{
|
||||
/* 2D single face */
|
||||
check_perimeter("POLYHEDRALSURFACE(((0 0,0 1,1 1,0 0)))", 2, 3.4142);
|
||||
check_perimeter("TIN(((0 0,0 1,1 1,0 0)))", 2, 3.4142);
|
||||
|
||||
/* 3D single face */
|
||||
check_perimeter("POLYHEDRALSURFACE(((0 0 0,0 0 1,0 1 0,0 0 0)))", 3, 3.4142);
|
||||
check_perimeter("TIN(((0 0 0,0 0 1,0 1 0,0 0 0)))", 3, 3.4142);
|
||||
|
||||
/* 3D Tetrahedron */
|
||||
check_perimeter("POLYHEDRALSURFACE(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", 3, 0.0);
|
||||
check_perimeter("TIN(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", 3, 0.0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Used by test harness to register the tests in this file.
|
||||
*/
|
||||
|
@ -567,10 +411,7 @@ CU_TestInfo surface_tests[] =
|
|||
PG_TEST(triangle_parse),
|
||||
PG_TEST(tin_parse),
|
||||
PG_TEST(polyhedralsurface_parse),
|
||||
PG_TEST(tin_tgeom),
|
||||
PG_TEST(psurface_tgeom),
|
||||
PG_TEST(surface_dimension),
|
||||
PG_TEST(surface_perimeter),
|
||||
CU_TEST_INFO_NULL
|
||||
};
|
||||
CU_SuiteInfo surface_suite = {"surface", NULL, NULL, surface_tests};
|
||||
|
|
|
@ -16,14 +16,10 @@
|
|||
#include "CUnit/Basic.h"
|
||||
|
||||
#include "liblwgeom_internal.h"
|
||||
#include "libtgeom.h"
|
||||
#include "cu_tester.h"
|
||||
|
||||
/* Test functions */
|
||||
void triangle_parse(void);
|
||||
void tin_parse(void);
|
||||
void polyhedralsurface_parse(void);
|
||||
void tin_tgeom(void);
|
||||
void psurface_tgeom(void);
|
||||
void surface_dimension(void);
|
||||
void surface_perimeter(void);
|
||||
|
|
1179
liblwgeom/libtgeom.c
1179
liblwgeom/libtgeom.c
File diff suppressed because it is too large
Load diff
|
@ -1,76 +0,0 @@
|
|||
/**********************************************************************
|
||||
* $Id:$
|
||||
*
|
||||
* PostGIS - Spatial Types for PostgreSQL
|
||||
* http://postgis.refractions.net
|
||||
* Copyright 2010 Olivier Courtin <olivier.courtin@oslandia.com>
|
||||
*
|
||||
* This is free software; you can redistribute and/or modify it under
|
||||
* the terms of the GNU General Public Licence. See the COPYING file.
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef _LIBTGEOM_H
|
||||
#define _LIBTGEOM_H 1
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* TSERIALIZED (mostly inspired by GSERIALIZED struct)
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t size; /* For PgSQL use only, use VAR* macros to manipulate. */
|
||||
uint32_t srid; /* SRID */
|
||||
uint8_t flags; /* HasZ, HasM, HasBBox, IsGeodetic, IsReadOnly, IsSolid */
|
||||
uint8_t *data; /* See tserialized.txt */
|
||||
} TSERIALIZED;
|
||||
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
POINT4D *s; /* Edge starting point */
|
||||
POINT4D *e; /* Edge ending point */
|
||||
int count; /* Count how many time this edge is used in the TGEOM.
|
||||
Caution: We don't care about edge orientation ! */
|
||||
} TEDGE;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t nedges;
|
||||
uint32_t maxedges;
|
||||
int32_t *edges; /* Array of edge index, a negative value
|
||||
means that the edge is reversed */
|
||||
int32_t nrings;
|
||||
POINTARRAY **rings; /* Internal rings array */
|
||||
} TFACE;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t type;
|
||||
uint8_t flags;
|
||||
uint32_t srid; /* 0 == unknown */
|
||||
BOX3D *bbox; /* NULL == unneeded */
|
||||
uint32_t nedges;
|
||||
uint32_t maxedges;
|
||||
TEDGE **edges;
|
||||
uint32_t nfaces;
|
||||
uint32_t maxfaces;
|
||||
TFACE **faces;
|
||||
} TGEOM;
|
||||
|
||||
extern TGEOM* tgeom_new(uint8_t type, int hasz, int hasm);
|
||||
extern void tgeom_free(TGEOM *tgeom);
|
||||
extern TSERIALIZED* tserialized_from_lwgeom(LWGEOM *lwgeom);
|
||||
extern TGEOM* tgeom_from_lwgeom(const LWGEOM *lwgeom);
|
||||
extern LWGEOM* lwgeom_from_tserialized(TSERIALIZED *t);
|
||||
extern LWGEOM* lwgeom_from_tgeom(TGEOM *tgeom);
|
||||
extern int lwgeom_is_solid(LWGEOM *lwgeom);
|
||||
TSERIALIZED * tgeom_serialize(const TGEOM *tgeom);
|
||||
TGEOM * tgeom_deserialize(TSERIALIZED *serialized_form);
|
||||
double tgeom_perimeter2d(TGEOM* tgeom);
|
||||
double tgeom_perimeter(TGEOM* tgeom);
|
||||
extern void printTGEOM(TGEOM *tgeom);
|
||||
|
||||
#endif /* !defined _LIBTGEOM_H */
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
#include "liblwgeom_internal.h"
|
||||
#include "lwgeom_log.h"
|
||||
#include "libtgeom.h"
|
||||
|
||||
|
||||
/** Force Right-hand-rule on LWGEOM polygons **/
|
||||
|
@ -1253,7 +1252,7 @@ extern int lwgeom_dimensionality(LWGEOM *geom)
|
|||
|
||||
case POLYHEDRALSURFACETYPE:
|
||||
case TINTYPE:
|
||||
dim = lwgeom_is_solid(geom)?3:2;
|
||||
dim = lwgeom_is_closed(geom)?3:2;
|
||||
return dim;
|
||||
break;
|
||||
|
||||
|
@ -1453,10 +1452,6 @@ double lwgeom_perimeter(const LWGEOM *geom)
|
|||
return lwcurvepoly_perimeter((LWCURVEPOLY*)geom);
|
||||
else if ( type == TRIANGLETYPE )
|
||||
return lwtriangle_perimeter((LWTRIANGLE*)geom);
|
||||
else if ( type == POLYHEDRALSURFACETYPE || type == TINTYPE )
|
||||
{
|
||||
return tgeom_perimeter(tgeom_from_lwgeom(geom));
|
||||
}
|
||||
else if ( lwgeom_is_collection(geom) )
|
||||
{
|
||||
double perimeter = 0.0;
|
||||
|
@ -1479,10 +1474,6 @@ double lwgeom_perimeter_2d(const LWGEOM *geom)
|
|||
return lwcurvepoly_perimeter_2d((LWCURVEPOLY*)geom);
|
||||
else if ( type == TRIANGLETYPE )
|
||||
return lwtriangle_perimeter_2d((LWTRIANGLE*)geom);
|
||||
else if ( type == POLYHEDRALSURFACETYPE || type == TINTYPE )
|
||||
{
|
||||
return tgeom_perimeter(tgeom_from_lwgeom(geom));
|
||||
}
|
||||
else if ( lwgeom_is_collection(geom) )
|
||||
{
|
||||
double perimeter = 0.0;
|
||||
|
|
|
@ -668,7 +668,7 @@ create_spatial ()
|
|||
{
|
||||
echo "Creating spatial db ${DB} "
|
||||
|
||||
createdb --encoding=UTF-8 --template=template0 --lc-collate="C" "${DB}" > ${PGIS_REG_TMPDIR}/regress_log 2>&1
|
||||
createdb --template=template0 --lc-collate="C" "${DB}" > ${PGIS_REG_TMPDIR}/regress_log 2>&1
|
||||
if [ $? -gt 0 ]; then # {
|
||||
fail "createdb failed" "${PGIS_REG_TMPDIR}/regress_log"
|
||||
exit 1
|
||||
|
|
|
@ -959,7 +959,7 @@ sub create_spatial
|
|||
my ($cmd, $rv);
|
||||
print "Creating database '$DB' \n";
|
||||
|
||||
$cmd = "createdb --encoding=UTF-8 --template=template0 --lc-collate=C $DB > $REGRESS_LOG";
|
||||
$cmd = "createdb --template=template0 --lc-collate=C $DB > $REGRESS_LOG";
|
||||
$rv = system($cmd);
|
||||
$cmd = "createlang plpgsql $DB >> $REGRESS_LOG 2>&1";
|
||||
$rv = system($cmd);
|
||||
|
|
Loading…
Reference in a new issue