PostgreSQL Source Code  git master
geo_ops.c File Reference
#include "postgres.h"
#include <math.h>
#include <limits.h>
#include <float.h>
#include <ctype.h>
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "utils/builtins.h"
#include "utils/geo_decls.h"
Include dependency graph for geo_ops.c:

Go to the source code of this file.

Macros

#define M_PI   3.14159265358979323846
 
#define LDELIM   '('
 
#define RDELIM   ')'
 
#define DELIM   ','
 
#define LDELIM_EP   '['
 
#define RDELIM_EP   ']'
 
#define LDELIM_C   '<'
 
#define RDELIM_C   '>'
 
#define POINTEQ(pt1, pt2)   (FPeq((pt1)->x, (pt2)->x) && FPeq((pt1)->y, (pt2)->y))
 
#define POINT_ON_POLYGON   INT_MAX
 

Enumerations

enum  path_delim { PATH_NONE, PATH_OPEN, PATH_CLOSED }
 

Functions

static int point_inside (Point *p, int npts, Point *plist)
 
static int lseg_crossing (double x, double y, double px, double py)
 
static BOXbox_construct (double x1, double x2, double y1, double y2)
 
static BOXbox_fill (BOX *result, double x1, double x2, double y1, double y2)
 
static bool box_ov (BOX *box1, BOX *box2)
 
static double box_ht (BOX *box)
 
static double box_wd (BOX *box)
 
static double circle_ar (CIRCLE *circle)
 
static CIRCLEcircle_copy (CIRCLE *circle)
 
static LINEline_construct_pm (Point *pt, double m)
 
static void line_construct_pts (LINE *line, Point *pt1, Point *pt2)
 
static bool lseg_intersect_internal (LSEG *l1, LSEG *l2)
 
static double lseg_dt (LSEG *l1, LSEG *l2)
 
static bool on_ps_internal (Point *pt, LSEG *lseg)
 
static void make_bound_box (POLYGON *poly)
 
static bool plist_same (int npts, Point *p1, Point *p2)
 
static Pointpoint_construct (double x, double y)
 
static Pointpoint_copy (Point *pt)
 
static double single_decode (char *num, char **endptr_p, const char *type_name, const char *orig_string)
 
static void single_encode (float8 x, StringInfo str)
 
static void pair_decode (char *str, double *x, double *y, char **endptr_p, const char *type_name, const char *orig_string)
 
static void pair_encode (float8 x, float8 y, StringInfo str)
 
static int pair_count (char *s, char delim)
 
static void path_decode (char *str, bool opentype, int npts, Point *p, bool *isopen, char **endptr_p, const char *type_name, const char *orig_string)
 
static char * path_encode (enum path_delim path_delim, int npts, Point *pt)
 
static void statlseg_construct (LSEG *lseg, Point *pt1, Point *pt2)
 
static double box_ar (BOX *box)
 
static void box_cn (Point *center, BOX *box)
 
static Pointinterpt_sl (LSEG *lseg, LINE *line)
 
static bool has_interpt_sl (LSEG *lseg, LINE *line)
 
static double dist_pl_internal (Point *pt, LINE *line)
 
static double dist_ps_internal (Point *pt, LSEG *lseg)
 
static Pointline_interpt_internal (LINE *l1, LINE *l2)
 
static bool lseg_inside_poly (Point *a, Point *b, POLYGON *poly, int start)
 
static Pointlseg_interpt_internal (LSEG *l1, LSEG *l2)
 
static double dist_ppoly_internal (Point *pt, POLYGON *poly)
 
static char * path_encode (enum path_delim path_delim, int npts, Point *pt)
 
Datum box_in (PG_FUNCTION_ARGS)
 
Datum box_out (PG_FUNCTION_ARGS)
 
Datum box_recv (PG_FUNCTION_ARGS)
 
Datum box_send (PG_FUNCTION_ARGS)
 
BOXbox_copy (BOX *box)
 
Datum box_same (PG_FUNCTION_ARGS)
 
Datum box_overlap (PG_FUNCTION_ARGS)
 
Datum box_left (PG_FUNCTION_ARGS)
 
Datum box_overleft (PG_FUNCTION_ARGS)
 
Datum box_right (PG_FUNCTION_ARGS)
 
Datum box_overright (PG_FUNCTION_ARGS)
 
Datum box_below (PG_FUNCTION_ARGS)
 
Datum box_overbelow (PG_FUNCTION_ARGS)
 
Datum box_above (PG_FUNCTION_ARGS)
 
Datum box_overabove (PG_FUNCTION_ARGS)
 
Datum box_contained (PG_FUNCTION_ARGS)
 
Datum box_contain (PG_FUNCTION_ARGS)
 
Datum box_below_eq (PG_FUNCTION_ARGS)
 
Datum box_above_eq (PG_FUNCTION_ARGS)
 
Datum box_lt (PG_FUNCTION_ARGS)
 
Datum box_gt (PG_FUNCTION_ARGS)
 
Datum box_eq (PG_FUNCTION_ARGS)
 
Datum box_le (PG_FUNCTION_ARGS)
 
Datum box_ge (PG_FUNCTION_ARGS)
 
Datum box_area (PG_FUNCTION_ARGS)
 
Datum box_width (PG_FUNCTION_ARGS)
 
Datum box_height (PG_FUNCTION_ARGS)
 
Datum box_distance (PG_FUNCTION_ARGS)
 
Datum box_center (PG_FUNCTION_ARGS)
 
Datum box_intersect (PG_FUNCTION_ARGS)
 
Datum box_diagonal (PG_FUNCTION_ARGS)
 
static bool line_decode (char *s, const char *str, LINE *line)
 
Datum line_in (PG_FUNCTION_ARGS)
 
Datum line_out (PG_FUNCTION_ARGS)
 
Datum line_recv (PG_FUNCTION_ARGS)
 
Datum line_send (PG_FUNCTION_ARGS)
 
Datum line_construct_pp (PG_FUNCTION_ARGS)
 
Datum line_intersect (PG_FUNCTION_ARGS)
 
Datum line_parallel (PG_FUNCTION_ARGS)
 
Datum line_perp (PG_FUNCTION_ARGS)
 
Datum line_vertical (PG_FUNCTION_ARGS)
 
Datum line_horizontal (PG_FUNCTION_ARGS)
 
Datum line_eq (PG_FUNCTION_ARGS)
 
Datum line_distance (PG_FUNCTION_ARGS)
 
Datum line_interpt (PG_FUNCTION_ARGS)
 
Datum path_area (PG_FUNCTION_ARGS)
 
Datum path_in (PG_FUNCTION_ARGS)
 
Datum path_out (PG_FUNCTION_ARGS)
 
Datum path_recv (PG_FUNCTION_ARGS)
 
Datum path_send (PG_FUNCTION_ARGS)
 
Datum path_n_lt (PG_FUNCTION_ARGS)
 
Datum path_n_gt (PG_FUNCTION_ARGS)
 
Datum path_n_eq (PG_FUNCTION_ARGS)
 
Datum path_n_le (PG_FUNCTION_ARGS)
 
Datum path_n_ge (PG_FUNCTION_ARGS)
 
Datum path_isclosed (PG_FUNCTION_ARGS)
 
Datum path_isopen (PG_FUNCTION_ARGS)
 
Datum path_npoints (PG_FUNCTION_ARGS)
 
Datum path_close (PG_FUNCTION_ARGS)
 
Datum path_open (PG_FUNCTION_ARGS)
 
Datum path_inter (PG_FUNCTION_ARGS)
 
Datum path_distance (PG_FUNCTION_ARGS)
 
Datum path_length (PG_FUNCTION_ARGS)
 
Datum point_in (PG_FUNCTION_ARGS)
 
Datum point_out (PG_FUNCTION_ARGS)
 
Datum point_recv (PG_FUNCTION_ARGS)
 
Datum point_send (PG_FUNCTION_ARGS)
 
Datum point_left (PG_FUNCTION_ARGS)
 
Datum point_right (PG_FUNCTION_ARGS)
 
Datum point_above (PG_FUNCTION_ARGS)
 
Datum point_below (PG_FUNCTION_ARGS)
 
Datum point_vert (PG_FUNCTION_ARGS)
 
Datum point_horiz (PG_FUNCTION_ARGS)
 
Datum point_eq (PG_FUNCTION_ARGS)
 
Datum point_ne (PG_FUNCTION_ARGS)
 
Datum point_distance (PG_FUNCTION_ARGS)
 
double point_dt (Point *pt1, Point *pt2)
 
Datum point_slope (PG_FUNCTION_ARGS)
 
double point_sl (Point *pt1, Point *pt2)
 
Datum lseg_in (PG_FUNCTION_ARGS)
 
Datum lseg_out (PG_FUNCTION_ARGS)
 
Datum lseg_recv (PG_FUNCTION_ARGS)
 
Datum lseg_send (PG_FUNCTION_ARGS)
 
Datum lseg_construct (PG_FUNCTION_ARGS)
 
Datum lseg_length (PG_FUNCTION_ARGS)
 
Datum lseg_intersect (PG_FUNCTION_ARGS)
 
Datum lseg_parallel (PG_FUNCTION_ARGS)
 
Datum lseg_perp (PG_FUNCTION_ARGS)
 
Datum lseg_vertical (PG_FUNCTION_ARGS)
 
Datum lseg_horizontal (PG_FUNCTION_ARGS)
 
Datum lseg_eq (PG_FUNCTION_ARGS)
 
Datum lseg_ne (PG_FUNCTION_ARGS)
 
Datum lseg_lt (PG_FUNCTION_ARGS)
 
Datum lseg_le (PG_FUNCTION_ARGS)
 
Datum lseg_gt (PG_FUNCTION_ARGS)
 
Datum lseg_ge (PG_FUNCTION_ARGS)
 
Datum lseg_distance (PG_FUNCTION_ARGS)
 
Datum lseg_center (PG_FUNCTION_ARGS)
 
Datum lseg_interpt (PG_FUNCTION_ARGS)
 
Datum dist_pl (PG_FUNCTION_ARGS)
 
Datum dist_ps (PG_FUNCTION_ARGS)
 
Datum dist_ppath (PG_FUNCTION_ARGS)
 
Datum dist_pb (PG_FUNCTION_ARGS)
 
Datum dist_sl (PG_FUNCTION_ARGS)
 
Datum dist_sb (PG_FUNCTION_ARGS)
 
Datum dist_lb (PG_FUNCTION_ARGS)
 
Datum dist_cpoly (PG_FUNCTION_ARGS)
 
Datum dist_ppoly (PG_FUNCTION_ARGS)
 
Datum dist_polyp (PG_FUNCTION_ARGS)
 
Datum close_pl (PG_FUNCTION_ARGS)
 
Datum close_ps (PG_FUNCTION_ARGS)
 
Datum close_lseg (PG_FUNCTION_ARGS)
 
Datum close_pb (PG_FUNCTION_ARGS)
 
Datum close_sl (PG_FUNCTION_ARGS)
 
Datum close_ls (PG_FUNCTION_ARGS)
 
Datum close_sb (PG_FUNCTION_ARGS)
 
Datum close_lb (PG_FUNCTION_ARGS)
 
Datum on_pl (PG_FUNCTION_ARGS)
 
Datum on_ps (PG_FUNCTION_ARGS)
 
Datum on_pb (PG_FUNCTION_ARGS)
 
Datum box_contain_pt (PG_FUNCTION_ARGS)
 
Datum on_ppath (PG_FUNCTION_ARGS)
 
Datum on_sl (PG_FUNCTION_ARGS)
 
Datum on_sb (PG_FUNCTION_ARGS)
 
Datum inter_sl (PG_FUNCTION_ARGS)
 
Datum inter_sb (PG_FUNCTION_ARGS)
 
Datum inter_lb (PG_FUNCTION_ARGS)
 
Datum poly_in (PG_FUNCTION_ARGS)
 
Datum poly_out (PG_FUNCTION_ARGS)
 
Datum poly_recv (PG_FUNCTION_ARGS)
 
Datum poly_send (PG_FUNCTION_ARGS)
 
Datum poly_left (PG_FUNCTION_ARGS)
 
Datum poly_overleft (PG_FUNCTION_ARGS)
 
Datum poly_right (PG_FUNCTION_ARGS)
 
Datum poly_overright (PG_FUNCTION_ARGS)
 
Datum poly_below (PG_FUNCTION_ARGS)
 
Datum poly_overbelow (PG_FUNCTION_ARGS)
 
Datum poly_above (PG_FUNCTION_ARGS)
 
Datum poly_overabove (PG_FUNCTION_ARGS)
 
Datum poly_same (PG_FUNCTION_ARGS)
 
Datum poly_overlap (PG_FUNCTION_ARGS)
 
static bool touched_lseg_inside_poly (Point *a, Point *b, LSEG *s, POLYGON *poly, int start)
 
Datum poly_contain (PG_FUNCTION_ARGS)
 
Datum poly_contained (PG_FUNCTION_ARGS)
 
Datum poly_contain_pt (PG_FUNCTION_ARGS)
 
Datum pt_contained_poly (PG_FUNCTION_ARGS)
 
Datum poly_distance (PG_FUNCTION_ARGS)
 
Datum construct_point (PG_FUNCTION_ARGS)
 
Datum point_add (PG_FUNCTION_ARGS)
 
Datum point_sub (PG_FUNCTION_ARGS)
 
Datum point_mul (PG_FUNCTION_ARGS)
 
Datum point_div (PG_FUNCTION_ARGS)
 
Datum points_box (PG_FUNCTION_ARGS)
 
Datum box_add (PG_FUNCTION_ARGS)
 
Datum box_sub (PG_FUNCTION_ARGS)
 
Datum box_mul (PG_FUNCTION_ARGS)
 
Datum box_div (PG_FUNCTION_ARGS)
 
Datum point_box (PG_FUNCTION_ARGS)
 
Datum boxes_bound_box (PG_FUNCTION_ARGS)
 
Datum path_add (PG_FUNCTION_ARGS)
 
Datum path_add_pt (PG_FUNCTION_ARGS)
 
Datum path_sub_pt (PG_FUNCTION_ARGS)
 
Datum path_mul_pt (PG_FUNCTION_ARGS)
 
Datum path_div_pt (PG_FUNCTION_ARGS)
 
Datum path_center (PG_FUNCTION_ARGS)
 
Datum path_poly (PG_FUNCTION_ARGS)
 
Datum poly_npoints (PG_FUNCTION_ARGS)
 
Datum poly_center (PG_FUNCTION_ARGS)
 
Datum poly_box (PG_FUNCTION_ARGS)
 
Datum box_poly (PG_FUNCTION_ARGS)
 
Datum poly_path (PG_FUNCTION_ARGS)
 
Datum circle_in (PG_FUNCTION_ARGS)
 
Datum circle_out (PG_FUNCTION_ARGS)
 
Datum circle_recv (PG_FUNCTION_ARGS)
 
Datum circle_send (PG_FUNCTION_ARGS)
 
Datum circle_same (PG_FUNCTION_ARGS)
 
Datum circle_overlap (PG_FUNCTION_ARGS)
 
Datum circle_overleft (PG_FUNCTION_ARGS)
 
Datum circle_left (PG_FUNCTION_ARGS)
 
Datum circle_right (PG_FUNCTION_ARGS)
 
Datum circle_overright (PG_FUNCTION_ARGS)
 
Datum circle_contained (PG_FUNCTION_ARGS)
 
Datum circle_contain (PG_FUNCTION_ARGS)
 
Datum circle_below (PG_FUNCTION_ARGS)
 
Datum circle_above (PG_FUNCTION_ARGS)
 
Datum circle_overbelow (PG_FUNCTION_ARGS)
 
Datum circle_overabove (PG_FUNCTION_ARGS)
 
Datum circle_eq (PG_FUNCTION_ARGS)
 
Datum circle_ne (PG_FUNCTION_ARGS)
 
Datum circle_lt (PG_FUNCTION_ARGS)
 
Datum circle_gt (PG_FUNCTION_ARGS)
 
Datum circle_le (PG_FUNCTION_ARGS)
 
Datum circle_ge (PG_FUNCTION_ARGS)
 
Datum circle_add_pt (PG_FUNCTION_ARGS)
 
Datum circle_sub_pt (PG_FUNCTION_ARGS)
 
Datum circle_mul_pt (PG_FUNCTION_ARGS)
 
Datum circle_div_pt (PG_FUNCTION_ARGS)
 
Datum circle_area (PG_FUNCTION_ARGS)
 
Datum circle_diameter (PG_FUNCTION_ARGS)
 
Datum circle_radius (PG_FUNCTION_ARGS)
 
Datum circle_distance (PG_FUNCTION_ARGS)
 
Datum circle_contain_pt (PG_FUNCTION_ARGS)
 
Datum pt_contained_circle (PG_FUNCTION_ARGS)
 
Datum dist_pc (PG_FUNCTION_ARGS)
 
Datum dist_cpoint (PG_FUNCTION_ARGS)
 
Datum circle_center (PG_FUNCTION_ARGS)
 
Datum cr_circle (PG_FUNCTION_ARGS)
 
Datum circle_box (PG_FUNCTION_ARGS)
 
Datum box_circle (PG_FUNCTION_ARGS)
 
Datum circle_poly (PG_FUNCTION_ARGS)
 
Datum poly_circle (PG_FUNCTION_ARGS)
 
double pg_hypot (double x, double y)
 

Macro Definition Documentation

◆ DELIM

#define DELIM   ','

Definition at line 91 of file geo_ops.c.

Referenced by circle_in(), circle_out(), line_decode(), pair_decode(), path_decode(), and path_encode().

◆ LDELIM

#define LDELIM   '('

Definition at line 89 of file geo_ops.c.

Referenced by circle_in(), circle_out(), pair_decode(), path_decode(), path_encode(), and path_in().

◆ LDELIM_C

#define LDELIM_C   '<'

Definition at line 94 of file geo_ops.c.

Referenced by circle_in(), and circle_out().

◆ LDELIM_EP

#define LDELIM_EP   '['

Definition at line 92 of file geo_ops.c.

Referenced by path_decode(), and path_encode().

◆ M_PI

#define M_PI   3.14159265358979323846

Definition at line 28 of file geo_ops.c.

Referenced by circle_ar(), and circle_poly().

◆ POINT_ON_POLYGON

#define POINT_ON_POLYGON   INT_MAX

Definition at line 5256 of file geo_ops.c.

Referenced by lseg_crossing(), and point_inside().

◆ POINTEQ

#define POINTEQ (   pt1,
  pt2 
)    (FPeq((pt1)->x, (pt2)->x) && FPeq((pt1)->y, (pt2)->y))

◆ RDELIM

#define RDELIM   ')'

Definition at line 90 of file geo_ops.c.

Referenced by circle_in(), circle_out(), pair_decode(), path_decode(), path_encode(), and path_in().

◆ RDELIM_C

#define RDELIM_C   '>'

Definition at line 95 of file geo_ops.c.

Referenced by circle_in(), and circle_out().

◆ RDELIM_EP

#define RDELIM_EP   ']'

Definition at line 93 of file geo_ops.c.

Referenced by path_decode(), and path_encode().

Enumeration Type Documentation

◆ path_delim

enum path_delim
Enumerator
PATH_NONE 
PATH_OPEN 
PATH_CLOSED 

Definition at line 36 of file geo_ops.c.

Function Documentation

◆ box_above()

Datum box_above ( PG_FUNCTION_ARGS  )

Definition at line 612 of file geo_ops.c.

References FPgt, BOX::high, BOX::low, PG_GETARG_BOX_P, PG_RETURN_BOOL, and Point::y.

Referenced by gist_box_leaf_consistent(), rtree_internal_consistent(), and spg_box_quad_leaf_consistent().

613 {
614  BOX *box1 = PG_GETARG_BOX_P(0);
615  BOX *box2 = PG_GETARG_BOX_P(1);
616 
617  PG_RETURN_BOOL(FPgt(box1->low.y, box2->high.y));
618 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
double y
Definition: geo_decls.h:60
#define FPgt(A, B)
Definition: geo_decls.h:41
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
Point high
Definition: geo_decls.h:104

◆ box_above_eq()

Datum box_above_eq ( PG_FUNCTION_ARGS  )

Definition at line 679 of file geo_ops.c.

References FPge, BOX::high, BOX::low, PG_GETARG_BOX_P, PG_RETURN_BOOL, and Point::y.

680 {
681  BOX *box1 = PG_GETARG_BOX_P(0);
682  BOX *box2 = PG_GETARG_BOX_P(1);
683 
684  PG_RETURN_BOOL(FPge(box1->low.y, box2->high.y));
685 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
double y
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
Point high
Definition: geo_decls.h:104
#define FPge(A, B)
Definition: geo_decls.h:42

◆ box_add()

Datum box_add ( PG_FUNCTION_ARGS  )

Definition at line 4117 of file geo_ops.c.

References box_construct(), BOX::high, BOX::low, PG_GETARG_BOX_P, PG_GETARG_POINT_P, PG_RETURN_BOX_P, Point::x, and Point::y.

4118 {
4119  BOX *box = PG_GETARG_BOX_P(0);
4120  Point *p = PG_GETARG_POINT_P(1);
4121 
4122  PG_RETURN_BOX_P(box_construct((box->high.x + p->x),
4123  (box->low.x + p->x),
4124  (box->high.y + p->y),
4125  (box->low.y + p->y)));
4126 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:162
Point high
Definition: geo_decls.h:104
static BOX * box_construct(double x1, double x2, double y1, double y2)
Definition: geo_ops.c:444

◆ box_ar()

static double box_ar ( BOX box)
static

Definition at line 811 of file geo_ops.c.

References box_ht(), and box_wd().

Referenced by box_area(), box_eq(), box_ge(), box_gt(), box_le(), and box_lt().

812 {
813  return box_wd(box) * box_ht(box);
814 }
static double box_wd(BOX *box)
Definition: geo_ops.c:831
static double box_ht(BOX *box)
Definition: geo_ops.c:841

◆ box_area()

Datum box_area ( PG_FUNCTION_ARGS  )

Definition at line 744 of file geo_ops.c.

References box_ar(), PG_GETARG_BOX_P, and PG_RETURN_FLOAT8.

745 {
746  BOX *box = PG_GETARG_BOX_P(0);
747 
748  PG_RETURN_FLOAT8(box_ar(box));
749 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
static double box_ar(BOX *box)
Definition: geo_ops.c:811

◆ box_below()

Datum box_below ( PG_FUNCTION_ARGS  )

Definition at line 589 of file geo_ops.c.

References FPlt, BOX::high, BOX::low, PG_GETARG_BOX_P, PG_RETURN_BOOL, and Point::y.

Referenced by gist_box_leaf_consistent(), rtree_internal_consistent(), and spg_box_quad_leaf_consistent().

590 {
591  BOX *box1 = PG_GETARG_BOX_P(0);
592  BOX *box2 = PG_GETARG_BOX_P(1);
593 
594  PG_RETURN_BOOL(FPlt(box1->high.y, box2->low.y));
595 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
double y
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define FPlt(A, B)
Definition: geo_decls.h:39
Point high
Definition: geo_decls.h:104

◆ box_below_eq()

Datum box_below_eq ( PG_FUNCTION_ARGS  )

Definition at line 670 of file geo_ops.c.

References FPle, BOX::high, BOX::low, PG_GETARG_BOX_P, PG_RETURN_BOOL, and Point::y.

671 {
672  BOX *box1 = PG_GETARG_BOX_P(0);
673  BOX *box2 = PG_GETARG_BOX_P(1);
674 
675  PG_RETURN_BOOL(FPle(box1->high.y, box2->low.y));
676 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
double y
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
Point high
Definition: geo_decls.h:104
#define FPle(A, B)
Definition: geo_decls.h:40

◆ box_center()

Datum box_center ( PG_FUNCTION_ARGS  )

Definition at line 797 of file geo_ops.c.

References box_cn(), palloc(), PG_GETARG_BOX_P, and PG_RETURN_POINT_P.

798 {
799  BOX *box = PG_GETARG_BOX_P(0);
800  Point *result = (Point *) palloc(sizeof(Point));
801 
802  box_cn(result, box);
803 
804  PG_RETURN_POINT_P(result);
805 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
static void box_cn(Point *center, BOX *box)
Definition: geo_ops.c:820
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:140
void * palloc(Size size)
Definition: mcxt.c:924

◆ box_circle()

Datum box_circle ( PG_FUNCTION_ARGS  )

Definition at line 5135 of file geo_ops.c.

References CIRCLE::center, BOX::high, BOX::low, palloc(), PG_GETARG_BOX_P, PG_RETURN_CIRCLE_P, point_dt(), CIRCLE::radius, Point::x, and Point::y.

5136 {
5137  BOX *box = PG_GETARG_BOX_P(0);
5138  CIRCLE *circle;
5139 
5140  circle = (CIRCLE *) palloc(sizeof(CIRCLE));
5141 
5142  circle->center.x = (box->high.x + box->low.x) / 2;
5143  circle->center.y = (box->high.y + box->low.y) / 2;
5144 
5145  circle->radius = point_dt(&circle->center, &box->high);
5146 
5147  PG_RETURN_CIRCLE_P(circle);
5148 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:174
Point high
Definition: geo_decls.h:104
Point center
Definition: geo_decls.h:126
double point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1905
void * palloc(Size size)
Definition: mcxt.c:924

◆ box_cn()

static void box_cn ( Point center,
BOX box 
)
static

Definition at line 820 of file geo_ops.c.

References BOX::high, BOX::low, Point::x, and Point::y.

Referenced by box_center(), box_distance(), and close_sb().

821 {
822  center->x = (box->high.x + box->low.x) / 2.0;
823  center->y = (box->high.y + box->low.y) / 2.0;
824 }
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
Point high
Definition: geo_decls.h:104

◆ box_construct()

static BOX * box_construct ( double  x1,
double  x2,
double  y1,
double  y2 
)
static

Definition at line 444 of file geo_ops.c.

References box_fill(), and palloc().

Referenced by box_add(), box_div(), box_mul(), box_sub(), and points_box().

445 {
446  BOX *result = (BOX *) palloc(sizeof(BOX));
447 
448  return box_fill(result, x1, x2, y1, y2);
449 }
Definition: geo_decls.h:102
static BOX * box_fill(BOX *result, double x1, double x2, double y1, double y2)
Definition: geo_ops.c:455
void * palloc(Size size)
Definition: mcxt.c:924

◆ box_contain()

Datum box_contain ( PG_FUNCTION_ARGS  )

Definition at line 649 of file geo_ops.c.

References FPge, FPle, BOX::high, BOX::low, PG_GETARG_BOX_P, PG_RETURN_BOOL, Point::x, and Point::y.

Referenced by gist_box_leaf_consistent(), poly_contain(), rtree_internal_consistent(), and spg_box_quad_leaf_consistent().

650 {
651  BOX *box1 = PG_GETARG_BOX_P(0);
652  BOX *box2 = PG_GETARG_BOX_P(1);
653 
654  PG_RETURN_BOOL(FPge(box1->high.x, box2->high.x) &&
655  FPle(box1->low.x, box2->low.x) &&
656  FPge(box1->high.y, box2->high.y) &&
657  FPle(box1->low.y, box2->low.y));
658 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
Point high
Definition: geo_decls.h:104
#define FPge(A, B)
Definition: geo_decls.h:42
#define FPle(A, B)
Definition: geo_decls.h:40

◆ box_contain_pt()

Datum box_contain_pt ( PG_FUNCTION_ARGS  )

Definition at line 3170 of file geo_ops.c.

References BOX::high, BOX::low, PG_GETARG_BOX_P, PG_GETARG_POINT_P, PG_RETURN_BOOL, Point::x, and Point::y.

Referenced by spg_quad_inner_consistent(), and spg_quad_leaf_consistent().

3171 {
3172  BOX *box = PG_GETARG_BOX_P(0);
3173  Point *pt = PG_GETARG_POINT_P(1);
3174 
3175  PG_RETURN_BOOL(pt->x <= box->high.x && pt->x >= box->low.x &&
3176  pt->y <= box->high.y && pt->y >= box->low.y);
3177 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
Point high
Definition: geo_decls.h:104

◆ box_contained()

Datum box_contained ( PG_FUNCTION_ARGS  )

Definition at line 635 of file geo_ops.c.

References FPge, FPle, BOX::high, BOX::low, PG_GETARG_BOX_P, PG_RETURN_BOOL, Point::x, and Point::y.

Referenced by gist_box_leaf_consistent(), and spg_box_quad_leaf_consistent().

636 {
637  BOX *box1 = PG_GETARG_BOX_P(0);
638  BOX *box2 = PG_GETARG_BOX_P(1);
639 
640  PG_RETURN_BOOL(FPle(box1->high.x, box2->high.x) &&
641  FPge(box1->low.x, box2->low.x) &&
642  FPle(box1->high.y, box2->high.y) &&
643  FPge(box1->low.y, box2->low.y));
644 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
Point high
Definition: geo_decls.h:104
#define FPge(A, B)
Definition: geo_decls.h:42
#define FPle(A, B)
Definition: geo_decls.h:40

◆ box_copy()

BOX* box_copy ( BOX box)

Definition at line 485 of file geo_ops.c.

References palloc().

Referenced by poly_box(), and spg_poly_quad_compress().

486 {
487  BOX *result = (BOX *) palloc(sizeof(BOX));
488 
489  memcpy((char *) result, (char *) box, sizeof(BOX));
490 
491  return result;
492 }
Definition: geo_decls.h:102
void * palloc(Size size)
Definition: mcxt.c:924

◆ box_diagonal()

Datum box_diagonal ( PG_FUNCTION_ARGS  )

Definition at line 881 of file geo_ops.c.

References BOX::high, BOX::low, palloc(), PG_GETARG_BOX_P, PG_RETURN_LSEG_P, and statlseg_construct().

882 {
883  BOX *box = PG_GETARG_BOX_P(0);
884  LSEG *result = (LSEG *) palloc(sizeof(LSEG));
885 
886  statlseg_construct(result, &box->high, &box->low);
887 
888  PG_RETURN_LSEG_P(result);
889 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
static void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: geo_ops.c:2025
Definition: geo_decls.h:68
#define PG_RETURN_LSEG_P(x)
Definition: geo_decls.h:145
Point low
Definition: geo_decls.h:104
Point high
Definition: geo_decls.h:104
void * palloc(Size size)
Definition: mcxt.c:924

◆ box_distance()

Datum box_distance ( PG_FUNCTION_ARGS  )

Definition at line 780 of file geo_ops.c.

References box_cn(), HYPOT, PG_GETARG_BOX_P, PG_RETURN_FLOAT8, Point::x, and Point::y.

781 {
782  BOX *box1 = PG_GETARG_BOX_P(0);
783  BOX *box2 = PG_GETARG_BOX_P(1);
784  Point a,
785  b;
786 
787  box_cn(&a, box1);
788  box_cn(&b, box2);
789 
790  PG_RETURN_FLOAT8(HYPOT(a.x - b.x, a.y - b.y));
791 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
double y
Definition: geo_decls.h:60
static void box_cn(Point *center, BOX *box)
Definition: geo_ops.c:820
double x
Definition: geo_decls.h:60
#define HYPOT(A, B)
Definition: geo_decls.h:53

◆ box_div()

Datum box_div ( PG_FUNCTION_ARGS  )

Definition at line 4162 of file geo_ops.c.

References box_construct(), DatumGetPointP, DirectFunctionCall2, BOX::high, BOX::low, PG_GETARG_BOX_P, PG_GETARG_POINT_P, PG_RETURN_BOX_P, point_div(), PointPGetDatum, Point::x, and Point::y.

4163 {
4164  BOX *box = PG_GETARG_BOX_P(0);
4165  Point *p = PG_GETARG_POINT_P(1);
4166  BOX *result;
4167  Point *high,
4168  *low;
4169 
4171  PointPGetDatum(&box->high),
4172  PointPGetDatum(p)));
4174  PointPGetDatum(&box->low),
4175  PointPGetDatum(p)));
4176 
4177  result = box_construct(high->x, low->x, high->y, low->y);
4178 
4179  PG_RETURN_BOX_P(result);
4180 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
Datum point_div(PG_FUNCTION_ARGS)
Definition: geo_ops.c:4078
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:162
#define DatumGetPointP(X)
Definition: geo_decls.h:137
Point high
Definition: geo_decls.h:104
static BOX * box_construct(double x1, double x2, double y1, double y2)
Definition: geo_ops.c:444
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:592
#define PointPGetDatum(X)
Definition: geo_decls.h:138

◆ box_eq()

Datum box_eq ( PG_FUNCTION_ARGS  )

Definition at line 710 of file geo_ops.c.

References box_ar(), FPeq, PG_GETARG_BOX_P, and PG_RETURN_BOOL.

711 {
712  BOX *box1 = PG_GETARG_BOX_P(0);
713  BOX *box2 = PG_GETARG_BOX_P(1);
714 
715  PG_RETURN_BOOL(FPeq(box_ar(box1), box_ar(box2)));
716 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
static double box_ar(BOX *box)
Definition: geo_ops.c:811
#define FPeq(A, B)
Definition: geo_decls.h:37
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324

◆ box_fill()

static BOX * box_fill ( BOX result,
double  x1,
double  x2,
double  y1,
double  y2 
)
static

Definition at line 455 of file geo_ops.c.

References BOX::high, BOX::low, Point::x, and Point::y.

Referenced by box_construct(), box_poly(), and make_bound_box().

456 {
457  if (x1 > x2)
458  {
459  result->high.x = x1;
460  result->low.x = x2;
461  }
462  else
463  {
464  result->high.x = x2;
465  result->low.x = x1;
466  }
467  if (y1 > y2)
468  {
469  result->high.y = y1;
470  result->low.y = y2;
471  }
472  else
473  {
474  result->high.y = y2;
475  result->low.y = y1;
476  }
477 
478  return result;
479 }
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
Point high
Definition: geo_decls.h:104

◆ box_ge()

Datum box_ge ( PG_FUNCTION_ARGS  )

Definition at line 728 of file geo_ops.c.

References box_ar(), FPge, PG_GETARG_BOX_P, and PG_RETURN_BOOL.

729 {
730  BOX *box1 = PG_GETARG_BOX_P(0);
731  BOX *box2 = PG_GETARG_BOX_P(1);
732 
733  PG_RETURN_BOOL(FPge(box_ar(box1), box_ar(box2)));
734 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
static double box_ar(BOX *box)
Definition: geo_ops.c:811
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define FPge(A, B)
Definition: geo_decls.h:42

◆ box_gt()

Datum box_gt ( PG_FUNCTION_ARGS  )

Definition at line 701 of file geo_ops.c.

References box_ar(), FPgt, PG_GETARG_BOX_P, and PG_RETURN_BOOL.

702 {
703  BOX *box1 = PG_GETARG_BOX_P(0);
704  BOX *box2 = PG_GETARG_BOX_P(1);
705 
706  PG_RETURN_BOOL(FPgt(box_ar(box1), box_ar(box2)));
707 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
#define FPgt(A, B)
Definition: geo_decls.h:41
static double box_ar(BOX *box)
Definition: geo_ops.c:811
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324

◆ box_height()

Datum box_height ( PG_FUNCTION_ARGS  )

Definition at line 768 of file geo_ops.c.

References BOX::high, BOX::low, PG_GETARG_BOX_P, PG_RETURN_FLOAT8, and Point::y.

769 {
770  BOX *box = PG_GETARG_BOX_P(0);
771 
772  PG_RETURN_FLOAT8(box->high.y - box->low.y);
773 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
double y
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
Point high
Definition: geo_decls.h:104

◆ box_ht()

static double box_ht ( BOX box)
static

Definition at line 841 of file geo_ops.c.

References BOX::high, BOX::low, and Point::y.

Referenced by box_ar().

842 {
843  return box->high.y - box->low.y;
844 }
double y
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
Point high
Definition: geo_decls.h:104

◆ box_in()

Datum box_in ( PG_FUNCTION_ARGS  )

Definition at line 351 of file geo_ops.c.

References BOX::high, BOX::low, palloc(), path_decode(), PG_GETARG_CSTRING, PG_RETURN_BOX_P, generate_unaccent_rules::str, Point::x, and Point::y.

352 {
353  char *str = PG_GETARG_CSTRING(0);
354  BOX *box = (BOX *) palloc(sizeof(BOX));
355  bool isopen;
356  double x,
357  y;
358 
359  path_decode(str, false, 2, &(box->high), &isopen, NULL, "box", str);
360 
361  /* reorder corners if necessary... */
362  if (box->high.x < box->low.x)
363  {
364  x = box->high.x;
365  box->high.x = box->low.x;
366  box->low.x = x;
367  }
368  if (box->high.y < box->low.y)
369  {
370  y = box->high.y;
371  box->high.y = box->low.y;
372  box->low.y = y;
373  }
374 
375  PG_RETURN_BOX_P(box);
376 }
Definition: geo_decls.h:102
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:162
Point high
Definition: geo_decls.h:104
void * palloc(Size size)
Definition: mcxt.c:924
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:247
static void path_decode(char *str, bool opentype, int npts, Point *p, bool *isopen, char **endptr_p, const char *type_name, const char *orig_string)
Definition: geo_ops.c:193

◆ box_intersect()

Datum box_intersect ( PG_FUNCTION_ARGS  )

Definition at line 856 of file geo_ops.c.

References box_ov(), BOX::high, BOX::low, Max, Min, palloc(), PG_GETARG_BOX_P, PG_RETURN_BOX_P, PG_RETURN_NULL, Point::x, and Point::y.

857 {
858  BOX *box1 = PG_GETARG_BOX_P(0);
859  BOX *box2 = PG_GETARG_BOX_P(1);
860  BOX *result;
861 
862  if (!box_ov(box1, box2))
863  PG_RETURN_NULL();
864 
865  result = (BOX *) palloc(sizeof(BOX));
866 
867  result->high.x = Min(box1->high.x, box2->high.x);
868  result->low.x = Max(box1->low.x, box2->low.x);
869  result->high.y = Min(box1->high.y, box2->high.y);
870  result->low.y = Max(box1->low.y, box2->low.y);
871 
872  PG_RETURN_BOX_P(result);
873 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
#define Min(x, y)
Definition: c.h:857
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
static bool box_ov(BOX *box1, BOX *box2)
Definition: geo_ops.c:526
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:162
#define Max(x, y)
Definition: c.h:851
Point high
Definition: geo_decls.h:104
void * palloc(Size size)
Definition: mcxt.c:924
#define PG_RETURN_NULL()
Definition: fmgr.h:310

◆ box_le()

Datum box_le ( PG_FUNCTION_ARGS  )

Definition at line 719 of file geo_ops.c.

References box_ar(), FPle, PG_GETARG_BOX_P, and PG_RETURN_BOOL.

720 {
721  BOX *box1 = PG_GETARG_BOX_P(0);
722  BOX *box2 = PG_GETARG_BOX_P(1);
723 
724  PG_RETURN_BOOL(FPle(box_ar(box1), box_ar(box2)));
725 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
static double box_ar(BOX *box)
Definition: geo_ops.c:811
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define FPle(A, B)
Definition: geo_decls.h:40

◆ box_left()

Datum box_left ( PG_FUNCTION_ARGS  )

Definition at line 537 of file geo_ops.c.

References FPlt, BOX::high, BOX::low, PG_GETARG_BOX_P, PG_RETURN_BOOL, and Point::x.

Referenced by gist_box_leaf_consistent(), rtree_internal_consistent(), and spg_box_quad_leaf_consistent().

538 {
539  BOX *box1 = PG_GETARG_BOX_P(0);
540  BOX *box2 = PG_GETARG_BOX_P(1);
541 
542  PG_RETURN_BOOL(FPlt(box1->high.x, box2->low.x));
543 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
double x
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define FPlt(A, B)
Definition: geo_decls.h:39
Point high
Definition: geo_decls.h:104

◆ box_lt()

Datum box_lt ( PG_FUNCTION_ARGS  )

Definition at line 692 of file geo_ops.c.

References box_ar(), FPlt, PG_GETARG_BOX_P, and PG_RETURN_BOOL.

693 {
694  BOX *box1 = PG_GETARG_BOX_P(0);
695  BOX *box2 = PG_GETARG_BOX_P(1);
696 
697  PG_RETURN_BOOL(FPlt(box_ar(box1), box_ar(box2)));
698 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
static double box_ar(BOX *box)
Definition: geo_ops.c:811
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define FPlt(A, B)
Definition: geo_decls.h:39

◆ box_mul()

Datum box_mul ( PG_FUNCTION_ARGS  )

Definition at line 4141 of file geo_ops.c.

References box_construct(), DatumGetPointP, DirectFunctionCall2, BOX::high, BOX::low, PG_GETARG_BOX_P, PG_GETARG_POINT_P, PG_RETURN_BOX_P, point_mul(), PointPGetDatum, Point::x, and Point::y.

4142 {
4143  BOX *box = PG_GETARG_BOX_P(0);
4144  Point *p = PG_GETARG_POINT_P(1);
4145  BOX *result;
4146  Point *high,
4147  *low;
4148 
4150  PointPGetDatum(&box->high),
4151  PointPGetDatum(p)));
4153  PointPGetDatum(&box->low),
4154  PointPGetDatum(p)));
4155 
4156  result = box_construct(high->x, low->x, high->y, low->y);
4157 
4158  PG_RETURN_BOX_P(result);
4159 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
Datum point_mul(PG_FUNCTION_ARGS)
Definition: geo_ops.c:4063
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:162
#define DatumGetPointP(X)
Definition: geo_decls.h:137
Point high
Definition: geo_decls.h:104
static BOX * box_construct(double x1, double x2, double y1, double y2)
Definition: geo_ops.c:444
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:592
#define PointPGetDatum(X)
Definition: geo_decls.h:138

◆ box_out()

Datum box_out ( PG_FUNCTION_ARGS  )

Definition at line 381 of file geo_ops.c.

References BOX::high, path_encode(), PATH_NONE, PG_GETARG_BOX_P, and PG_RETURN_CSTRING.

382 {
383  BOX *box = PG_GETARG_BOX_P(0);
384 
386 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:327
Point high
Definition: geo_decls.h:104
static char * path_encode(enum path_delim path_delim, int npts, Point *pt)

◆ box_ov()

static bool box_ov ( BOX box1,
BOX box2 
)
static

Definition at line 526 of file geo_ops.c.

References FPle, BOX::high, BOX::low, Point::x, and Point::y.

Referenced by box_intersect(), box_overlap(), inter_sb(), path_inter(), and poly_overlap().

527 {
528  return (FPle(box1->low.x, box2->high.x) &&
529  FPle(box2->low.x, box1->high.x) &&
530  FPle(box1->low.y, box2->high.y) &&
531  FPle(box2->low.y, box1->high.y));
532 }
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
Point high
Definition: geo_decls.h:104
#define FPle(A, B)
Definition: geo_decls.h:40

◆ box_overabove()

Datum box_overabove ( PG_FUNCTION_ARGS  )

Definition at line 624 of file geo_ops.c.

References FPge, BOX::low, PG_GETARG_BOX_P, PG_RETURN_BOOL, and Point::y.

Referenced by gist_box_leaf_consistent(), rtree_internal_consistent(), and spg_box_quad_leaf_consistent().

625 {
626  BOX *box1 = PG_GETARG_BOX_P(0);
627  BOX *box2 = PG_GETARG_BOX_P(1);
628 
629  PG_RETURN_BOOL(FPge(box1->low.y, box2->low.y));
630 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
double y
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define FPge(A, B)
Definition: geo_decls.h:42

◆ box_overbelow()

Datum box_overbelow ( PG_FUNCTION_ARGS  )

Definition at line 601 of file geo_ops.c.

References FPle, BOX::high, PG_GETARG_BOX_P, PG_RETURN_BOOL, and Point::y.

Referenced by gist_box_leaf_consistent(), rtree_internal_consistent(), and spg_box_quad_leaf_consistent().

602 {
603  BOX *box1 = PG_GETARG_BOX_P(0);
604  BOX *box2 = PG_GETARG_BOX_P(1);
605 
606  PG_RETURN_BOOL(FPle(box1->high.y, box2->high.y));
607 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
double y
Definition: geo_decls.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
Point high
Definition: geo_decls.h:104
#define FPle(A, B)
Definition: geo_decls.h:40

◆ box_overlap()

Datum box_overlap ( PG_FUNCTION_ARGS  )

Definition at line 517 of file geo_ops.c.

References box_ov(), PG_GETARG_BOX_P, and PG_RETURN_BOOL.

Referenced by gist_box_leaf_consistent(), rtree_internal_consistent(), and spg_box_quad_leaf_consistent().

518 {
519  BOX *box1 = PG_GETARG_BOX_P(0);
520  BOX *box2 = PG_GETARG_BOX_P(1);
521 
522  PG_RETURN_BOOL(box_ov(box1, box2));
523 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
static bool box_ov(BOX *box1, BOX *box2)
Definition: geo_ops.c:526
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324

◆ box_overleft()

Datum box_overleft ( PG_FUNCTION_ARGS  )

Definition at line 552 of file geo_ops.c.

References FPle, BOX::high, PG_GETARG_BOX_P, PG_RETURN_BOOL, and Point::x.

Referenced by gist_box_leaf_consistent(), rtree_internal_consistent(), and spg_box_quad_leaf_consistent().

553 {
554  BOX *box1 = PG_GETARG_BOX_P(0);
555  BOX *box2 = PG_GETARG_BOX_P(1);
556 
557  PG_RETURN_BOOL(FPle(box1->high.x, box2->high.x));
558 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
double x
Definition: geo_decls.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
Point high
Definition: geo_decls.h:104
#define FPle(A, B)
Definition: geo_decls.h:40

◆ box_overright()

Datum box_overright ( PG_FUNCTION_ARGS  )

Definition at line 578 of file geo_ops.c.

References FPge, BOX::low, PG_GETARG_BOX_P, PG_RETURN_BOOL, and Point::x.

Referenced by gist_box_leaf_consistent(), rtree_internal_consistent(), and spg_box_quad_leaf_consistent().

579 {
580  BOX *box1 = PG_GETARG_BOX_P(0);
581  BOX *box2 = PG_GETARG_BOX_P(1);
582 
583  PG_RETURN_BOOL(FPge(box1->low.x, box2->low.x));
584 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
double x
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define FPge(A, B)
Definition: geo_decls.h:42

◆ box_poly()

Datum box_poly ( PG_FUNCTION_ARGS  )

Definition at line 4455 of file geo_ops.c.

References POLYGON::boundbox, box_fill(), BOX::high, BOX::low, POLYGON::npts, offsetof, POLYGON::p, palloc(), PG_GETARG_BOX_P, PG_RETURN_POLYGON_P, SET_VARSIZE, Point::x, and Point::y.

4456 {
4457  BOX *box = PG_GETARG_BOX_P(0);
4458  POLYGON *poly;
4459  int size;
4460 
4461  /* map four corners of the box to a polygon */
4462  size = offsetof(POLYGON, p) + sizeof(poly->p[0]) * 4;
4463  poly = (POLYGON *) palloc(size);
4464 
4465  SET_VARSIZE(poly, size);
4466  poly->npts = 4;
4467 
4468  poly->p[0].x = box->low.x;
4469  poly->p[0].y = box->low.y;
4470  poly->p[1].x = box->low.x;
4471  poly->p[1].y = box->high.y;
4472  poly->p[2].x = box->high.x;
4473  poly->p[2].y = box->high.y;
4474  poly->p[3].x = box->high.x;
4475  poly->p[3].y = box->low.y;
4476 
4477  box_fill(&poly->boundbox, box->high.x, box->low.x,
4478  box->high.y, box->low.y);
4479 
4480  PG_RETURN_POLYGON_P(poly);
4481 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
double y
Definition: geo_decls.h:60
int32 npts
Definition: geo_decls.h:116
double x
Definition: geo_decls.h:60
static BOX * box_fill(BOX *result, double x1, double x2, double y1, double y2)
Definition: geo_ops.c:455
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:118
Point low
Definition: geo_decls.h:104
BOX boundbox
Definition: geo_decls.h:117
#define PG_RETURN_POLYGON_P(x)
Definition: geo_decls.h:169
Point high
Definition: geo_decls.h:104
void * palloc(Size size)
Definition: mcxt.c:924
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
#define offsetof(type, field)
Definition: c.h:622

◆ box_recv()

Datum box_recv ( PG_FUNCTION_ARGS  )

Definition at line 392 of file geo_ops.c.

References buf, BOX::high, BOX::low, palloc(), PG_GETARG_POINTER, PG_RETURN_BOX_P, pq_getmsgfloat8(), Point::x, and Point::y.

393 {
395  BOX *box;
396  double x,
397  y;
398 
399  box = (BOX *) palloc(sizeof(BOX));
400 
401  box->high.x = pq_getmsgfloat8(buf);
402  box->high.y = pq_getmsgfloat8(buf);
403  box->low.x = pq_getmsgfloat8(buf);
404  box->low.y = pq_getmsgfloat8(buf);
405 
406  /* reorder corners if necessary... */
407  if (box->high.x < box->low.x)
408  {
409  x = box->high.x;
410  box->high.x = box->low.x;
411  box->low.x = x;
412  }
413  if (box->high.y < box->low.y)
414  {
415  y = box->high.y;
416  box->high.y = box->low.y;
417  box->low.y = y;
418  }
419 
420  PG_RETURN_BOX_P(box);
421 }
Definition: geo_decls.h:102
StringInfoData * StringInfo
Definition: stringinfo.h:43
double y
Definition: geo_decls.h:60
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:246
double x
Definition: geo_decls.h:60
static char * buf
Definition: pg_test_fsync.c:67
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:162
float8 pq_getmsgfloat8(StringInfo msg)
Definition: pqformat.c:490
Point high
Definition: geo_decls.h:104
void * palloc(Size size)
Definition: mcxt.c:924

◆ box_right()

Datum box_right ( PG_FUNCTION_ARGS  )

Definition at line 563 of file geo_ops.c.

References FPgt, BOX::high, BOX::low, PG_GETARG_BOX_P, PG_RETURN_BOOL, and Point::x.

Referenced by gist_box_leaf_consistent(), rtree_internal_consistent(), and spg_box_quad_leaf_consistent().

564 {
565  BOX *box1 = PG_GETARG_BOX_P(0);
566  BOX *box2 = PG_GETARG_BOX_P(1);
567 
568  PG_RETURN_BOOL(FPgt(box1->low.x, box2->high.x));
569 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
double x
Definition: geo_decls.h:60
#define FPgt(A, B)
Definition: geo_decls.h:41
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
Point high
Definition: geo_decls.h:104

◆ box_same()

Datum box_same ( PG_FUNCTION_ARGS  )

Definition at line 503 of file geo_ops.c.

References FPeq, BOX::high, BOX::low, PG_GETARG_BOX_P, PG_RETURN_BOOL, Point::x, and Point::y.

Referenced by gist_box_leaf_consistent(), and spg_box_quad_leaf_consistent().

504 {
505  BOX *box1 = PG_GETARG_BOX_P(0);
506  BOX *box2 = PG_GETARG_BOX_P(1);
507 
508  PG_RETURN_BOOL(FPeq(box1->high.x, box2->high.x) &&
509  FPeq(box1->low.x, box2->low.x) &&
510  FPeq(box1->high.y, box2->high.y) &&
511  FPeq(box1->low.y, box2->low.y));
512 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
#define FPeq(A, B)
Definition: geo_decls.h:37
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
Point high
Definition: geo_decls.h:104

◆ box_send()

Datum box_send ( PG_FUNCTION_ARGS  )

Definition at line 427 of file geo_ops.c.

References buf, BOX::high, BOX::low, PG_GETARG_BOX_P, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), pq_sendfloat8(), Point::x, and Point::y.

428 {
429  BOX *box = PG_GETARG_BOX_P(0);
431 
432  pq_begintypsend(&buf);
433  pq_sendfloat8(&buf, box->high.x);
434  pq_sendfloat8(&buf, box->high.y);
435  pq_sendfloat8(&buf, box->low.x);
436  pq_sendfloat8(&buf, box->low.y);
438 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
void pq_sendfloat8(StringInfo buf, float8 f)
Definition: pqformat.c:278
double y
Definition: geo_decls.h:60
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:335
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
double x
Definition: geo_decls.h:60
static char * buf
Definition: pg_test_fsync.c:67
Point low
Definition: geo_decls.h:104
Point high
Definition: geo_decls.h:104

◆ box_sub()

Datum box_sub ( PG_FUNCTION_ARGS  )

Definition at line 4129 of file geo_ops.c.

References box_construct(), BOX::high, BOX::low, PG_GETARG_BOX_P, PG_GETARG_POINT_P, PG_RETURN_BOX_P, Point::x, and Point::y.

4130 {
4131  BOX *box = PG_GETARG_BOX_P(0);
4132  Point *p = PG_GETARG_POINT_P(1);
4133 
4134  PG_RETURN_BOX_P(box_construct((box->high.x - p->x),
4135  (box->low.x - p->x),
4136  (box->high.y - p->y),
4137  (box->low.y - p->y)));
4138 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:162
Point high
Definition: geo_decls.h:104
static BOX * box_construct(double x1, double x2, double y1, double y2)
Definition: geo_ops.c:444

◆ box_wd()

static double box_wd ( BOX box)
static

Definition at line 831 of file geo_ops.c.

References BOX::high, BOX::low, and Point::x.

Referenced by box_ar().

832 {
833  return box->high.x - box->low.x;
834 }
double x
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
Point high
Definition: geo_decls.h:104

◆ box_width()

Datum box_width ( PG_FUNCTION_ARGS  )

Definition at line 756 of file geo_ops.c.

References BOX::high, BOX::low, PG_GETARG_BOX_P, PG_RETURN_FLOAT8, and Point::x.

757 {
758  BOX *box = PG_GETARG_BOX_P(0);
759 
760  PG_RETURN_FLOAT8(box->high.x - box->low.x);
761 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
double x
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
Point high
Definition: geo_decls.h:104

◆ boxes_bound_box()

Datum boxes_bound_box ( PG_FUNCTION_ARGS  )

Definition at line 4205 of file geo_ops.c.

References BOX::high, BOX::low, Max, Min, palloc(), PG_GETARG_BOX_P, PG_RETURN_BOX_P, Point::x, and Point::y.

4206 {
4207  BOX *box1 = PG_GETARG_BOX_P(0),
4208  *box2 = PG_GETARG_BOX_P(1),
4209  *container;
4210 
4211  container = (BOX *) palloc(sizeof(BOX));
4212 
4213  container->high.x = Max(box1->high.x, box2->high.x);
4214  container->low.x = Min(box1->low.x, box2->low.x);
4215  container->high.y = Max(box1->high.y, box2->high.y);
4216  container->low.y = Min(box1->low.y, box2->low.y);
4217 
4218  PG_RETURN_BOX_P(container);
4219 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
#define Min(x, y)
Definition: c.h:857
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:162
#define Max(x, y)
Definition: c.h:851
Point high
Definition: geo_decls.h:104
void * palloc(Size size)
Definition: mcxt.c:924

◆ circle_above()

Datum circle_above ( PG_FUNCTION_ARGS  )

Definition at line 4770 of file geo_ops.c.

References CIRCLE::center, FPgt, PG_GETARG_CIRCLE_P, PG_RETURN_BOOL, CIRCLE::radius, and Point::y.

4771 {
4772  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4773  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4774 
4775  PG_RETURN_BOOL(FPgt((circle1->center.y - circle1->radius),
4776  (circle2->center.y + circle2->radius)));
4777 }
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
#define FPgt(A, B)
Definition: geo_decls.h:41
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126

◆ circle_add_pt()

Datum circle_add_pt ( PG_FUNCTION_ARGS  )

Definition at line 4886 of file geo_ops.c.

References CIRCLE::center, circle_copy(), PG_GETARG_CIRCLE_P, PG_GETARG_POINT_P, PG_RETURN_CIRCLE_P, Point::x, and Point::y.

4887 {
4888  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4889  Point *point = PG_GETARG_POINT_P(1);
4890  CIRCLE *result;
4891 
4892  result = circle_copy(circle);
4893 
4894  result->center.x += point->x;
4895  result->center.y += point->y;
4896 
4897  PG_RETURN_CIRCLE_P(result);
4898 }
double y
Definition: geo_decls.h:60
static CIRCLE * circle_copy(CIRCLE *circle)
Definition: geo_ops.c:4869
double x
Definition: geo_decls.h:60
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:174
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126

◆ circle_ar()

static double circle_ar ( CIRCLE circle)
static

Definition at line 5086 of file geo_ops.c.

References M_PI, and CIRCLE::radius.

Referenced by circle_area(), circle_eq(), circle_ge(), circle_gt(), circle_le(), circle_lt(), and circle_ne().

5087 {
5088  return M_PI * (circle->radius * circle->radius);
5089 }
double radius
Definition: geo_decls.h:127
#define M_PI
Definition: geo_ops.c:28

◆ circle_area()

Datum circle_area ( PG_FUNCTION_ARGS  )

Definition at line 4963 of file geo_ops.c.

References circle_ar(), PG_GETARG_CIRCLE_P, and PG_RETURN_FLOAT8.

4964 {
4965  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4966 
4967  PG_RETURN_FLOAT8(circle_ar(circle));
4968 }
static double circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5086
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173

◆ circle_below()

Datum circle_below ( PG_FUNCTION_ARGS  )

Definition at line 4758 of file geo_ops.c.

References CIRCLE::center, FPlt, PG_GETARG_CIRCLE_P, PG_RETURN_BOOL, CIRCLE::radius, and Point::y.

4759 {
4760  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4761  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4762 
4763  PG_RETURN_BOOL(FPlt((circle1->center.y + circle1->radius),
4764  (circle2->center.y - circle2->radius)));
4765 }
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
#define FPlt(A, B)
Definition: geo_decls.h:39
Point center
Definition: geo_decls.h:126

◆ circle_box()

Datum circle_box ( PG_FUNCTION_ARGS  )

Definition at line 5113 of file geo_ops.c.

References CIRCLE::center, BOX::high, BOX::low, palloc(), PG_GETARG_CIRCLE_P, PG_RETURN_BOX_P, CIRCLE::radius, Point::x, and Point::y.

5114 {
5115  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5116  BOX *box;
5117  double delta;
5118 
5119  box = (BOX *) palloc(sizeof(BOX));
5120 
5121  delta = circle->radius / sqrt(2.0);
5122 
5123  box->high.x = circle->center.x + delta;
5124  box->low.x = circle->center.x - delta;
5125  box->high.y = circle->center.y + delta;
5126  box->low.y = circle->center.y - delta;
5127 
5128  PG_RETURN_BOX_P(box);
5129 }
Definition: geo_decls.h:102
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:162
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point high
Definition: geo_decls.h:104
Point center
Definition: geo_decls.h:126
void * palloc(Size size)
Definition: mcxt.c:924

◆ circle_center()

Datum circle_center ( PG_FUNCTION_ARGS  )

Definition at line 5070 of file geo_ops.c.

References CIRCLE::center, palloc(), PG_GETARG_CIRCLE_P, PG_RETURN_POINT_P, Point::x, and Point::y.

Referenced by poly_center().

5071 {
5072  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5073  Point *result;
5074 
5075  result = (Point *) palloc(sizeof(Point));
5076  result->x = circle->center.x;
5077  result->y = circle->center.y;
5078 
5079  PG_RETURN_POINT_P(result);
5080 }
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:140
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126
void * palloc(Size size)
Definition: mcxt.c:924

◆ circle_contain()

Datum circle_contain ( PG_FUNCTION_ARGS  )

Definition at line 4746 of file geo_ops.c.

References CIRCLE::center, FPle, PG_GETARG_CIRCLE_P, PG_RETURN_BOOL, point_dt(), and CIRCLE::radius.

4747 {
4748  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4749  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4750 
4751  PG_RETURN_BOOL(FPle((point_dt(&circle1->center, &circle2->center) + circle2->radius), circle1->radius));
4752 }
double radius
Definition: geo_decls.h:127
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126
double point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1905
#define FPle(A, B)
Definition: geo_decls.h:40

◆ circle_contain_pt()

Datum circle_contain_pt ( PG_FUNCTION_ARGS  )

Definition at line 5012 of file geo_ops.c.

References CIRCLE::center, PG_GETARG_CIRCLE_P, PG_GETARG_POINT_P, PG_RETURN_BOOL, and point_dt().

Referenced by gist_point_consistent().

5013 {
5014  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5015  Point *point = PG_GETARG_POINT_P(1);
5016  double d;
5017 
5018  d = point_dt(&circle->center, point);
5019  PG_RETURN_BOOL(d <= circle->radius);
5020 }
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126
double point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1905

◆ circle_contained()

Datum circle_contained ( PG_FUNCTION_ARGS  )

Definition at line 4735 of file geo_ops.c.

References CIRCLE::center, FPle, PG_GETARG_CIRCLE_P, PG_RETURN_BOOL, point_dt(), and CIRCLE::radius.

4736 {
4737  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4738  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4739 
4740  PG_RETURN_BOOL(FPle((point_dt(&circle1->center, &circle2->center) + circle1->radius), circle2->radius));
4741 }
double radius
Definition: geo_decls.h:127
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126
double point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1905
#define FPle(A, B)
Definition: geo_decls.h:40

◆ circle_copy()

static CIRCLE * circle_copy ( CIRCLE circle)
static

Definition at line 4869 of file geo_ops.c.

References palloc(), and PointerIsValid.

Referenced by circle_add_pt(), circle_div_pt(), circle_mul_pt(), and circle_sub_pt().

4870 {
4871  CIRCLE *result;
4872 
4873  if (!PointerIsValid(circle))
4874  return NULL;
4875 
4876  result = (CIRCLE *) palloc(sizeof(CIRCLE));
4877  memcpy((char *) result, (char *) circle, sizeof(CIRCLE));
4878  return result;
4879 }
void * palloc(Size size)
Definition: mcxt.c:924
#define PointerIsValid(pointer)
Definition: c.h:593

◆ circle_diameter()

Datum circle_diameter ( PG_FUNCTION_ARGS  )

Definition at line 4974 of file geo_ops.c.

References PG_GETARG_CIRCLE_P, PG_RETURN_FLOAT8, and CIRCLE::radius.

4975 {
4976  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4977 
4978  PG_RETURN_FLOAT8(2 * circle->radius);
4979 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
double radius
Definition: geo_decls.h:127
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173

◆ circle_distance()

Datum circle_distance ( PG_FUNCTION_ARGS  )

Definition at line 4997 of file geo_ops.c.

References CIRCLE::center, PG_GETARG_CIRCLE_P, PG_RETURN_FLOAT8, point_dt(), and CIRCLE::radius.

4998 {
4999  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
5000  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
5001  float8 result;
5002 
5003  result = point_dt(&circle1->center, &circle2->center)
5004  - (circle1->radius + circle2->radius);
5005  if (result < 0)
5006  result = 0;
5007  PG_RETURN_FLOAT8(result);
5008 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
double radius
Definition: geo_decls.h:127
double float8
Definition: c.h:458
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126
double point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1905

◆ circle_div_pt()

Datum circle_div_pt ( PG_FUNCTION_ARGS  )

Definition at line 4940 of file geo_ops.c.

References CIRCLE::center, circle_copy(), DatumGetPointP, DirectFunctionCall2, HYPOT, PG_GETARG_CIRCLE_P, PG_GETARG_POINT_P, PG_RETURN_CIRCLE_P, point_div(), PointPGetDatum, CIRCLE::radius, Point::x, and Point::y.

4941 {
4942  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4943  Point *point = PG_GETARG_POINT_P(1);
4944  CIRCLE *result;
4945  Point *p;
4946 
4947  result = circle_copy(circle);
4948 
4950  PointPGetDatum(&circle->center),
4951  PointPGetDatum(point)));
4952  result->center.x = p->x;
4953  result->center.y = p->y;
4954  result->radius /= HYPOT(point->x, point->y);
4955 
4956  PG_RETURN_CIRCLE_P(result);
4957 }
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
static CIRCLE * circle_copy(CIRCLE *circle)
Definition: geo_ops.c:4869
double x
Definition: geo_decls.h:60
Datum point_div(PG_FUNCTION_ARGS)
Definition: geo_ops.c:4078
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:174
#define HYPOT(A, B)
Definition: geo_decls.h:53
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
#define DatumGetPointP(X)
Definition: geo_decls.h:137
Point center
Definition: geo_decls.h:126
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:592
#define PointPGetDatum(X)
Definition: geo_decls.h:138

◆ circle_eq()

Datum circle_eq ( PG_FUNCTION_ARGS  )

Definition at line 4810 of file geo_ops.c.

References circle_ar(), FPeq, PG_GETARG_CIRCLE_P, and PG_RETURN_BOOL.

4811 {
4812  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4813  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4814 
4815  PG_RETURN_BOOL(FPeq(circle_ar(circle1), circle_ar(circle2)));
4816 }
static double circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5086
#define FPeq(A, B)
Definition: geo_decls.h:37
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173

◆ circle_ge()

Datum circle_ge ( PG_FUNCTION_ARGS  )

Definition at line 4855 of file geo_ops.c.

References circle_ar(), FPge, PG_GETARG_CIRCLE_P, and PG_RETURN_BOOL.

4856 {
4857  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4858  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4859 
4860  PG_RETURN_BOOL(FPge(circle_ar(circle1), circle_ar(circle2)));
4861 }
static double circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5086
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
#define FPge(A, B)
Definition: geo_decls.h:42

◆ circle_gt()

Datum circle_gt ( PG_FUNCTION_ARGS  )

Definition at line 4837 of file geo_ops.c.

References circle_ar(), FPgt, PG_GETARG_CIRCLE_P, and PG_RETURN_BOOL.

4838 {
4839  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4840  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4841 
4842  PG_RETURN_BOOL(FPgt(circle_ar(circle1), circle_ar(circle2)));
4843 }
static double circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5086
#define FPgt(A, B)
Definition: geo_decls.h:41
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173

◆ circle_in()

Datum circle_in ( PG_FUNCTION_ARGS  )

Definition at line 4532 of file geo_ops.c.

References CIRCLE::center, DELIM, ereport, errcode(), errmsg(), ERROR, LDELIM, LDELIM_C, pair_decode(), palloc(), PG_GETARG_CSTRING, PG_RETURN_CIRCLE_P, CIRCLE::radius, RDELIM, RDELIM_C, single_decode(), generate_unaccent_rules::str, Point::x, and Point::y.

4533 {
4534  char *str = PG_GETARG_CSTRING(0);
4535  CIRCLE *circle = (CIRCLE *) palloc(sizeof(CIRCLE));
4536  char *s,
4537  *cp;
4538  int depth = 0;
4539 
4540  s = str;
4541  while (isspace((unsigned char) *s))
4542  s++;
4543  if ((*s == LDELIM_C) || (*s == LDELIM))
4544  {
4545  depth++;
4546  cp = (s + 1);
4547  while (isspace((unsigned char) *cp))
4548  cp++;
4549  if (*cp == LDELIM)
4550  s = cp;
4551  }
4552 
4553  pair_decode(s, &circle->center.x, &circle->center.y, &s, "circle", str);
4554 
4555  if (*s == DELIM)
4556  s++;
4557 
4558  circle->radius = single_decode(s, &s, "circle", str);
4559  if (circle->radius < 0)
4560  ereport(ERROR,
4561  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
4562  errmsg("invalid input syntax for type %s: \"%s\"",
4563  "circle", str)));
4564 
4565  while (depth > 0)
4566  {
4567  if ((*s == RDELIM)
4568  || ((*s == RDELIM_C) && (depth == 1)))
4569  {
4570  depth--;
4571  s++;
4572  while (isspace((unsigned char) *s))
4573  s++;
4574  }
4575  else
4576  ereport(ERROR,
4577  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
4578  errmsg("invalid input syntax for type %s: \"%s\"",
4579  "circle", str)));
4580  }
4581 
4582  if (*s != '\0')
4583  ereport(ERROR,
4584  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
4585  errmsg("invalid input syntax for type %s: \"%s\"",
4586  "circle", str)));
4587 
4588  PG_RETURN_CIRCLE_P(circle);
4589 }
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
static double single_decode(char *num, char **endptr_p, const char *type_name, const char *orig_string)
Definition: geo_ops.c:124
int errcode(int sqlerrcode)
Definition: elog.c:575
double x
Definition: geo_decls.h:60
#define DELIM
Definition: geo_ops.c:91
#define ERROR
Definition: elog.h:43
#define LDELIM
Definition: geo_ops.c:89
#define RDELIM
Definition: geo_ops.c:90
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:174
static void pair_decode(char *str, double *x, double *y, char **endptr_p, const char *type_name, const char *orig_string)
Definition: geo_ops.c:140
#define LDELIM_C
Definition: geo_ops.c:94
Point center
Definition: geo_decls.h:126
#define RDELIM_C
Definition: geo_ops.c:95
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:247

◆ circle_le()

Datum circle_le ( PG_FUNCTION_ARGS  )

Definition at line 4846 of file geo_ops.c.

References circle_ar(), FPle, PG_GETARG_CIRCLE_P, and PG_RETURN_BOOL.

4847 {
4848  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4849  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4850 
4851  PG_RETURN_BOOL(FPle(circle_ar(circle1), circle_ar(circle2)));
4852 }
static double circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5086
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
#define FPle(A, B)
Definition: geo_decls.h:40

◆ circle_left()

Datum circle_left ( PG_FUNCTION_ARGS  )

Definition at line 4698 of file geo_ops.c.

References CIRCLE::center, FPlt, PG_GETARG_CIRCLE_P, PG_RETURN_BOOL, CIRCLE::radius, and Point::x.

4699 {
4700  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4701  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4702 
4703  PG_RETURN_BOOL(FPlt((circle1->center.x + circle1->radius),
4704  (circle2->center.x - circle2->radius)));
4705 }
double radius
Definition: geo_decls.h:127
double x
Definition: geo_decls.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
#define FPlt(A, B)
Definition: geo_decls.h:39
Point center
Definition: geo_decls.h:126

◆ circle_lt()

Datum circle_lt ( PG_FUNCTION_ARGS  )

Definition at line 4828 of file geo_ops.c.

References circle_ar(), FPlt, PG_GETARG_CIRCLE_P, and PG_RETURN_BOOL.

4829 {
4830  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4831  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4832 
4833  PG_RETURN_BOOL(FPlt(circle_ar(circle1), circle_ar(circle2)));
4834 }
static double circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5086
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
#define FPlt(A, B)
Definition: geo_decls.h:39

◆ circle_mul_pt()

Datum circle_mul_pt ( PG_FUNCTION_ARGS  )

Definition at line 4920 of file geo_ops.c.

References CIRCLE::center, circle_copy(), DatumGetPointP, DirectFunctionCall2, HYPOT, PG_GETARG_CIRCLE_P, PG_GETARG_POINT_P, PG_RETURN_CIRCLE_P, point_mul(), PointPGetDatum, CIRCLE::radius, Point::x, and Point::y.

4921 {
4922  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4923  Point *point = PG_GETARG_POINT_P(1);
4924  CIRCLE *result;
4925  Point *p;
4926 
4927  result = circle_copy(circle);
4928 
4930  PointPGetDatum(&circle->center),
4931  PointPGetDatum(point)));
4932  result->center.x = p->x;
4933  result->center.y = p->y;
4934  result->radius *= HYPOT(point->x, point->y);
4935 
4936  PG_RETURN_CIRCLE_P(result);
4937 }
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
static CIRCLE * circle_copy(CIRCLE *circle)
Definition: geo_ops.c:4869
double x
Definition: geo_decls.h:60
Datum point_mul(PG_FUNCTION_ARGS)
Definition: geo_ops.c:4063
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:174
#define HYPOT(A, B)
Definition: geo_decls.h:53
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
#define DatumGetPointP(X)
Definition: geo_decls.h:137
Point center
Definition: geo_decls.h:126
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:592
#define PointPGetDatum(X)
Definition: geo_decls.h:138

◆ circle_ne()

Datum circle_ne ( PG_FUNCTION_ARGS  )

Definition at line 4819 of file geo_ops.c.

References circle_ar(), FPne, PG_GETARG_CIRCLE_P, and PG_RETURN_BOOL.

4820 {
4821  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4822  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4823 
4824  PG_RETURN_BOOL(FPne(circle_ar(circle1), circle_ar(circle2)));
4825 }
static double circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5086
#define FPne(A, B)
Definition: geo_decls.h:38
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173

◆ circle_out()

Datum circle_out ( PG_FUNCTION_ARGS  )

Definition at line 4594 of file geo_ops.c.

References appendStringInfoChar(), CIRCLE::center, StringInfoData::data, DELIM, initStringInfo(), LDELIM, LDELIM_C, pair_encode(), PG_GETARG_CIRCLE_P, PG_RETURN_CSTRING, CIRCLE::radius, RDELIM, RDELIM_C, single_encode(), generate_unaccent_rules::str, Point::x, and Point::y.

4595 {
4596  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4598 
4599  initStringInfo(&str);
4600 
4603  pair_encode(circle->center.x, circle->center.y, &str);
4605  appendStringInfoChar(&str, DELIM);
4606  single_encode(circle->radius, &str);
4608 
4609  PG_RETURN_CSTRING(str.data);
4610 }
static void single_encode(float8 x, StringInfo str)
Definition: geo_ops.c:131
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
static void pair_encode(float8 x, float8 y, StringInfo str)
Definition: geo_ops.c:182
double x
Definition: geo_decls.h:60
#define DELIM
Definition: geo_ops.c:91
#define LDELIM
Definition: geo_ops.c:89
#define RDELIM
Definition: geo_ops.c:90
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:169
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:327
#define LDELIM_C
Definition: geo_ops.c:94
Point center
Definition: geo_decls.h:126
#define RDELIM_C
Definition: geo_ops.c:95

◆ circle_overabove()

Datum circle_overabove ( PG_FUNCTION_ARGS  )

Definition at line 4796 of file geo_ops.c.

References CIRCLE::center, FPge, PG_GETARG_CIRCLE_P, PG_RETURN_BOOL, CIRCLE::radius, and Point::y.

4797 {
4798  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4799  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4800 
4801  PG_RETURN_BOOL(FPge((circle1->center.y - circle1->radius),
4802  (circle2->center.y - circle2->radius)));
4803 }
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126
#define FPge(A, B)
Definition: geo_decls.h:42

◆ circle_overbelow()

Datum circle_overbelow ( PG_FUNCTION_ARGS  )

Definition at line 4783 of file geo_ops.c.

References CIRCLE::center, FPle, PG_GETARG_CIRCLE_P, PG_RETURN_BOOL, CIRCLE::radius, and Point::y.

4784 {
4785  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4786  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4787 
4788  PG_RETURN_BOOL(FPle((circle1->center.y + circle1->radius),
4789  (circle2->center.y + circle2->radius)));
4790 }
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126
#define FPle(A, B)
Definition: geo_decls.h:40

◆ circle_overlap()

Datum circle_overlap ( PG_FUNCTION_ARGS  )

Definition at line 4673 of file geo_ops.c.

References CIRCLE::center, FPle, PG_GETARG_CIRCLE_P, PG_RETURN_BOOL, point_dt(), and CIRCLE::radius.

4674 {
4675  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4676  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4677 
4678  PG_RETURN_BOOL(FPle(point_dt(&circle1->center, &circle2->center),
4679  circle1->radius + circle2->radius));
4680 }
double radius
Definition: geo_decls.h:127
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126
double point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1905
#define FPle(A, B)
Definition: geo_decls.h:40

◆ circle_overleft()

Datum circle_overleft ( PG_FUNCTION_ARGS  )

Definition at line 4686 of file geo_ops.c.

References CIRCLE::center, FPle, PG_GETARG_CIRCLE_P, PG_RETURN_BOOL, CIRCLE::radius, and Point::x.

4687 {
4688  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4689  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4690 
4691  PG_RETURN_BOOL(FPle((circle1->center.x + circle1->radius),
4692  (circle2->center.x + circle2->radius)));
4693 }
double radius
Definition: geo_decls.h:127
double x
Definition: geo_decls.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126
#define FPle(A, B)
Definition: geo_decls.h:40

◆ circle_overright()

Datum circle_overright ( PG_FUNCTION_ARGS  )

Definition at line 4723 of file geo_ops.c.

References CIRCLE::center, FPge, PG_GETARG_CIRCLE_P, PG_RETURN_BOOL, CIRCLE::radius, and Point::x.

4724 {
4725  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4726  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4727 
4728  PG_RETURN_BOOL(FPge((circle1->center.x - circle1->radius),
4729  (circle2->center.x - circle2->radius)));
4730 }
double radius
Definition: geo_decls.h:127
double x
Definition: geo_decls.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126
#define FPge(A, B)
Definition: geo_decls.h:42

◆ circle_poly()

Datum circle_poly ( PG_FUNCTION_ARGS  )

Definition at line 5152 of file geo_ops.c.

References CIRCLE::center, ereport, errcode(), errmsg(), ERROR, FPzero, i, M_PI, make_bound_box(), POLYGON::npts, offsetof, POLYGON::p, palloc0(), PG_GETARG_CIRCLE_P, PG_GETARG_INT32, PG_RETURN_POLYGON_P, CIRCLE::radius, SET_VARSIZE, Point::x, and Point::y.

5153 {
5154  int32 npts = PG_GETARG_INT32(0);
5155  CIRCLE *circle = PG_GETARG_CIRCLE_P(1);
5156  POLYGON *poly;
5157  int base_size,
5158  size;
5159  int i;
5160  double angle;
5161  double anglestep;
5162 
5163  if (FPzero(circle->radius))
5164  ereport(ERROR,
5165  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5166  errmsg("cannot convert circle with radius zero to polygon")));
5167 
5168  if (npts < 2)
5169  ereport(ERROR,
5170  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5171  errmsg("must request at least 2 points")));
5172 
5173  base_size = sizeof(poly->p[0]) * npts;
5174  size = offsetof(POLYGON, p) + base_size;
5175 
5176  /* Check for integer overflow */
5177  if (base_size / npts != sizeof(poly->p[0]) || size <= base_size)
5178  ereport(ERROR,
5179  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
5180  errmsg("too many points requested")));
5181 
5182  poly = (POLYGON *) palloc0(size); /* zero any holes */
5183  SET_VARSIZE(poly, size);
5184  poly->npts = npts;
5185 
5186  anglestep = (2.0 * M_PI) / npts;
5187 
5188  for (i = 0; i < npts; i++)
5189  {
5190  angle = i * anglestep;
5191  poly->p[i].x = circle->center.x - (circle->radius * cos(angle));
5192  poly->p[i].y = circle->center.y + (circle->radius * sin(angle));
5193  }
5194 
5195  make_bound_box(poly);
5196 
5197  PG_RETURN_POLYGON_P(poly);
5198 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:239
#define FPzero(A)
Definition: geo_decls.h:36
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
int errcode(int sqlerrcode)
Definition: elog.c:575
int32 npts
Definition: geo_decls.h:116
signed int int32
Definition: c.h:313
double x
Definition: geo_decls.h:60
#define ERROR
Definition: elog.h:43
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:118
#define ereport(elevel, rest)
Definition: elog.h:122
void * palloc0(Size size)
Definition: mcxt.c:955
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
static void make_bound_box(POLYGON *poly)
Definition: geo_ops.c:3376
#define PG_RETURN_POLYGON_P(x)
Definition: geo_decls.h:169
Point center
Definition: geo_decls.h:126
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define M_PI
Definition: geo_ops.c:28
int i
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
#define offsetof(type, field)
Definition: c.h:622

◆ circle_radius()

Datum circle_radius ( PG_FUNCTION_ARGS  )

Definition at line 4985 of file geo_ops.c.

References PG_GETARG_CIRCLE_P, PG_RETURN_FLOAT8, and CIRCLE::radius.

4986 {
4987  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4988 
4989  PG_RETURN_FLOAT8(circle->radius);
4990 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
double radius
Definition: geo_decls.h:127
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173

◆ circle_recv()

Datum circle_recv ( PG_FUNCTION_ARGS  )

Definition at line 4616 of file geo_ops.c.

References buf, CIRCLE::center, ereport, errcode(), errmsg(), ERROR, palloc(), PG_GETARG_POINTER, PG_RETURN_CIRCLE_P, pq_getmsgfloat8(), CIRCLE::radius, Point::x, and Point::y.

4617 {
4619  CIRCLE *circle;
4620 
4621  circle = (CIRCLE *) palloc(sizeof(CIRCLE));
4622 
4623  circle->center.x = pq_getmsgfloat8(buf);
4624  circle->center.y = pq_getmsgfloat8(buf);
4625  circle->radius = pq_getmsgfloat8(buf);
4626 
4627  if (circle->radius < 0)
4628  ereport(ERROR,
4629  (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
4630  errmsg("invalid radius in external \"circle\" value")));
4631 
4632  PG_RETURN_CIRCLE_P(circle);
4633 }
StringInfoData * StringInfo
Definition: stringinfo.h:43
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:246
double x
Definition: geo_decls.h:60
#define ERROR
Definition: elog.h:43
static char * buf
Definition: pg_test_fsync.c:67
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:174
float8 pq_getmsgfloat8(StringInfo msg)
Definition: pqformat.c:490
Point center
Definition: geo_decls.h:126
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ circle_right()

Datum circle_right ( PG_FUNCTION_ARGS  )

Definition at line 4710 of file geo_ops.c.

References CIRCLE::center, FPgt, PG_GETARG_CIRCLE_P, PG_RETURN_BOOL, CIRCLE::radius, and Point::x.

4711 {
4712  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4713  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4714 
4715  PG_RETURN_BOOL(FPgt((circle1->center.x - circle1->radius),
4716  (circle2->center.x + circle2->radius)));
4717 }
double radius
Definition: geo_decls.h:127
double x
Definition: geo_decls.h:60
#define FPgt(A, B)
Definition: geo_decls.h:41
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126

◆ circle_same()

Datum circle_same ( PG_FUNCTION_ARGS  )

Definition at line 4660 of file geo_ops.c.

References CIRCLE::center, FPeq, PG_GETARG_CIRCLE_P, PG_RETURN_BOOL, CIRCLE::radius, Point::x, and Point::y.

4661 {
4662  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4663  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4664 
4665  PG_RETURN_BOOL(FPeq(circle1->radius, circle2->radius) &&
4666  FPeq(circle1->center.x, circle2->center.x) &&
4667  FPeq(circle1->center.y, circle2->center.y));
4668 }
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
#define FPeq(A, B)
Definition: geo_decls.h:37
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126

◆ circle_send()

Datum circle_send ( PG_FUNCTION_ARGS  )

Definition at line 4639 of file geo_ops.c.

References buf, CIRCLE::center, PG_GETARG_CIRCLE_P, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), pq_sendfloat8(), CIRCLE::radius, Point::x, and Point::y.

4640 {
4641  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4643 
4644  pq_begintypsend(&buf);
4645  pq_sendfloat8(&buf, circle->center.x);
4646  pq_sendfloat8(&buf, circle->center.y);
4647  pq_sendfloat8(&buf, circle->radius);
4649 }
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
void pq_sendfloat8(StringInfo buf, float8 f)
Definition: pqformat.c:278
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:335
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
double x
Definition: geo_decls.h:60
static char * buf
Definition: pg_test_fsync.c:67
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126

◆ circle_sub_pt()

Datum circle_sub_pt ( PG_FUNCTION_ARGS  )

Definition at line 4901 of file geo_ops.c.

References CIRCLE::center, circle_copy(), PG_GETARG_CIRCLE_P, PG_GETARG_POINT_P, PG_RETURN_CIRCLE_P, Point::x, and Point::y.

4902 {
4903  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4904  Point *point = PG_GETARG_POINT_P(1);
4905  CIRCLE *result;
4906 
4907  result = circle_copy(circle);
4908 
4909  result->center.x -= point->x;
4910  result->center.y -= point->y;
4911 
4912  PG_RETURN_CIRCLE_P(result);
4913 }
double y
Definition: geo_decls.h:60
static CIRCLE * circle_copy(CIRCLE *circle)
Definition: geo_ops.c:4869
double x
Definition: geo_decls.h:60
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:174
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126

◆ close_lb()

Datum close_lb ( PG_FUNCTION_ARGS  )

Definition at line 3106 of file geo_ops.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_BOX_P, PG_GETARG_LINE_P, and PG_RETURN_NULL.

3107 {
3108 #ifdef NOT_USED
3109  LINE *line = PG_GETARG_LINE_P(0);
3110  BOX *box = PG_GETARG_BOX_P(1);
3111 #endif
3112 
3113  /* think about this one for a while */
3114  ereport(ERROR,
3115  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3116  errmsg("function \"close_lb\" not implemented")));
3117 
3118  PG_RETURN_NULL();
3119 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:156
#define ERROR
Definition: elog.h:43
Definition: geo_decls.h:90
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_RETURN_NULL()
Definition: fmgr.h:310

◆ close_ls()

Datum close_ls ( PG_FUNCTION_ARGS  )

Definition at line 3023 of file geo_ops.c.

References dist_pl_internal(), interpt_sl(), LSEG::p, PG_GETARG_LINE_P, PG_GETARG_LSEG_P, PG_RETURN_POINT_P, and point_copy().

3024 {
3025  LINE *line = PG_GETARG_LINE_P(0);
3026  LSEG *lseg = PG_GETARG_LSEG_P(1);
3027  Point *result;
3028  float8 d1,
3029  d2;
3030 
3031  result = interpt_sl(lseg, line);
3032  if (result)
3033  PG_RETURN_POINT_P(result);
3034 
3035  d1 = dist_pl_internal(&lseg->p[0], line);
3036  d2 = dist_pl_internal(&lseg->p[1], line);
3037  if (d1 < d2)
3038  result = point_copy(&lseg->p[0]);
3039  else
3040  result = point_copy(&lseg->p[1]);
3041 
3042  PG_RETURN_POINT_P(result);
3043 }
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:144
static Point * interpt_sl(LSEG *lseg, LINE *line)
Definition: geo_ops.c:2660
Definition: geo_decls.h:68
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:156
double float8
Definition: c.h:458
Definition: geo_decls.h:90
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:140
static Point * point_copy(Point *pt)
Definition: geo_ops.c:1795
Point p[2]
Definition: geo_decls.h:70
static double dist_pl_internal(Point *pt, LINE *line)
Definition: geo_ops.c:2347

◆ close_lseg()

Datum close_lseg ( PG_FUNCTION_ARGS  )

Definition at line 2879 of file geo_ops.c.

References close_ps(), DatumGetPointP, DirectFunctionCall2, dist_ps_internal(), LsegPGetDatum, LSEG::p, PG_GETARG_LSEG_P, PG_RETURN_POINT_P, point_copy(), and PointPGetDatum.

Referenced by close_sb().

2880 {
2881  LSEG *l1 = PG_GETARG_LSEG_P(0);
2882  LSEG *l2 = PG_GETARG_LSEG_P(1);
2883  Point *result = NULL;
2884  Point point;
2885  double dist;
2886  double d;
2887 
2888  d = dist_ps_internal(&l1->p[0], l2);
2889  dist = d;
2890  memcpy(&point, &l1->p[0], sizeof(Point));
2891 
2892  if ((d = dist_ps_internal(&l1->p[1], l2)) < dist)
2893  {
2894  dist = d;
2895  memcpy(&point, &l1->p[1], sizeof(Point));
2896  }
2897 
2898  if (dist_ps_internal(&l2->p[0], l1) < dist)
2899  {
2901  PointPGetDatum(&l2->p[0]),
2902  LsegPGetDatum(l1)));
2903  memcpy(&point, result, sizeof(Point));
2905  PointPGetDatum(&point),
2906  LsegPGetDatum(l2)));
2907  }
2908 
2909  if (dist_ps_internal(&l2->p[1], l1) < dist)
2910  {
2912  PointPGetDatum(&l2->p[1]),
2913  LsegPGetDatum(l1)));
2914  memcpy(&point, result, sizeof(Point));
2916  PointPGetDatum(&point),
2917  LsegPGetDatum(l2)));
2918  }
2919 
2920  if (result == NULL)
2921  result = point_copy(&point);
2922 
2923  PG_RETURN_POINT_P(result);
2924 }
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:144
Definition: geo_decls.h:68
#define LsegPGetDatum(X)
Definition: geo_decls.h:143
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:140
static Point * point_copy(Point *pt)
Definition: geo_ops.c:1795
static double dist_ps_internal(Point *pt, LSEG *lseg)
Definition: geo_ops.c:2366
#define DatumGetPointP(X)
Definition: geo_decls.h:137
Point p[2]
Definition: geo_decls.h:70
Datum close_ps(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2757
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:592
#define PointPGetDatum(X)
Definition: geo_decls.h:138

◆ close_pb()

Datum close_pb ( PG_FUNCTION_ARGS  )

Definition at line 2930 of file geo_ops.c.

References BoxPGetDatum, close_ps(), DatumGetBool, DirectFunctionCall2, dist_ps_internal(), BOX::high, BOX::low, LsegPGetDatum, on_pb(), PG_GETARG_BOX_P, PG_GETARG_POINT_P, PG_RETURN_DATUM, PG_RETURN_POINT_P, PointPGetDatum, statlseg_construct(), Point::x, and Point::y.

Referenced by dist_pb().

2931 {
2932  Point *pt = PG_GETARG_POINT_P(0);
2933  BOX *box = PG_GETARG_BOX_P(1);
2934  LSEG lseg,
2935  seg;
2936  Point point;
2937  double dist,
2938  d;
2939 
2941  PointPGetDatum(pt),
2942  BoxPGetDatum(box))))
2943  PG_RETURN_POINT_P(pt);
2944 
2945  /* pairwise check lseg distances */
2946  point.x = box->low.x;
2947  point.y = box->high.y;
2948  statlseg_construct(&lseg, &box->low, &point);
2949  dist = dist_ps_internal(pt, &lseg);
2950 
2951  statlseg_construct(&seg, &box->high, &point);
2952  if ((d = dist_ps_internal(pt, &seg)) < dist)
2953  {
2954  dist = d;
2955  memcpy(&lseg, &seg, sizeof(lseg));
2956  }
2957 
2958  point.x = box->high.x;
2959  point.y = box->low.y;
2960  statlseg_construct(&seg, &box->low, &point);
2961  if ((d = dist_ps_internal(pt, &seg)) < dist)
2962  {
2963  dist = d;
2964  memcpy(&lseg, &seg, sizeof(lseg));
2965  }
2966 
2967  statlseg_construct(&seg, &box->high, &point);
2968  if ((d = dist_ps_internal(pt, &seg)) < dist)
2969  {
2970  dist = d;
2971  memcpy(&lseg, &seg, sizeof(lseg));
2972  }
2973 
2975  PointPGetDatum(pt),
2976  LsegPGetDatum(&lseg)));
2977 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
static void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: geo_ops.c:2025
Definition: geo_decls.h:68
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
#define LsegPGetDatum(X)
Definition: geo_decls.h:143
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:140
#define DatumGetBool(X)
Definition: postgres.h:378
Datum on_pb(PG_FUNCTION_ARGS)
Definition: geo_ops.c:3160
Point low
Definition: geo_decls.h:104
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:318
#define BoxPGetDatum(X)
Definition: geo_decls.h:160
static double dist_ps_internal(Point *pt, LSEG *lseg)
Definition: geo_ops.c:2366
Point high
Definition: geo_decls.h:104
Datum close_ps(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2757
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:592
#define PointPGetDatum(X)
Definition: geo_decls.h:138

◆ close_pl()

Datum close_pl ( PG_FUNCTION_ARGS  )

Definition at line 2713 of file geo_ops.c.

References LINE::A, Assert, LINE::B, LINE::C, FPzero, line_construct_pm(), line_interpt_internal(), palloc(), PG_GETARG_LINE_P, PG_GETARG_POINT_P, PG_RETURN_POINT_P, Point::x, and Point::y.

2714 {
2715  Point *pt = PG_GETARG_POINT_P(0);
2716  LINE *line = PG_GETARG_LINE_P(1);
2717  Point *result;
2718  LINE *tmp;
2719  double invm;
2720 
2721  result = (Point *) palloc(sizeof(Point));
2722 
2723  if (FPzero(line->B)) /* vertical? */
2724  {
2725  result->x = line->C;
2726  result->y = pt->y;
2727  PG_RETURN_POINT_P(result);
2728  }
2729  if (FPzero(line->A)) /* horizontal? */
2730  {
2731  result->x = pt->x;
2732  result->y = line->C;
2733  PG_RETURN_POINT_P(result);
2734  }
2735  /* drop a perpendicular and find the intersection point */
2736 
2737  /* invert and flip the sign on the slope to get a perpendicular */
2738  invm = line->B / line->A;
2739  tmp = line_construct_pm(pt, invm);
2740  result = line_interpt_internal(tmp, line);
2741  Assert(result != NULL);
2742  PG_RETURN_POINT_P(result);
2743 }
double A
Definition: geo_decls.h:92
static Point * line_interpt_internal(LINE *l1, LINE *l2)
Definition: geo_ops.c:1217
#define FPzero(A)
Definition: geo_decls.h:36
static LINE * line_construct_pm(Point *pt, double m)
Definition: geo_ops.c:1010
double y
Definition: geo_decls.h:60
double B
Definition: geo_decls.h:92
double x
Definition: geo_decls.h:60
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:156
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
Definition: geo_decls.h:90
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:140
#define Assert(condition)
Definition: c.h:699
double C
Definition: geo_decls.h:92
void * palloc(Size size)
Definition: mcxt.c:924

◆ close_ps()

Datum close_ps ( PG_FUNCTION_ARGS  )

Definition at line 2757 of file geo_ops.c.

References LINE::A, LINE::B, LINE::C, FPeq, interpt_sl(), line_construct_pm(), LSEG::p, palloc(), PG_GETARG_LSEG_P, PG_GETARG_POINT_P, PG_RETURN_NULL, PG_RETURN_POINT_P, point_copy(), point_sl(), Point::x, and Point::y.

Referenced by close_lseg(), close_pb(), and close_sb().

2758 {
2759  Point *pt = PG_GETARG_POINT_P(0);
2760  LSEG *lseg = PG_GETARG_LSEG_P(1);
2761  Point *result = NULL;
2762  LINE *tmp;
2763  double invm;
2764  int xh,
2765  yh;
2766 
2767 #ifdef GEODEBUG
2768  printf("close_sp:pt->x %f pt->y %f\nlseg(0).x %f lseg(0).y %f lseg(1).x %f lseg(1).y %f\n",
2769  pt->x, pt->y, lseg->p[0].x, lseg->p[0].y,
2770  lseg->p[1].x, lseg->p[1].y);
2771 #endif
2772 
2773  /* xh (or yh) is the index of upper x( or y) end point of lseg */
2774  /* !xh (or !yh) is the index of lower x( or y) end point of lseg */
2775  xh = lseg->p[0].x < lseg->p[1].x;
2776  yh = lseg->p[0].y < lseg->p[1].y;
2777 
2778  if (FPeq(lseg->p[0].x, lseg->p[1].x)) /* vertical? */
2779  {
2780 #ifdef GEODEBUG
2781  printf("close_ps- segment is vertical\n");
2782 #endif
2783  /* first check if point is below or above the entire lseg. */
2784  if (pt->y < lseg->p[!yh].y)
2785  result = point_copy(&lseg->p[!yh]); /* below the lseg */
2786  else if (pt->y > lseg->p[yh].y)
2787  result = point_copy(&lseg->p[yh]); /* above the lseg */
2788  if (result != NULL)
2789  PG_RETURN_POINT_P(result);
2790 
2791  /* point lines along (to left or right) of the vertical lseg. */
2792 
2793  result = (Point *) palloc(sizeof(Point));
2794  result->x = lseg->p[0].x;
2795  result->y = pt->y;
2796  PG_RETURN_POINT_P(result);
2797  }
2798  else if (FPeq(lseg->p[0].y, lseg->p[1].y)) /* horizontal? */
2799  {
2800 #ifdef GEODEBUG
2801  printf("close_ps- segment is horizontal\n");
2802 #endif
2803  /* first check if point is left or right of the entire lseg. */
2804  if (pt->x < lseg->p[!xh].x)
2805  result = point_copy(&lseg->p[!xh]); /* left of the lseg */
2806  else if (pt->x > lseg->p[xh].x)
2807  result = point_copy(&lseg->p[xh]); /* right of the lseg */
2808  if (result != NULL)
2809  PG_RETURN_POINT_P(result);
2810 
2811  /* point lines along (at top or below) the horiz. lseg. */
2812  result = (Point *) palloc(sizeof(Point));
2813  result->x = pt->x;
2814  result->y = lseg->p[0].y;
2815  PG_RETURN_POINT_P(result);
2816  }
2817 
2818  /*
2819  * vert. and horiz. cases are down, now check if the closest point is one
2820  * of the end points or someplace on the lseg.
2821  */
2822 
2823  invm = -1.0 / point_sl(&(lseg->p[0]), &(lseg->p[1]));
2824  tmp = line_construct_pm(&lseg->p[!yh], invm); /* lower edge of the
2825  * "band" */
2826  if (pt->y < (tmp->A * pt->x + tmp->C))
2827  { /* we are below the lower edge */
2828  result = point_copy(&lseg->p[!yh]); /* below the lseg, take lower end
2829  * pt */
2830 #ifdef GEODEBUG
2831  printf("close_ps below: tmp A %f B %f C %f\n",
2832  tmp->A, tmp->B, tmp->C);
2833 #endif
2834  PG_RETURN_POINT_P(result);
2835  }
2836  tmp = line_construct_pm(&lseg->p[yh], invm); /* upper edge of the
2837  * "band" */
2838  if (pt->y > (tmp->A * pt->x + tmp->C))
2839  { /* we are below the lower edge */
2840  result = point_copy(&lseg->p[yh]); /* above the lseg, take higher end
2841  * pt */
2842 #ifdef GEODEBUG
2843  printf("close_ps above: tmp A %f B %f C %f\n",
2844  tmp->A, tmp->B, tmp->C);
2845 #endif
2846  PG_RETURN_POINT_P(result);
2847  }
2848 
2849  /*
2850  * at this point the "normal" from point will hit lseg. The closest point
2851  * will be somewhere on the lseg
2852  */
2853  tmp = line_construct_pm(pt, invm);
2854 #ifdef GEODEBUG
2855  printf("close_ps- tmp A %f B %f C %f\n",
2856  tmp->A, tmp->B, tmp->C);
2857 #endif
2858  result = interpt_sl(lseg, tmp);
2859 
2860  /*
2861  * ordinarily we should always find an intersection point, but that could
2862  * fail in the presence of NaN coordinates, and perhaps even from simple
2863  * roundoff issues. Return a SQL NULL if so.
2864  */
2865  if (result == NULL)
2866  PG_RETURN_NULL();
2867 
2868 #ifdef GEODEBUG
2869  printf("close_ps- result.x %f result.y %f\n", result->x, result->y);
2870 #endif
2871  PG_RETURN_POINT_P(result);
2872 }
double A
Definition: geo_decls.h:92
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:144
static Point * interpt_sl(LSEG *lseg, LINE *line)
Definition: geo_ops.c:2660
static LINE * line_construct_pm(Point *pt, double m)
Definition: geo_ops.c:1010
Definition: geo_decls.h:68
double y
Definition: geo_decls.h:60
double point_sl(Point *pt1, Point *pt2)
Definition: geo_ops.c:1925
double B
Definition: geo_decls.h:92
double x
Definition: geo_decls.h:60
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
Definition: geo_decls.h:90
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:140
static Point * point_copy(Point *pt)
Definition: geo_ops.c:1795
#define FPeq(A, B)
Definition: geo_decls.h:37
Point p[2]
Definition: geo_decls.h:70
double C
Definition: geo_decls.h:92
void * palloc(Size size)
Definition: mcxt.c:924
#define PG_RETURN_NULL()
Definition: fmgr.h:310

◆ close_sb()

Datum close_sb ( PG_FUNCTION_ARGS  )

Definition at line 3049 of file geo_ops.c.

References box_cn(), BoxPGetDatum, close_lseg(), close_ps(), DatumGetBool, DirectFunctionCall2, BOX::high, inter_sb(), BOX::low, lseg_dt(), LsegPGetDatum, PG_GETARG_BOX_P, PG_GETARG_LSEG_P, PG_RETURN_DATUM, PointPGetDatum, statlseg_construct(), Point::x, and Point::y.

Referenced by dist_sb().

3050 {
3051  LSEG *lseg = PG_GETARG_LSEG_P(0);
3052  BOX *box = PG_GETARG_BOX_P(1);
3053  Point point;
3054  LSEG bseg,
3055  seg;
3056  double dist,
3057  d;
3058 
3059  /* segment intersects box? then just return closest point to center */
3061  LsegPGetDatum(lseg),
3062  BoxPGetDatum(box))))
3063  {
3064  box_cn(&point, box);
3066  PointPGetDatum(&point),
3067  LsegPGetDatum(lseg)));
3068  }
3069 
3070  /* pairwise check lseg distances */
3071  point.x = box->low.x;
3072  point.y = box->high.y;
3073  statlseg_construct(&bseg, &box->low, &point);
3074  dist = lseg_dt(lseg, &bseg);
3075 
3076  statlseg_construct(&seg, &box->high, &point);
3077  if ((d = lseg_dt(lseg, &seg)) < dist)
3078  {
3079  dist = d;
3080  memcpy(&bseg, &seg, sizeof(bseg));
3081  }
3082 
3083  point.x = box->high.x;
3084  point.y = box->low.y;
3085  statlseg_construct(&seg, &box->low, &point);
3086  if ((d = lseg_dt(lseg, &seg)) < dist)
3087  {
3088  dist = d;
3089  memcpy(&bseg, &seg, sizeof(bseg));
3090  }
3091 
3092  statlseg_construct(&seg, &box->high, &point);
3093  if ((d = lseg_dt(lseg, &seg)) < dist)
3094  {
3095  dist = d;
3096  memcpy(&bseg, &seg, sizeof(bseg));
3097  }
3098 
3099  /* OK, we now have the closest line segment on the box boundary */
3101  LsegPGetDatum(lseg),
3102  LsegPGetDatum(&bseg)));
3103 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:144
static void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: geo_ops.c:2025
Definition: geo_decls.h:68
Datum inter_sb(PG_FUNCTION_ARGS)
Definition: geo_ops.c:3273
double y
Definition: geo_decls.h:60
static void box_cn(Point *center, BOX *box)
Definition: geo_ops.c:820
double x
Definition: geo_decls.h:60
static double lseg_dt(LSEG *l1, LSEG *l2)
Definition: geo_ops.c:2222
#define LsegPGetDatum(X)
Definition: geo_decls.h:143
#define DatumGetBool(X)
Definition: postgres.h:378
Point low
Definition: geo_decls.h:104
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:318
#define BoxPGetDatum(X)
Definition: geo_decls.h:160
Point high
Definition: geo_decls.h:104
Datum close_ps(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2757
Datum close_lseg(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2879
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:592
#define PointPGetDatum(X)
Definition: geo_decls.h:138

◆ close_sl()

Datum close_sl ( PG_FUNCTION_ARGS  )

Definition at line 2989 of file geo_ops.c.

References dist_pl_internal(), ereport, errcode(), errmsg(), ERROR, interpt_sl(), LSEG::p, PG_GETARG_LINE_P, PG_GETARG_LSEG_P, PG_RETURN_NULL, PG_RETURN_POINT_P, and point_copy().

2990 {
2991 #ifdef NOT_USED
2992  LSEG *lseg = PG_GETARG_LSEG_P(0);
2993  LINE *line = PG_GETARG_LINE_P(1);
2994  Point *result;
2995  float8 d1,
2996  d2;
2997 
2998  result = interpt_sl(lseg, line);
2999  if (result)
3000  PG_RETURN_POINT_P(result);
3001 
3002  d1 = dist_pl_internal(&lseg->p[0], line);
3003  d2 = dist_pl_internal(&lseg->p[1], line);
3004  if (d1 < d2)
3005  result = point_copy(&lseg->p[0]);
3006  else
3007  result = point_copy(&lseg->p[1]);
3008 
3009  PG_RETURN_POINT_P(result);
3010 #endif
3011 
3012  ereport(ERROR,
3013  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3014  errmsg("function \"close_sl\" not implemented")));
3015 
3016  PG_RETURN_NULL();
3017 }
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:144
static Point * interpt_sl(LSEG *lseg, LINE *line)
Definition: geo_ops.c:2660
Definition: geo_decls.h:68
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:156
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:458
Definition: geo_decls.h:90
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:140
static Point * point_copy(Point *pt)
Definition: geo_ops.c:1795
#define ereport(elevel, rest)
Definition: elog.h:122
Point p[2]
Definition: geo_decls.h:70
static double dist_pl_internal(Point *pt, LINE *line)
Definition: geo_ops.c:2347
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_RETURN_NULL()
Definition: fmgr.h:310

◆ construct_point()

Datum construct_point ( PG_FUNCTION_ARGS  )

Definition at line 4024 of file geo_ops.c.

References PG_GETARG_FLOAT8, PG_RETURN_POINT_P, and point_construct().

4025 {
4026  float8 x = PG_GETARG_FLOAT8(0);
4027  float8 y = PG_GETARG_FLOAT8(1);
4028 
4030 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:251
static Point * point_construct(double x, double y)
Definition: geo_ops.c:1784
double float8
Definition: c.h:458
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:140

◆ cr_circle()

Datum cr_circle ( PG_FUNCTION_ARGS  )

Definition at line 5097 of file geo_ops.c.

References CIRCLE::center, palloc(), PG_GETARG_FLOAT8, PG_GETARG_POINT_P, PG_RETURN_CIRCLE_P, CIRCLE::radius, Point::x, and Point::y.

5098 {
5099  Point *center = PG_GETARG_POINT_P(0);
5100  float8 radius = PG_GETARG_FLOAT8(1);
5101  CIRCLE *result;
5102 
5103  result = (CIRCLE *) palloc(sizeof(CIRCLE));
5104 
5105  result->center.x = center->x;
5106  result->center.y = center->y;
5107  result->radius = radius;
5108 
5109  PG_RETURN_CIRCLE_P(result);
5110 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:251
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
double float8
Definition: c.h:458
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:174
Point center
Definition: geo_decls.h:126
void * palloc(Size size)
Definition: mcxt.c:924

◆ dist_cpoint()

Datum dist_cpoint ( PG_FUNCTION_ARGS  )

Definition at line 5055 of file geo_ops.c.

References CIRCLE::center, PG_GETARG_CIRCLE_P, PG_GETARG_POINT_P, PG_RETURN_FLOAT8, point_dt(), and CIRCLE::radius.

5056 {
5057  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5058  Point *point = PG_GETARG_POINT_P(1);
5059  float8 result;
5060 
5061  result = point_dt(point, &circle->center) - circle->radius;
5062  if (result < 0)
5063  result = 0;
5064  PG_RETURN_FLOAT8(result);
5065 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
double radius
Definition: geo_decls.h:127
double float8
Definition: c.h:458
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126
double point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1905

◆ dist_cpoly()

Datum dist_cpoly ( PG_FUNCTION_ARGS  )

Definition at line 2563 of file geo_ops.c.

References CIRCLE::center, dist_ppoly_internal(), PG_GETARG_CIRCLE_P, PG_GETARG_POLYGON_P, PG_RETURN_FLOAT8, and CIRCLE::radius.

2564 {
2565  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
2566  POLYGON *poly = PG_GETARG_POLYGON_P(1);
2567  float8 result;
2568 
2569  /* calculate distance to center, and subtract radius */
2570  result = dist_ppoly_internal(&circle->center, poly);
2571 
2572  result -= circle->radius;
2573  if (result < 0)
2574  result = 0;
2575 
2576  PG_RETURN_FLOAT8(result);
2577 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
double radius
Definition: geo_decls.h:127
#define PG_GETARG_POLYGON_P(n)
Definition: geo_decls.h:167
double float8
Definition: c.h:458
static double dist_ppoly_internal(Point *pt, POLYGON *poly)
Definition: geo_ops.c:2607
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126

◆ dist_lb()

Datum dist_lb ( PG_FUNCTION_ARGS  )

Definition at line 2544 of file geo_ops.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_BOX_P, PG_GETARG_LINE_P, and PG_RETURN_NULL.

2545 {
2546 #ifdef NOT_USED
2547  LINE *line = PG_GETARG_LINE_P(0);
2548  BOX *box = PG_GETARG_BOX_P(1);
2549 #endif
2550 
2551  /* need to think about this one for a while */
2552  ereport(ERROR,
2553  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2554  errmsg("function \"dist_lb\" not implemented")));
2555 
2556  PG_RETURN_NULL();
2557 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:156
#define ERROR
Definition: elog.h:43
Definition: geo_decls.h:90
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_RETURN_NULL()
Definition: fmgr.h:310

◆ dist_pb()

Datum dist_pb ( PG_FUNCTION_ARGS  )

Definition at line 2479 of file geo_ops.c.

References BoxPGetDatum, close_pb(), DatumGetPointP, DirectFunctionCall2, PG_GETARG_BOX_P, PG_GETARG_POINT_P, PG_RETURN_FLOAT8, point_dt(), and PointPGetDatum.

Referenced by dist_sb().

2480 {
2481  Point *pt = PG_GETARG_POINT_P(0);
2482  BOX *box = PG_GETARG_BOX_P(1);
2483  float8 result;
2484  Point *near;
2485 
2487  PointPGetDatum(pt),
2488  BoxPGetDatum(box)));
2489  result = point_dt(near, pt);
2490 
2491  PG_RETURN_FLOAT8(result);
2492 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
double float8
Definition: c.h:458
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
Datum close_pb(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2930
#define BoxPGetDatum(X)
Definition: geo_decls.h:160
#define DatumGetPointP(X)
Definition: geo_decls.h:137
double point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1905
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:592
#define PointPGetDatum(X)
Definition: geo_decls.h:138

◆ dist_pc()

Datum dist_pc ( PG_FUNCTION_ARGS  )

Definition at line 5039 of file geo_ops.c.

References CIRCLE::center, PG_GETARG_CIRCLE_P, PG_GETARG_POINT_P, PG_RETURN_FLOAT8, point_dt(), and CIRCLE::radius.

5040 {
5041  Point *point = PG_GETARG_POINT_P(0);
5042  CIRCLE *circle = PG_GETARG_CIRCLE_P(1);
5043  float8 result;
5044 
5045  result = point_dt(point, &circle->center) - circle->radius;
5046  if (result < 0)
5047  result = 0;
5048  PG_RETURN_FLOAT8(result);
5049 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
double radius
Definition: geo_decls.h:127
double float8
Definition: c.h:458
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126
double point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1905

◆ dist_pl()

Datum dist_pl ( PG_FUNCTION_ARGS  )

Definition at line 2338 of file geo_ops.c.

References dist_pl_internal(), PG_GETARG_LINE_P, PG_GETARG_POINT_P, and PG_RETURN_FLOAT8.

2339 {
2340  Point *pt = PG_GETARG_POINT_P(0);
2341  LINE *line = PG_GETARG_LINE_P(1);
2342 
2344 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:156
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
Definition: geo_decls.h:90
static double dist_pl_internal(Point *pt, LINE *line)
Definition: geo_ops.c:2347

◆ dist_pl_internal()

static double dist_pl_internal ( Point pt,
LINE line 
)
static

Definition at line 2347 of file geo_ops.c.

References LINE::A, LINE::B, LINE::C, HYPOT, Point::x, and Point::y.

Referenced by close_ls(), close_sl(), dist_pl(), dist_sl(), and line_distance().

2348 {
2349  return fabs((line->A * pt->x + line->B * pt->y + line->C) /
2350  HYPOT(line->A, line->B));
2351 }
double A
Definition: geo_decls.h:92
double y
Definition: geo_decls.h:60
double B
Definition: geo_decls.h:92
double x
Definition: geo_decls.h:60
#define HYPOT(A, B)
Definition: geo_decls.h:53
double C
Definition: geo_decls.h:92

◆ dist_polyp()

Datum dist_polyp ( PG_FUNCTION_ARGS  )

Definition at line 2595 of file geo_ops.c.

References dist_ppoly_internal(), PG_GETARG_POINT_P, PG_GETARG_POLYGON_P, and PG_RETURN_FLOAT8.

2596 {
2597  POLYGON *poly = PG_GETARG_POLYGON_P(0);
2598  Point *point = PG_GETARG_POINT_P(1);
2599  float8 result;
2600 
2601  result = dist_ppoly_internal(point, poly);
2602 
2603  PG_RETURN_FLOAT8(result);
2604 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
#define PG_GETARG_POLYGON_P(n)
Definition: geo_decls.h:167
double float8
Definition: c.h:458
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
static double dist_ppoly_internal(Point *pt, POLYGON *poly)
Definition: geo_ops.c:2607

◆ dist_ppath()

Datum dist_ppath ( PG_FUNCTION_ARGS  )

Definition at line 2422 of file geo_ops.c.

References Assert, PATH::closed, dist_ps_internal(), i, PATH::npts, PATH::p, PG_GETARG_PATH_P, PG_GETARG_POINT_P, PG_RETURN_FLOAT8, PG_RETURN_NULL, point_dt(), and statlseg_construct().

2423 {
2424  Point *pt = PG_GETARG_POINT_P(0);
2425  PATH *path = PG_GETARG_PATH_P(1);
2426  float8 result = 0.0; /* keep compiler quiet */
2427  bool have_min = false;
2428  float8 tmp;
2429  int i;
2430  LSEG lseg;
2431 
2432  switch (path->npts)
2433  {
2434  case 0:
2435  /* no points in path? then result is undefined... */
2436  PG_RETURN_NULL();
2437  case 1:
2438  /* one point in path? then get distance between two points... */
2439  result = point_dt(pt, &path->p[0]);
2440  break;
2441  default:
2442  /* make sure the path makes sense... */
2443  Assert(path->npts > 1);
2444 
2445  /*
2446  * the distance from a point to a path is the smallest distance
2447  * from the point to any of its constituent segments.
2448  */
2449  for (i = 0; i < path->npts; i++)
2450  {
2451  int iprev;
2452 
2453  if (i > 0)
2454  iprev = i - 1;
2455  else
2456  {
2457  if (!path->closed)
2458  continue;
2459  iprev = path->npts - 1; /* include the closure segment */
2460  }
2461 
2462  statlseg_construct(&lseg, &path->p[iprev], &path->p[i]);
2463  tmp = dist_ps_internal(pt, &lseg);
2464  if (!have_min || tmp < result)
2465  {
2466  result = tmp;
2467  have_min = true;
2468  }
2469  }
2470  break;
2471  }
2472  PG_RETURN_FLOAT8(result);
2473 }
int32 closed
Definition: geo_decls.h:81
static void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: geo_ops.c:2025
Definition: geo_decls.h:68
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
double float8
Definition: c.h:458
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:83
int32 npts
Definition: geo_decls.h:80
#define PG_GETARG_PATH_P(n)
Definition: geo_decls.h:150
static double dist_ps_internal(Point *pt, LSEG *lseg)
Definition: geo_ops.c:2366
#define Assert(condition)
Definition: c.h:699
double point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1905
Definition: geo_decls.h:77
int i
#define PG_RETURN_NULL()
Definition: fmgr.h:310

◆ dist_ppoly()

Datum dist_ppoly ( PG_FUNCTION_ARGS  )

Definition at line 2583 of file geo_ops.c.

References dist_ppoly_internal(), PG_GETARG_POINT_P, PG_GETARG_POLYGON_P, and PG_RETURN_FLOAT8.

2584 {
2585  Point *point = PG_GETARG_POINT_P(0);
2586  POLYGON *poly = PG_GETARG_POLYGON_P(1);
2587  float8 result;
2588 
2589  result = dist_ppoly_internal(point, poly);
2590 
2591  PG_RETURN_FLOAT8(result);
2592 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
#define PG_GETARG_POLYGON_P(n)
Definition: geo_decls.h:167
double float8
Definition: c.h:458
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
static double dist_ppoly_internal(Point *pt, POLYGON *poly)
Definition: geo_ops.c:2607

◆ dist_ppoly_internal()

static double dist_ppoly_internal ( Point pt,
POLYGON poly 
)
static

Definition at line 2607 of file geo_ops.c.

References dist_ps_internal(), i, POLYGON::npts, LSEG::p, POLYGON::p, point_inside(), Point::x, and Point::y.

Referenced by dist_cpoly(), dist_polyp(), and dist_ppoly().

2608 {
2609  float8 result;
2610  float8 d;
2611  int i;
2612  LSEG seg;
2613 
2614  if (point_inside(pt, poly->npts, poly->p) != 0)
2615  {
2616 #ifdef GEODEBUG
2617  printf("dist_ppoly_internal- point inside of polygon\n");
2618 #endif
2619  return 0.0;
2620  }
2621 
2622  /* initialize distance with segment between first and last points */
2623  seg.p[0].x = poly->p[0].x;
2624  seg.p[0].y = poly->p[0].y;
2625  seg.p[1].x = poly->p[poly->npts - 1].x;
2626  seg.p[1].y = poly->p[poly->npts - 1].y;
2627  result = dist_ps_internal(pt, &seg);
2628 #ifdef GEODEBUG
2629  printf("dist_ppoly_internal- segment 0/n distance is %f\n", result);
2630 #endif
2631 
2632  /* check distances for other segments */
2633  for (i = 0; (i < poly->npts - 1); i++)
2634  {
2635  seg.p[0].x = poly->p[i].x;
2636  seg.p[0].y = poly->p[i].y;
2637  seg.p[1].x = poly->p[i + 1].x;
2638  seg.p[1].y = poly->p[i + 1].y;
2639  d = dist_ps_internal(pt, &seg);
2640 #ifdef GEODEBUG
2641  printf("dist_ppoly_internal- segment %d distance is %f\n", (i + 1), d);
2642 #endif
2643  if (d < result)
2644  result = d;
2645  }
2646 
2647  return result;
2648 }
Definition: geo_decls.h:68
double y
Definition: geo_decls.h:60
static int point_inside(Point *p, int npts, Point *plist)
Definition: geo_ops.c:5259
int32 npts
Definition: geo_decls.h:116
double x
Definition: geo_decls.h:60
double float8
Definition: c.h:458
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:118
static double dist_ps_internal(Point *pt, LSEG *lseg)
Definition: geo_ops.c:2366
Point p[2]
Definition: geo_decls.h:70
int i

◆ dist_ps()

Datum dist_ps ( PG_FUNCTION_ARGS  )

Definition at line 2357 of file geo_ops.c.

References dist_ps_internal(), PG_GETARG_LSEG_P, PG_GETARG_POINT_P, and PG_RETURN_FLOAT8.

2358 {
2359  Point *pt = PG_GETARG_POINT_P(0);
2360  LSEG *lseg = PG_GETARG_LSEG_P(1);
2361 
2363 }
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:144
Definition: geo_decls.h:68
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
static double dist_ps_internal(Point *pt, LSEG *lseg)
Definition: geo_ops.c:2366

◆ dist_ps_internal()

static double dist_ps_internal ( Point pt,
LSEG lseg 
)
static

Definition at line 2366 of file geo_ops.c.

References LINE::A, LINE::B, LINE::C, interpt_sl(), line_construct_pm(), LSEG::p, point_dt(), Point::x, and Point::y.

Referenced by close_lseg(), close_pb(), dist_ppath(), dist_ppoly_internal(), dist_ps(), and lseg_dt().

2367 {
2368  double m; /* slope of perp. */
2369  LINE *ln;
2370  double result,
2371  tmpdist;
2372  Point *ip;
2373 
2374  /*
2375  * Construct a line perpendicular to the input segment and through the
2376  * input point
2377  */
2378  if (lseg->p[1].x == lseg->p[0].x)
2379  m = 0;
2380  else if (lseg->p[1].y == lseg->p[0].y)
2381  m = (double) DBL_MAX; /* slope is infinite */
2382  else
2383  m = (lseg->p[0].x - lseg->p[1].x) / (lseg->p[1].y - lseg->p[0].y);
2384  ln = line_construct_pm(pt, m);
2385 
2386 #ifdef GEODEBUG
2387  printf("dist_ps- line is A=%g B=%g C=%g from (point) slope (%f,%f) %g\n",
2388  ln->A, ln->B, ln->C, pt->x, pt->y, m);
2389 #endif
2390 
2391  /*
2392  * Calculate distance to the line segment or to the nearest endpoint of
2393  * the segment.
2394  */
2395 
2396  /* intersection is on the line segment? */
2397  if ((ip = interpt_sl(lseg, ln)) != NULL)
2398  {
2399  /* yes, so use distance to the intersection point */
2400  result = point_dt(pt, ip);
2401 #ifdef GEODEBUG
2402  printf("dist_ps- distance is %f to intersection point is (%f,%f)\n",
2403  result, ip->x, ip->y);
2404 #endif
2405  }
2406  else
2407  {
2408  /* no, so use distance to the nearer endpoint */
2409  result = point_dt(pt, &lseg->p[0]);
2410  tmpdist = point_dt(pt, &lseg->p[1]);
2411  if (tmpdist < result)
2412  result = tmpdist;
2413  }
2414 
2415  return result;
2416 }
double A
Definition: geo_decls.h:92
static Point * interpt_sl(LSEG *lseg, LINE *line)
Definition: geo_ops.c:2660
static LINE * line_construct_pm(Point *pt, double m)
Definition: geo_ops.c:1010
double y
Definition: geo_decls.h:60
double B
Definition: geo_decls.h:92
double x
Definition: geo_decls.h:60
Definition: geo_decls.h:90
Point p[2]
Definition: geo_decls.h:70
double point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1905
double C
Definition: geo_decls.h:92

◆ dist_sb()

Datum dist_sb ( PG_FUNCTION_ARGS  )

Definition at line 2523 of file geo_ops.c.

References BoxPGetDatum, close_sb(), DatumGetPointP, DirectFunctionCall2, dist_pb(), LsegPGetDatum, PG_GETARG_BOX_P, PG_GETARG_LSEG_P, PG_RETURN_DATUM, and PointPGetDatum.

2524 {
2525  LSEG *lseg = PG_GETARG_LSEG_P(0);
2526  BOX *box = PG_GETARG_BOX_P(1);
2527  Point *tmp;
2528  Datum result;
2529 
2531  LsegPGetDatum(lseg),
2532  BoxPGetDatum(box)));
2533  result = DirectFunctionCall2(dist_pb,
2534  PointPGetDatum(tmp),
2535  BoxPGetDatum(box));
2536 
2537  PG_RETURN_DATUM(result);
2538 }
Datum dist_pb(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2479
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:144
Definition: geo_decls.h:68
#define LsegPGetDatum(X)
Definition: geo_decls.h:143
uintptr_t Datum
Definition: postgres.h:367
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:318
#define BoxPGetDatum(X)
Definition: geo_decls.h:160
#define DatumGetPointP(X)
Definition: geo_decls.h:137
Datum close_sb(PG_FUNCTION_ARGS)
Definition: geo_ops.c:3049
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:592
#define PointPGetDatum(X)
Definition: geo_decls.h:138

◆ dist_sl()

Datum dist_sl ( PG_FUNCTION_ARGS  )

Definition at line 2498 of file geo_ops.c.

References dist_pl_internal(), has_interpt_sl(), LSEG::p, PG_GETARG_LINE_P, PG_GETARG_LSEG_P, and PG_RETURN_FLOAT8.

2499 {
2500  LSEG *lseg = PG_GETARG_LSEG_P(0);
2501  LINE *line = PG_GETARG_LINE_P(1);
2502  float8 result,
2503  d2;
2504 
2505  if (has_interpt_sl(lseg, line))
2506  result = 0.0;
2507  else
2508  {
2509  result = dist_pl_internal(&lseg->p[0], line);
2510  d2 = dist_pl_internal(&lseg->p[1], line);
2511  /* XXX shouldn't we take the min not max? */
2512  if (d2 > result)
2513  result = d2;
2514  }
2515 
2516  PG_RETURN_FLOAT8(result);
2517 }
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:144
Definition: geo_decls.h:68
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
static bool has_interpt_sl(LSEG *lseg, LINE *line)
Definition: geo_ops.c:2693
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:156
double float8
Definition: c.h:458
Definition: geo_decls.h:90
Point p[2]
Definition: geo_decls.h:70
static double dist_pl_internal(Point *pt, LINE *line)
Definition: geo_ops.c:2347

◆ has_interpt_sl()

static bool has_interpt_sl ( LSEG lseg,
LINE line 
)
static

Definition at line 2693 of file geo_ops.c.

References interpt_sl().

Referenced by dist_sl(), inter_lb(), and inter_sl().

2694 {
2695  Point *tmp;
2696 
2697  tmp = interpt_sl(lseg, line);
2698  if (tmp)
2699  return true;
2700  return false;
2701 }
static Point * interpt_sl(LSEG *lseg, LINE *line)
Definition: geo_ops.c:2660

◆ inter_lb()

Datum inter_lb ( PG_FUNCTION_ARGS  )

Definition at line 3328 of file geo_ops.c.

References has_interpt_sl(), BOX::high, BOX::low, PG_GETARG_BOX_P, PG_GETARG_LINE_P, PG_RETURN_BOOL, statlseg_construct(), Point::x, and Point::y.

3329 {
3330  LINE *line = PG_GETARG_LINE_P(0);
3331  BOX *box = PG_GETARG_BOX_P(1);
3332  LSEG bseg;
3333  Point p1,
3334  p2;
3335 
3336  /* pairwise check lseg intersections */
3337  p1.x = box->low.x;
3338  p1.y = box->low.y;
3339  p2.x = box->low.x;
3340  p2.y = box->high.y;
3341  statlseg_construct(&bseg, &p1, &p2);
3342  if (has_interpt_sl(&bseg, line))
3343  PG_RETURN_BOOL(true);
3344  p1.x = box->high.x;
3345  p1.y = box->high.y;
3346  statlseg_construct(&bseg, &p1, &p2);
3347  if (has_interpt_sl(&bseg, line))
3348  PG_RETURN_BOOL(true);
3349  p2.x = box->high.x;
3350  p2.y = box->low.y;
3351  statlseg_construct(&bseg, &p1, &p2);
3352  if (has_interpt_sl(&bseg, line))
3353  PG_RETURN_BOOL(true);
3354  p1.x = box->low.x;
3355  p1.y = box->low.y;
3356  statlseg_construct(&bseg, &p1, &p2);
3357  if (has_interpt_sl(&bseg, line))
3358  PG_RETURN_BOOL(true);
3359 
3360  /* if we dropped through, no intersection */
3361  PG_RETURN_BOOL(false);
3362 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
static void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: geo_ops.c:2025
Definition: geo_decls.h:68
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
static bool has_interpt_sl(LSEG *lseg, LINE *line)
Definition: geo_ops.c:2693
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:156
Definition: geo_decls.h:90
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
Point high
Definition: geo_decls.h:104

◆ inter_sb()

Datum inter_sb ( PG_FUNCTION_ARGS  )

Definition at line 3273 of file geo_ops.c.

References box_ov(), BoxPGetDatum, DatumGetBool, DirectFunctionCall2, BOX::high, BOX::low, lseg_intersect_internal(), Max, Min, on_pb(), LSEG::p, PG_GETARG_BOX_P, PG_GETARG_LSEG_P, PG_RETURN_BOOL, PointPGetDatum, statlseg_construct(), Point::x, and Point::y.

Referenced by close_sb().

3274 {
3275  LSEG *lseg = PG_GETARG_LSEG_P(0);
3276  BOX *box = PG_GETARG_BOX_P(1);
3277  BOX lbox;
3278  LSEG bseg;
3279  Point point;
3280 
3281  lbox.low.x = Min(lseg->p[0].x, lseg->p[1].x);
3282  lbox.low.y = Min(lseg->p[0].y, lseg->p[1].y);
3283  lbox.high.x = Max(lseg->p[0].x, lseg->p[1].x);
3284  lbox.high.y = Max(lseg->p[0].y, lseg->p[1].y);
3285 
3286  /* nothing close to overlap? then not going to intersect */
3287  if (!box_ov(&lbox, box))
3288  PG_RETURN_BOOL(false);
3289 
3290  /* an endpoint of segment is inside box? then clearly intersects */
3292  PointPGetDatum(&lseg->p[0]),
3293  BoxPGetDatum(box))) ||
3295  PointPGetDatum(&lseg->p[1]),
3296  BoxPGetDatum(box))))
3297  PG_RETURN_BOOL(true);
3298 
3299  /* pairwise check lseg intersections */
3300  point.x = box->low.x;
3301  point.y = box->high.y;
3302  statlseg_construct(&bseg, &box->low, &point);
3303  if (lseg_intersect_internal(&bseg, lseg))
3304  PG_RETURN_BOOL(true);
3305 
3306  statlseg_construct(&bseg, &box->high, &point);
3307  if (lseg_intersect_internal(&bseg, lseg))
3308  PG_RETURN_BOOL(true);
3309 
3310  point.x = box->high.x;
3311  point.y = box->low.y;
3312  statlseg_construct(&bseg, &box->low, &point);
3313  if (lseg_intersect_internal(&bseg, lseg))
3314  PG_RETURN_BOOL(true);
3315 
3316  statlseg_construct(&bseg, &box->high, &point);
3317  if (lseg_intersect_internal(&bseg, lseg))
3318  PG_RETURN_BOOL(true);
3319 
3320  /* if we dropped through, no two segs intersected */
3321  PG_RETURN_BOOL(false);
3322 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:144
static void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: geo_ops.c:2025
Definition: geo_decls.h:68
#define Min(x, y)
Definition: c.h:857
double y
Definition: geo_decls.h:60
double x
Definition: geo_decls.h:60
static bool box_ov(BOX *box1, BOX *box2)
Definition: geo_ops.c:526
#define DatumGetBool(X)
Definition: postgres.h:378
Datum on_pb(PG_FUNCTION_ARGS)
Definition: geo_ops.c:3160
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
#define BoxPGetDatum(X)
Definition: geo_decls.h:160
#define Max(x, y)
Definition: c.h:851
Point p[2]
Definition: geo_decls.h:70
Point high
Definition: geo_decls.h:104
static bool lseg_intersect_internal(LSEG *l1, LSEG *l2)
Definition: geo_ops.c:2059
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:592
#define PointPGetDatum(X)
Definition: geo_decls.h:138

◆ inter_sl()

Datum inter_sl ( PG_FUNCTION_ARGS  )

Definition at line 3254 of file geo_ops.c.

References has_interpt_sl(), PG_GETARG_LINE_P, PG_GETARG_LSEG_P, and PG_RETURN_BOOL.

3255 {
3256  LSEG *lseg = PG_GETARG_LSEG_P(0);
3257  LINE *line = PG_GETARG_LINE_P(1);
3258 
3259  PG_RETURN_BOOL(has_interpt_sl(lseg, line));
3260 }
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:144
Definition: geo_decls.h:68
static bool has_interpt_sl(LSEG *lseg, LINE *line)
Definition: geo_ops.c:2693
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:156
Definition: geo_decls.h:90
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324

◆ interpt_sl()

static Point * interpt_sl ( LSEG lseg,
LINE line 
)
static

Definition at line 2660 of file geo_ops.c.

References LINE::A, LINE::B, LINE::C, line_construct_pts(), line_interpt_internal(), on_ps_internal(), LSEG::p, PointerIsValid, Point::x, and Point::y.

Referenced by close_ls(), close_ps(), close_sl(), dist_ps_internal(), has_interpt_sl(), and lseg_intersect_internal().

2661 {
2662  LINE tmp;
2663  Point *p;
2664 
2665  line_construct_pts(&tmp, &lseg->p[0], &lseg->p[1]);
2666  p = line_interpt_internal(&tmp, line);
2667 #ifdef GEODEBUG
2668  printf("interpt_sl- segment is (%.*g %.*g) (%.*g %.*g)\n",
2669  DBL_DIG, lseg->p[0].x, DBL_DIG, lseg->p[0].y, DBL_DIG, lseg->p[1].x, DBL_DIG, lseg->p[1].y);
2670  printf("interpt_sl- segment becomes line A=%.*g B=%.*g C=%.*g\n",
2671  DBL_DIG, tmp.A, DBL_DIG, tmp.B, DBL_DIG, tmp.C);
2672 #endif
2673  if (PointerIsValid(p))
2674  {
2675 #ifdef GEODEBUG
2676  printf("interpt_sl- intersection point is (%.*g %.*g)\n", DBL_DIG, p->x, DBL_DIG, p->y);
2677 #endif
2678  if (on_ps_internal(p, lseg))
2679  {
2680 #ifdef GEODEBUG
2681  printf("interpt_sl- intersection point is on segment\n");
2682 #endif
2683  }
2684  else
2685  p = NULL;
2686  }
2687 
2688  return p;
2689 }
double A
Definition: geo_decls.h:92
static Point * line_interpt_internal(LINE *l1, LINE *l2)
Definition: geo_ops.c:1217
double y
Definition: geo_decls.h:60
double B
Definition: geo_decls.h:92
double x
Definition: geo_decls.h:60
Definition: geo_decls.h:90
static void line_construct_pts(LINE *line, Point *pt1, Point *pt2)
Definition: geo_ops.c:1036
static bool on_ps_internal(Point *pt, LSEG *lseg)
Definition: geo_ops.c:3153
Point p[2]
Definition: geo_decls.h:70
double C
Definition: geo_decls.h:92
#define PointerIsValid(pointer)
Definition: c.h:593

◆ line_construct_pm()

static LINE * line_construct_pm ( Point pt,
double  m 
)
static

Definition at line 1010 of file geo_ops.c.

References LINE::A, LINE::B, LINE::C, palloc(), Point::x, and Point::y.

Referenced by close_pl(), close_ps(), and dist_ps_internal().

1011 {
1012  LINE *result = (LINE *) palloc(sizeof(LINE));
1013 
1014  if (m == DBL_MAX)
1015  {
1016  /* vertical - use "x = C" */
1017  result->A = -1;
1018  result->B = 0;
1019  result->C = pt->x;
1020  }
1021  else
1022  {
1023  /* use "mx - y + yinter = 0" */
1024  result->A = m;
1025  result->B = -1.0;
1026  result->C = pt->y - m * pt->x;
1027  }
1028 
1029  return result;
1030 }
double A
Definition: geo_decls.h:92
double y
Definition: geo_decls.h:60
double B
Definition: geo_decls.h:92
double x
Definition: geo_decls.h:60
Definition: geo_decls.h:90
double C
Definition: geo_decls.h:92
void * palloc(Size size)
Definition: mcxt.c:924

◆ line_construct_pp()

Datum line_construct_pp ( PG_FUNCTION_ARGS  )

Definition at line 1078 of file geo_ops.c.

References line_construct_pts(), palloc(), PG_GETARG_POINT_P, and PG_RETURN_LINE_P.

1079 {
1080  Point *pt1 = PG_GETARG_POINT_P(0);
1081  Point *pt2 = PG_GETARG_POINT_P(1);
1082  LINE *result = (LINE *) palloc(sizeof(LINE));
1083 
1084  line_construct_pts(result, pt1, pt2);
1085  PG_RETURN_LINE_P(result);
1086 }
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
Definition: geo_decls.h:90
static void line_construct_pts(LINE *line, Point *pt1, Point *pt2)
Definition: geo_ops.c:1036
#define PG_RETURN_LINE_P(x)
Definition: geo_decls.h:157
void * palloc(Size size)
Definition: mcxt.c:924

◆ line_construct_pts()

static void line_construct_pts ( LINE line,
Point pt1,
Point pt2 
)
static

Definition at line 1036 of file geo_ops.c.

References LINE::A, LINE::B, LINE::C, FPeq, Point::x, and Point::y.

Referenced by interpt_sl(), line_construct_pp(), line_in(), lseg_interpt_internal(), and lseg_intersect_internal().

1037 {
1038  if (FPeq(pt1->x, pt2->x))
1039  { /* vertical */
1040  /* use "x = C" */
1041  line->A = -1;
1042  line->B = 0;
1043  line->C = pt1->x;
1044 #ifdef GEODEBUG
1045  printf("line_construct_pts- line is vertical\n");
1046 #endif
1047  }
1048  else if (FPeq(pt1->y, pt2->y))
1049  { /* horizontal */
1050  /* use "y = C" */
1051  line->A = 0;
1052  line->B = -1;
1053  line->C = pt1->y;
1054 #ifdef GEODEBUG
1055  printf("line_construct_pts- line is horizontal\n");
1056 #endif
1057  }
1058  else
1059  {
1060  /* use "mx - y + yinter = 0" */
1061  line->A = (pt2->y - pt1->y) / (pt2->x - pt1->x);
1062  line->B = -1.0;
1063  line->C = pt1->y - line->A * pt1->x;
1064  /* on some platforms, the preceding expression tends to produce -0 */
1065  if (line->C == 0.0)
1066  line->C = 0.0;
1067 #ifdef GEODEBUG
1068  printf("line_construct_pts- line is neither vertical nor horizontal (diffs x=%.*g, y=%.*g\n",
1069  DBL_DIG, (pt2->x - pt1->x), DBL_DIG, (pt2->y - pt1->y));
1070 #endif
1071  }
1072 }
double A
Definition: geo_decls.h:92
double y
Definition: geo_decls.h:60
double B
Definition: geo_decls.h:92
double x
Definition: geo_decls.h:60
#define FPeq(A, B)
Definition: geo_decls.h:37
double C
Definition: geo_decls.h:92

◆ line_decode()

static bool line_decode ( char *  s,
const char *  str,
LINE line 
)
static

Definition at line 898 of file geo_ops.c.

References LINE::A, LINE::B, LINE::C, DELIM, and single_decode().

Referenced by line_in().

899 {
900  /* s was already advanced over leading '{' */
901  line->A = single_decode(s, &s, "line", str);
902  if (*s++ != DELIM)
903  return false;
904  line->B = single_decode(s, &s, "line", str);
905  if (*s++ != DELIM)
906  return false;
907  line->C = single_decode(s, &s, "line", str);
908  if (*s++ != '}')
909  return false;
910  while (isspace((unsigned char) *s))
911  s++;
912  if (*s != '\0')
913  return false;
914  return true;
915 }
double A
Definition: geo_decls.h:92
static double single_decode(char *num, char **endptr_p, const char *type_name, const char *orig_string)
Definition: geo_ops.c:124
double B
Definition: geo_decls.h:92
#define DELIM
Definition: geo_ops.c:91
double C
Definition: geo_decls.h:92

◆ line_distance()

Datum line_distance ( PG_FUNCTION_ARGS  )

Definition at line 1176 of file geo_ops.c.

References LINE::B, LINE::C, DatumGetBool, DirectFunctionCall2, dist_pl_internal(), FPzero, line_parallel(), LinePGetDatum, PG_GETARG_LINE_P, PG_RETURN_FLOAT8, and point_construct().

1177 {
1178  LINE *l1 = PG_GETARG_LINE_P(0);
1179  LINE *l2 = PG_GETARG_LINE_P(1);
1180  float8 result;
1181  Point *tmp;
1182 
1184  LinePGetDatum(l1),
1185  LinePGetDatum(l2))))
1186  PG_RETURN_FLOAT8(0.0);
1187  if (FPzero(l1->B)) /* vertical? */
1188  PG_RETURN_FLOAT8(fabs(l1->C - l2->C));
1189  tmp = point_construct(0.0, l1->C);
1190  result = dist_pl_internal(tmp, l2);
1191  PG_RETURN_FLOAT8(result);
1192 }
#define FPzero(A)
Definition: geo_decls.h:36
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:331
static Point * point_construct(double x, double y)
Definition: geo_ops.c:1784
double B
Definition: geo_decls.h:92
Datum line_parallel(PG_FUNCTION_ARGS)
Definition: geo_ops.c:1105
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:156
double float8
Definition: c.h:458
Definition: geo_decls.h:90
#define DatumGetBool(X)
Definition: postgres.h:378
#define LinePGetDatum(X)
Definition: geo_decls.h:155
static double dist_pl_internal(Point *pt, LINE *line)
Definition: geo_ops.c:2347
double C
Definition: geo_decls.h:92
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:592

◆ line_eq()

Datum line_eq ( PG_FUNCTION_ARGS  )

Definition at line 1147 of file geo_ops.c.

References LINE::A, LINE::B, LINE::C, FPeq, FPzero, PG_GETARG_LINE_P, and PG_RETURN_BOOL.

1148 {
1149  LINE *l1 = PG_GETARG_LINE_P(0);
1150  LINE *l2 = PG_GETARG_LINE_P(1);
1151  double k;
1152 
1153  if (!FPzero(l2->A))
1154  k = l1->A / l2->A;
1155  else if (!FPzero(l2->B))
1156  k = l1->B / l2->B;
1157  else if (!FPzero(l2->C))
1158  k = l1->C / l2->C;
1159  else
1160  k = 1.0;
1161 
1162  PG_RETURN_BOOL(FPeq(l1->A, k * l2->A) &&
1163  FPeq(l1->B, k * l2->B) &&
1164  FPeq(l1->C, k * l2->C));
1165 }
double A
Definition: geo_decls.h:92
#define FPzero(A)
Definition: geo_decls.h:36
double B
Definition: geo_decls.h:92
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:156
Definition: geo_decls.h:90
#define FPeq(A, B)
Definition: geo_decls.h:37
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324
double C
Definition: geo_decls.h:92

◆ line_horizontal()

Datum line_horizontal ( PG_FUNCTION_ARGS  )

Definition at line 1139 of file geo_ops.c.

References LINE::A, FPzero, PG_GETARG_LINE_P, and PG_RETURN_BOOL.

1140 {
1141  LINE *line = PG_GETARG_LINE_P(0);
1142 
1143  PG_RETURN_BOOL(FPzero(line->A));
1144 }
double A
Definition: geo_decls.h:92
#define FPzero(A)
Definition: geo_decls.h:36
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:156
Definition: geo_decls.h:90
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:324

◆ line_in()

Datum line_in ( PG_FUNCTION_ARGS  )

Definition at line 918 of file geo_ops.c.

References LINE::A, LINE::B, ereport, errcode(), errmsg(), ERROR, FPeq, FPzero, line_construct_pts(), line_decode(), LSEG::p, palloc(), path_decode(), PG_GETARG_CSTRING, PG_RETURN_LINE_P, generate_unaccent_rules::str, Point::x, and Point::y.

919 {
920  char *str = PG_GETARG_CSTRING(0);
921  LINE *line = (LINE *) palloc(sizeof(LINE));
922  LSEG lseg;
923  bool isopen;
924  char *s;
925 
926  s = str;
927  while (isspace((unsigned char) *s))
928  s++;
929  if (*s == '{')
930  {
931  if (!line_decode(s + 1, str, line))
932  ereport(ERROR,
933  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
934  errmsg("invalid input syntax for type %s: \"%s\"",
935  "line", str)));
936  if (FPzero(line->A) && FPzero(line->B))
937  ereport(ERROR,
938  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
939  errmsg("invalid line specification: A and B cannot both be zero")));
940  }
941  else
942  {
943  path_decode(s, true, 2, &(lseg.p[0]), &isopen, NULL, "line", str);
944  if (FPeq(lseg.p[0].x, lseg.p[1].x) && FPeq(lseg.p[0].y, lseg.p[1].y))
945  ereport(ERROR,
946  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
947  errmsg("invalid line specification: must be two distinct points")));
948  line_construct_pts(line, &lseg.p[0], &lseg.p[1]);
949  }
950 
951  PG_RETURN_LINE_P(line);
952 }
double A
Definition: geo_decls.h:92
#define FPzero(A)
Definition: geo_decls.h:36
Definition: geo_decls.h:68
double y
Definition: geo_decls.h:60
int errcode(int sqlerrcode)
Definition: elog.c:575
double B
Definition: geo_decls.h:92
double x
Definition: geo_decls.h:60
#define ERROR
Definition: elog.h:43
Definition: geo_decls.h:90
#define ereport(elevel, rest)
Definition: elog.h:122
#define FPeq(A, B)
Definition: geo_decls.h:37
static void line_construct_pts(LINE *line, Point *pt1, Point *pt2)
Definition: geo_ops.c:1036
static bool line_decode(char *s, const char *str, LINE *line)
Definition: geo_ops.c:898
Point p[2]
Definition: geo_decls.h:70
#define PG_RETURN_LINE_P(x)
Definition: geo_decls.h:157
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:247
static void path_decode(char *str, bool opentype, int npts, Point *p, bool *isopen, char **endptr_p, const char *type_name, const char *orig_string)
Definition: geo_ops.c:193

◆ line_interpt()

Datum line_interpt ( PG_FUNCTION_ARGS  )

Definition at line 1198 of file geo_ops.c.

References line_interpt_internal(), PG_GETARG_LINE_P, PG_RETURN_NULL, and PG_RETURN_POINT_P.

1199 {
1200  LINE *l1 = PG_GETARG_LINE_P(0);
1201  LINE *l2 = PG_GETARG_LINE_P(1);
1202  Point *result;
1203 
1204  result = line_interpt_internal(l1, l2);
1205 
1206  if (result == NULL)
1207  PG_RETURN_NULL();
1208  PG_RETURN_POINT_P(result);
1209 }
static Point * line_interpt_internal(LINE *l1, LINE *l2)
Definition: geo_ops.c:1217
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:156
Definition: geo_decls.h:90
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:140
#define PG_RETURN_NULL()
Definition: fmgr.h:310

◆ line_interpt_internal()

static Point * line_interpt_internal ( LINE l1,
LINE l2 
)
static

Definition at line 1217 of file geo_ops.c.

References LINE::A, LINE::B, LINE::C, DatumGetBool, DirectFunctionCall2, FPzero, line_parallel(), LinePGetDatum, and point_construct().

Referenced by close_pl(), interpt_sl(), line_interpt(), and lseg_interpt_internal().

1218 {
1219  Point *result;
1220  double x,
1221  y;
1222 
1223  /*
1224  * NOTE: if the lines are identical then we will find they are parallel
1225  * and report "no intersection". This is a little weird, but since
1226  * there's no *unique* intersection, maybe it's appropriate behavior.
1227  */
1229  LinePGetDatum(l1),
1230  LinePGetDatum(l2))))
1231  return NULL;
1232 
1233  if (FPzero(l1->B)) /* l1 vertical? */
1234  {
1235  x = l1->C;
1236  y = (l2->A * x + l2->C);
1237  }
1238  else if (FPzero(l2->B)) /* l2 vertical? */
1239  {
1240  x = l2->C;
1241  y = (l1->A * x + l1->C);
1242  }
1243  else
1244  {
1245  x = (l1->C - l2->C) / (l2->A - l1->A);
1246  y = (l1->A * x + l1->C);
1247  }
1248  result = point_construct(x, y);
1249 
1250 #ifdef GEODEBUG
1251  printf("line_interpt- lines are A=%.*g, B=%.*g, C=%.*g, A=%.*g, B=%.*g, C=%.*g\n",
1252  DBL_DIG, l1->A, DBL_DIG, l1->B, DBL_DIG, l1->C, DBL_DIG, l2->A, DBL_DIG, l2->B, DBL_DIG, l2->C);
1253  printf("line_interpt- lines intersect at (%.*g,%.*g)\n", DBL_DIG, x, DBL_DIG, y);
1254 #endif
1255 
1256  return result;
1257 }
double A
Definition: geo_decls.h:92
#define FPzero(A)
Definition: geo_decls.h:36
static Point * point_construct(double x, double y)
Definition: geo_ops.c:1784
double B
Definition: geo_decls.h:92
Datum line_parallel(PG_FUNCTION_ARGS)
Definition: geo_ops.c:1105
#define DatumGetBool(X)
Definition: postgres.h:378
#define LinePGetDatum(X)
Definition: geo_decls.h:155
double C
Definition: geo_decls.h:92
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:592

◆ line_intersect()

Datum line_intersect ( PG_FUNCTION_ARGS  )

Definition at line 1094 of file