Skip to content

Commit 60a2fcf

Browse files
committed
wip
1 parent b9e9c08 commit 60a2fcf

File tree

10 files changed

+285
-243
lines changed

10 files changed

+285
-243
lines changed

liblwgeom/lwgeom_nurbs.c

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <string.h>
2828
#include <math.h>
2929
#include "liblwgeom_internal.h"
30+
#include "stringbuffer.h"
3031
#include "lwgeom_log.h"
3132
#include "lwgeom_nurbs.h"
3233

@@ -485,11 +486,6 @@ lwgeom_as_lwnurbs(const LWGEOM *lwgeom)
485486
return (LWNURBSCURVE*)lwgeom;
486487
}
487488

488-
/* WKB and WKT functions would be implemented here following PostGIS patterns,
489-
* but are omitted for brevity. They would follow the same patterns as
490-
* lwcircstring_to_wkb_buf, lwcircstring_from_wkb_state, etc.
491-
*/
492-
493489
/**
494490
* WKB serialization size calculation
495491
*/
@@ -539,19 +535,6 @@ lwnurbs_to_wkt(const LWNURBSCURVE *nurbs, uint8_t variant, int precision, size_t
539535
return result;
540536
}
541537

542-
uint8_t *
543-
lwnurbs_to_wkb_buf(const LWNURBSCURVE *nurbs, uint8_t *buf, uint8_t variant)
544-
{
545-
// TODO: FIX: Convert to linestring atm
546-
LWLINE *line = lwnurbs_to_linestring(nurbs, NURBS_DEFAULT_SAMPLES);
547-
if (line)
548-
{
549-
buf = lwgeom_to_wkb_buf((LWGEOM*)line, buf, variant);
550-
lwline_free(line);
551-
}
552-
return buf;
553-
}
554-
555538
LWNURBSCURVE *
556539
lwnurbs_from_wkb_state(wkb_parse_state *s)
557540
{

liblwgeom/lwgeom_nurbs.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
#define _LWGEOM_NURBS_H 1
2727

2828
#include "liblwgeom.h"
29-
30-
/* Forward declaration */
31-
typedef struct wkb_parse_state_t wkb_parse_state;
29+
#include "lwin.h"
3230

3331
/**
3432
* NURBS curve constants
@@ -88,13 +86,10 @@ extern void lwnurbs_compute_bbox_p(LWNURBSCURVE *nurbs);
8886
extern double *lwnurbs_uniform_knots(uint32_t degree, uint32_t nctrl);
8987
extern double *lwnurbs_clamped_knots(uint32_t degree, uint32_t nctrl);
9088

91-
/* WKB serialization - only declare if wkb_parse_state is available */
92-
#ifdef LIBLWGEOM_INTERNAL_H
89+
/* WKB serialization */
9390
extern uint8_t *lwnurbs_to_wkb_buf(const LWNURBSCURVE *nurbs, uint8_t *buf,
9491
uint8_t variant);
95-
extern LWNURBSCURVE *lwnurbs_from_wkb_state(wkb_parse_state *s);
9692
extern size_t lwnurbs_to_wkb_size(const LWNURBSCURVE *nurbs, uint8_t variant);
97-
#endif
9893

9994
/* WKT serialization */
10095
extern char *lwnurbs_to_wkt(const LWNURBSCURVE *nurbs, uint8_t variant,
@@ -106,6 +101,9 @@ extern uint32_t lwnurbs_get_npoints(const LWNURBSCURVE *nurbs);
106101
extern int lwnurbs_startpoint(const LWNURBSCURVE *nurbs, POINT4D *pt);
107102
extern int lwnurbs_endpoint(const LWNURBSCURVE *nurbs, POINT4D *pt);
108103

104+
/* Forward declaration for WKB functions */
105+
extern LWNURBSCURVE *lwnurbs_from_wkb_state(wkb_parse_state *s);
106+
109107
/* Type conversion */
110108
extern LWGEOM *lwnurbs_as_lwgeom(const LWNURBSCURVE *nurbs);
111109
extern LWNURBSCURVE *lwgeom_as_lwnurbs(const LWGEOM *lwgeom);

liblwgeom/lwin.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**********************************************************************
2+
*
3+
* PostGIS - Spatial Types for PostgreSQL
4+
* http://postgis.net
5+
*
6+
* PostGIS is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* PostGIS is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with PostGIS. If not, see <http://www.gnu.org/licenses/>.
18+
*
19+
**********************************************************************
20+
*
21+
* Copyright (C) 2025 PostGIS contributors
22+
*
23+
**********************************************************************/
24+
25+
#ifndef _LWIN_H
26+
#define _LWIN_H 1
27+
28+
/** Max depth in a geometry. Matches the default YYINITDEPTH for WKT */
29+
#define LW_PARSER_MAX_DEPTH 200
30+
31+
/**
32+
* Used for passing the parse state between the parsing functions.
33+
*/
34+
typedef struct
35+
{
36+
const uint8_t *wkb; /* Points to start of WKB */
37+
int32_t srid; /* Current SRID we are handling */
38+
size_t wkb_size; /* Expected size of WKB */
39+
int8_t swap_bytes; /* Do an endian flip? */
40+
int8_t check; /* Simple validity checks on geometries */
41+
int8_t lwtype; /* Current type we are handling */
42+
int8_t has_z; /* Z? */
43+
int8_t has_m; /* M? */
44+
int8_t has_srid; /* SRID? */
45+
int8_t error; /* An error was found (not enough bytes to read) */
46+
uint8_t depth; /* Current recursion level (to prevent stack overflows). Maxes at LW_PARSER_MAX_DEPTH */
47+
const uint8_t *pos; /* Current parse position */
48+
} wkb_parse_state;
49+
50+
#endif

liblwgeom/lwin_wkb.c

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,7 @@
3030
#include <math.h>
3131
#include <limits.h>
3232
#include "lwgeom_nurbs.h"
33-
34-
/** Max depth in a geometry. Matches the default YYINITDEPTH for WKT */
35-
#define LW_PARSER_MAX_DEPTH 200
36-
37-
/**
38-
* Used for passing the parse state between the parsing functions.
39-
*/
40-
typedef struct
41-
{
42-
const uint8_t *wkb; /* Points to start of WKB */
43-
int32_t srid; /* Current SRID we are handling */
44-
size_t wkb_size; /* Expected size of WKB */
45-
int8_t swap_bytes; /* Do an endian flip? */
46-
int8_t check; /* Simple validity checks on geometries */
47-
int8_t lwtype; /* Current type we are handling */
48-
int8_t has_z; /* Z? */
49-
int8_t has_m; /* M? */
50-
int8_t has_srid; /* SRID? */
51-
int8_t error; /* An error was found (not enough bytes to read) */
52-
uint8_t depth; /* Current recursion level (to prevent stack overflows). Maxes at LW_PARSER_MAX_DEPTH */
53-
const uint8_t *pos; /* Current parse position */
54-
} wkb_parse_state;
55-
33+
#include "lwin.h"
5634

5735
/**
5836
* Internal function declarations.

0 commit comments

Comments
 (0)