PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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_copy (BOX *box)
 
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)
 
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

#define DELIM   ','

Definition at line 92 of file geo_ops.c.

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

#define LDELIM   '('

Definition at line 90 of file geo_ops.c.

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

#define LDELIM_C   '<'

Definition at line 95 of file geo_ops.c.

Referenced by circle_in(), and circle_out().

#define LDELIM_EP   '['

Definition at line 93 of file geo_ops.c.

Referenced by path_decode(), and path_encode().

#define M_PI   3.14159265358979323846

Definition at line 28 of file geo_ops.c.

Referenced by circle_ar(), and circle_poly().

#define POINT_ON_POLYGON   INT_MAX

Definition at line 5257 of file geo_ops.c.

Referenced by lseg_crossing(), and point_inside().

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

Definition at line 91 of file geo_ops.c.

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

#define RDELIM_C   '>'

Definition at line 96 of file geo_ops.c.

Referenced by circle_in(), and circle_out().

#define RDELIM_EP   ']'

Definition at line 94 of file geo_ops.c.

Referenced by path_decode(), and path_encode().

Enumeration Type Documentation

enum path_delim
Enumerator
PATH_NONE 
PATH_OPEN 
PATH_CLOSED 

Definition at line 36 of file geo_ops.c.

37 {
39 };

Function Documentation

Datum box_above ( PG_FUNCTION_ARGS  )

Definition at line 613 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().

614 {
615  BOX *box1 = PG_GETARG_BOX_P(0);
616  BOX *box2 = PG_GETARG_BOX_P(1);
617 
618  PG_RETURN_BOOL(FPgt(box1->low.y, box2->high.y));
619 }
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:303
Point high
Definition: geo_decls.h:104
Datum box_above_eq ( PG_FUNCTION_ARGS  )

Definition at line 680 of file geo_ops.c.

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

681 {
682  BOX *box1 = PG_GETARG_BOX_P(0);
683  BOX *box2 = PG_GETARG_BOX_P(1);
684 
685  PG_RETURN_BOOL(FPge(box1->low.y, box2->high.y));
686 }
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:303
Point high
Definition: geo_decls.h:104
#define FPge(A, B)
Definition: geo_decls.h:42
Datum box_add ( PG_FUNCTION_ARGS  )

Definition at line 4118 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.

4119 {
4120  BOX *box = PG_GETARG_BOX_P(0);
4121  Point *p = PG_GETARG_POINT_P(1);
4122 
4123  PG_RETURN_BOX_P(box_construct((box->high.x + p->x),
4124  (box->low.x + p->x),
4125  (box->high.y + p->y),
4126  (box->low.y + p->y)));
4127 }
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:445
static double box_ar ( BOX box)
static

Definition at line 812 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().

813 {
814  return box_wd(box) * box_ht(box);
815 }
static double box_wd(BOX *box)
Definition: geo_ops.c:832
static double box_ht(BOX *box)
Definition: geo_ops.c:842
Datum box_area ( PG_FUNCTION_ARGS  )

Definition at line 745 of file geo_ops.c.

References box_ar(), PG_GETARG_BOX_P, and PG_RETURN_FLOAT8.

746 {
747  BOX *box = PG_GETARG_BOX_P(0);
748 
749  PG_RETURN_FLOAT8(box_ar(box));
750 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:310
static double box_ar(BOX *box)
Definition: geo_ops.c:812
Datum box_below ( PG_FUNCTION_ARGS  )

Definition at line 590 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().

591 {
592  BOX *box1 = PG_GETARG_BOX_P(0);
593  BOX *box2 = PG_GETARG_BOX_P(1);
594 
595  PG_RETURN_BOOL(FPlt(box1->high.y, box2->low.y));
596 }
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:303
#define FPlt(A, B)
Definition: geo_decls.h:39
Point high
Definition: geo_decls.h:104
Datum box_below_eq ( PG_FUNCTION_ARGS  )

Definition at line 671 of file geo_ops.c.

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

672 {
673  BOX *box1 = PG_GETARG_BOX_P(0);
674  BOX *box2 = PG_GETARG_BOX_P(1);
675 
676  PG_RETURN_BOOL(FPle(box1->high.y, box2->low.y));
677 }
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:303
Point high
Definition: geo_decls.h:104
#define FPle(A, B)
Definition: geo_decls.h:40
Datum box_center ( PG_FUNCTION_ARGS  )

Definition at line 798 of file geo_ops.c.

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

799 {
800  BOX *box = PG_GETARG_BOX_P(0);
801  Point *result = (Point *) palloc(sizeof(Point));
802 
803  box_cn(result, box);
804 
805  PG_RETURN_POINT_P(result);
806 }
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:821
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:140
void * palloc(Size size)
Definition: mcxt.c:891
Datum box_circle ( PG_FUNCTION_ARGS  )

Definition at line 5136 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.

5137 {
5138  BOX *box = PG_GETARG_BOX_P(0);
5139  CIRCLE *circle;
5140 
5141  circle = (CIRCLE *) palloc(sizeof(CIRCLE));
5142 
5143  circle->center.x = (box->high.x + box->low.x) / 2;
5144  circle->center.y = (box->high.y + box->low.y) / 2;
5145 
5146  circle->radius = point_dt(&circle->center, &box->high);
5147 
5148  PG_RETURN_CIRCLE_P(circle);
5149 }
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:1906
void * palloc(Size size)
Definition: mcxt.c:891
static void box_cn ( Point center,
BOX box 
)
static

Definition at line 821 of file geo_ops.c.

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

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

822 {
823  center->x = (box->high.x + box->low.x) / 2.0;
824  center->y = (box->high.y + box->low.y) / 2.0;
825 }
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
static BOX * box_construct ( double  x1,
double  x2,
double  y1,
double  y2 
)
static

Definition at line 445 of file geo_ops.c.

References box_fill(), and palloc().

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

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

Definition at line 650 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().

651 {
652  BOX *box1 = PG_GETARG_BOX_P(0);
653  BOX *box2 = PG_GETARG_BOX_P(1);
654 
655  PG_RETURN_BOOL(FPge(box1->high.x, box2->high.x) &&
656  FPle(box1->low.x, box2->low.x) &&
657  FPge(box1->high.y, box2->high.y) &&
658  FPle(box1->low.y, box2->low.y));
659 }
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:303
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
Datum box_contain_pt ( PG_FUNCTION_ARGS  )

Definition at line 3171 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().

3172 {
3173  BOX *box = PG_GETARG_BOX_P(0);
3174  Point *pt = PG_GETARG_POINT_P(1);
3175 
3176  PG_RETURN_BOOL(pt->x <= box->high.x && pt->x >= box->low.x &&
3177  pt->y <= box->high.y && pt->y >= box->low.y);
3178 }
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:303
Point high
Definition: geo_decls.h:104
Datum box_contained ( PG_FUNCTION_ARGS  )

Definition at line 636 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().

637 {
638  BOX *box1 = PG_GETARG_BOX_P(0);
639  BOX *box2 = PG_GETARG_BOX_P(1);
640 
641  PG_RETURN_BOOL(FPle(box1->high.x, box2->high.x) &&
642  FPge(box1->low.x, box2->low.x) &&
643  FPle(box1->high.y, box2->high.y) &&
644  FPge(box1->low.y, box2->low.y));
645 }
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:303
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
static BOX * box_copy ( BOX box)
static

Definition at line 486 of file geo_ops.c.

References palloc().

Referenced by poly_box().

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

Definition at line 882 of file geo_ops.c.

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

883 {
884  BOX *box = PG_GETARG_BOX_P(0);
885  LSEG *result = (LSEG *) palloc(sizeof(LSEG));
886 
887  statlseg_construct(result, &box->high, &box->low);
888 
889  PG_RETURN_LSEG_P(result);
890 }
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:2026
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:891
Datum box_distance ( PG_FUNCTION_ARGS  )

Definition at line 781 of file geo_ops.c.

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

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

Definition at line 4163 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.

4164 {
4165  BOX *box = PG_GETARG_BOX_P(0);
4166  Point *p = PG_GETARG_POINT_P(1);
4167  BOX *result;
4168  Point *high,
4169  *low;
4170 
4172  PointPGetDatum(&box->high),
4173  PointPGetDatum(p)));
4175  PointPGetDatum(&box->low),
4176  PointPGetDatum(p)));
4177 
4178  result = box_construct(high->x, low->x, high->y, low->y);
4179 
4180  PG_RETURN_BOX_P(result);
4181 }
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:4079
#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:445
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:557
#define PointPGetDatum(X)
Definition: geo_decls.h:138
Datum box_eq ( PG_FUNCTION_ARGS  )

Definition at line 711 of file geo_ops.c.

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

712 {
713  BOX *box1 = PG_GETARG_BOX_P(0);
714  BOX *box2 = PG_GETARG_BOX_P(1);
715 
716  PG_RETURN_BOOL(FPeq(box_ar(box1), box_ar(box2)));
717 }
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:812
#define FPeq(A, B)
Definition: geo_decls.h:37
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
static BOX * box_fill ( BOX result,
double  x1,
double  x2,
double  y1,
double  y2 
)
static

Definition at line 456 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().

457 {
458  if (x1 > x2)
459  {
460  result->high.x = x1;
461  result->low.x = x2;
462  }
463  else
464  {
465  result->high.x = x2;
466  result->low.x = x1;
467  }
468  if (y1 > y2)
469  {
470  result->high.y = y1;
471  result->low.y = y2;
472  }
473  else
474  {
475  result->high.y = y2;
476  result->low.y = y1;
477  }
478 
479  return result;
480 }
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
Datum box_ge ( PG_FUNCTION_ARGS  )

Definition at line 729 of file geo_ops.c.

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

730 {
731  BOX *box1 = PG_GETARG_BOX_P(0);
732  BOX *box2 = PG_GETARG_BOX_P(1);
733 
734  PG_RETURN_BOOL(FPge(box_ar(box1), box_ar(box2)));
735 }
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:812
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
#define FPge(A, B)
Definition: geo_decls.h:42
Datum box_gt ( PG_FUNCTION_ARGS  )

Definition at line 702 of file geo_ops.c.

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

703 {
704  BOX *box1 = PG_GETARG_BOX_P(0);
705  BOX *box2 = PG_GETARG_BOX_P(1);
706 
707  PG_RETURN_BOOL(FPgt(box_ar(box1), box_ar(box2)));
708 }
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:812
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
Datum box_height ( PG_FUNCTION_ARGS  )

Definition at line 769 of file geo_ops.c.

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

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

Definition at line 842 of file geo_ops.c.

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

Referenced by box_ar().

843 {
844  return box->high.y - box->low.y;
845 }
double y
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
Point high
Definition: geo_decls.h:104
Datum box_in ( PG_FUNCTION_ARGS  )

Definition at line 352 of file geo_ops.c.

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

353 {
354  char *str = PG_GETARG_CSTRING(0);
355  BOX *box = (BOX *) palloc(sizeof(BOX));
356  bool isopen;
357  double x,
358  y;
359 
360  path_decode(str, false, 2, &(box->high), &isopen, NULL, "box", str);
361 
362  /* reorder corners if necessary... */
363  if (box->high.x < box->low.x)
364  {
365  x = box->high.x;
366  box->high.x = box->low.x;
367  box->low.x = x;
368  }
369  if (box->high.y < box->low.y)
370  {
371  y = box->high.y;
372  box->high.y = box->low.y;
373  box->low.y = y;
374  }
375 
376  PG_RETURN_BOX_P(box);
377 }
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
#define NULL
Definition: c.h:226
Point high
Definition: geo_decls.h:104
void * palloc(Size size)
Definition: mcxt.c:891
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:233
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:194
Datum box_intersect ( PG_FUNCTION_ARGS  )

Definition at line 857 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.

858 {
859  BOX *box1 = PG_GETARG_BOX_P(0);
860  BOX *box2 = PG_GETARG_BOX_P(1);
861  BOX *result;
862 
863  if (!box_ov(box1, box2))
864  PG_RETURN_NULL();
865 
866  result = (BOX *) palloc(sizeof(BOX));
867 
868  result->high.x = Min(box1->high.x, box2->high.x);
869  result->low.x = Max(box1->low.x, box2->low.x);
870  result->high.y = Min(box1->high.y, box2->high.y);
871  result->low.y = Max(box1->low.y, box2->low.y);
872 
873  PG_RETURN_BOX_P(result);
874 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
#define Min(x, y)
Definition: c.h:802
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:527
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:796
Point high
Definition: geo_decls.h:104
void * palloc(Size size)
Definition: mcxt.c:891
#define PG_RETURN_NULL()
Definition: fmgr.h:289
Datum box_le ( PG_FUNCTION_ARGS  )

Definition at line 720 of file geo_ops.c.

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

721 {
722  BOX *box1 = PG_GETARG_BOX_P(0);
723  BOX *box2 = PG_GETARG_BOX_P(1);
724 
725  PG_RETURN_BOOL(FPle(box_ar(box1), box_ar(box2)));
726 }
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:812
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
#define FPle(A, B)
Definition: geo_decls.h:40
Datum box_left ( PG_FUNCTION_ARGS  )

Definition at line 538 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().

539 {
540  BOX *box1 = PG_GETARG_BOX_P(0);
541  BOX *box2 = PG_GETARG_BOX_P(1);
542 
543  PG_RETURN_BOOL(FPlt(box1->high.x, box2->low.x));
544 }
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:303
#define FPlt(A, B)
Definition: geo_decls.h:39
Point high
Definition: geo_decls.h:104
Datum box_lt ( PG_FUNCTION_ARGS  )

Definition at line 693 of file geo_ops.c.

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

694 {
695  BOX *box1 = PG_GETARG_BOX_P(0);
696  BOX *box2 = PG_GETARG_BOX_P(1);
697 
698  PG_RETURN_BOOL(FPlt(box_ar(box1), box_ar(box2)));
699 }
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:812
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
#define FPlt(A, B)
Definition: geo_decls.h:39
Datum box_mul ( PG_FUNCTION_ARGS  )

Definition at line 4142 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.

4143 {
4144  BOX *box = PG_GETARG_BOX_P(0);
4145  Point *p = PG_GETARG_POINT_P(1);
4146  BOX *result;
4147  Point *high,
4148  *low;
4149 
4151  PointPGetDatum(&box->high),
4152  PointPGetDatum(p)));
4154  PointPGetDatum(&box->low),
4155  PointPGetDatum(p)));
4156 
4157  result = box_construct(high->x, low->x, high->y, low->y);
4158 
4159  PG_RETURN_BOX_P(result);
4160 }
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:4064
#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:445
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:557
#define PointPGetDatum(X)
Definition: geo_decls.h:138
Datum box_out ( PG_FUNCTION_ARGS  )

Definition at line 382 of file geo_ops.c.

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

383 {
384  BOX *box = PG_GETARG_BOX_P(0);
385 
387 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:306
Point high
Definition: geo_decls.h:104
static char * path_encode(enum path_delim path_delim, int npts, Point *pt)
static bool box_ov ( BOX box1,
BOX box2 
)
static

Definition at line 527 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().

528 {
529  return (FPle(box1->low.x, box2->high.x) &&
530  FPle(box2->low.x, box1->high.x) &&
531  FPle(box1->low.y, box2->high.y) &&
532  FPle(box2->low.y, box1->high.y));
533 }
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
Datum box_overabove ( PG_FUNCTION_ARGS  )

Definition at line 625 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().

626 {
627  BOX *box1 = PG_GETARG_BOX_P(0);
628  BOX *box2 = PG_GETARG_BOX_P(1);
629 
630  PG_RETURN_BOOL(FPge(box1->low.y, box2->low.y));
631 }
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:303
#define FPge(A, B)
Definition: geo_decls.h:42
Datum box_overbelow ( PG_FUNCTION_ARGS  )

Definition at line 602 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().

603 {
604  BOX *box1 = PG_GETARG_BOX_P(0);
605  BOX *box2 = PG_GETARG_BOX_P(1);
606 
607  PG_RETURN_BOOL(FPle(box1->high.y, box2->high.y));
608 }
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:303
Point high
Definition: geo_decls.h:104
#define FPle(A, B)
Definition: geo_decls.h:40
Datum box_overlap ( PG_FUNCTION_ARGS  )

Definition at line 518 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().

519 {
520  BOX *box1 = PG_GETARG_BOX_P(0);
521  BOX *box2 = PG_GETARG_BOX_P(1);
522 
523  PG_RETURN_BOOL(box_ov(box1, box2));
524 }
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:527
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
Datum box_overleft ( PG_FUNCTION_ARGS  )

Definition at line 553 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().

554 {
555  BOX *box1 = PG_GETARG_BOX_P(0);
556  BOX *box2 = PG_GETARG_BOX_P(1);
557 
558  PG_RETURN_BOOL(FPle(box1->high.x, box2->high.x));
559 }
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:303
Point high
Definition: geo_decls.h:104
#define FPle(A, B)
Definition: geo_decls.h:40
Datum box_overright ( PG_FUNCTION_ARGS  )

Definition at line 579 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().

580 {
581  BOX *box1 = PG_GETARG_BOX_P(0);
582  BOX *box2 = PG_GETARG_BOX_P(1);
583 
584  PG_RETURN_BOOL(FPge(box1->low.x, box2->low.x));
585 }
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:303
#define FPge(A, B)
Definition: geo_decls.h:42
Datum box_poly ( PG_FUNCTION_ARGS  )

Definition at line 4456 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.

4457 {
4458  BOX *box = PG_GETARG_BOX_P(0);
4459  POLYGON *poly;
4460  int size;
4461 
4462  /* map four corners of the box to a polygon */
4463  size = offsetof(POLYGON, p) +sizeof(poly->p[0]) * 4;
4464  poly = (POLYGON *) palloc(size);
4465 
4466  SET_VARSIZE(poly, size);
4467  poly->npts = 4;
4468 
4469  poly->p[0].x = box->low.x;
4470  poly->p[0].y = box->low.y;
4471  poly->p[1].x = box->low.x;
4472  poly->p[1].y = box->high.y;
4473  poly->p[2].x = box->high.x;
4474  poly->p[2].y = box->high.y;
4475  poly->p[3].x = box->high.x;
4476  poly->p[3].y = box->low.y;
4477 
4478  box_fill(&poly->boundbox, box->high.x, box->low.x,
4479  box->high.y, box->low.y);
4480 
4481  PG_RETURN_POLYGON_P(poly);
4482 }
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:456
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:891
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:330
#define offsetof(type, field)
Definition: c.h:551
Datum box_recv ( PG_FUNCTION_ARGS  )

Definition at line 393 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.

394 {
396  BOX *box;
397  double x,
398  y;
399 
400  box = (BOX *) palloc(sizeof(BOX));
401 
402  box->high.x = pq_getmsgfloat8(buf);
403  box->high.y = pq_getmsgfloat8(buf);
404  box->low.x = pq_getmsgfloat8(buf);
405  box->low.y = pq_getmsgfloat8(buf);
406 
407  /* reorder corners if necessary... */
408  if (box->high.x < box->low.x)
409  {
410  x = box->high.x;
411  box->high.x = box->low.x;
412  box->low.x = x;
413  }
414  if (box->high.y < box->low.y)
415  {
416  y = box->high.y;
417  box->high.y = box->low.y;
418  box->low.y = y;
419  }
420 
421  PG_RETURN_BOX_P(box);
422 }
Definition: geo_decls.h:102
StringInfoData * StringInfo
Definition: stringinfo.h:46
double y
Definition: geo_decls.h:60
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:232
double x
Definition: geo_decls.h:60
static char * buf
Definition: pg_test_fsync.c:65
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:530
Point high
Definition: geo_decls.h:104
void * palloc(Size size)
Definition: mcxt.c:891
Datum box_right ( PG_FUNCTION_ARGS  )

Definition at line 564 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().

565 {
566  BOX *box1 = PG_GETARG_BOX_P(0);
567  BOX *box2 = PG_GETARG_BOX_P(1);
568 
569  PG_RETURN_BOOL(FPgt(box1->low.x, box2->high.x));
570 }
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:303
Point high
Definition: geo_decls.h:104
Datum box_same ( PG_FUNCTION_ARGS  )

Definition at line 504 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().

505 {
506  BOX *box1 = PG_GETARG_BOX_P(0);
507  BOX *box2 = PG_GETARG_BOX_P(1);
508 
509  PG_RETURN_BOOL(FPeq(box1->high.x, box2->high.x) &&
510  FPeq(box1->low.x, box2->low.x) &&
511  FPeq(box1->high.y, box2->high.y) &&
512  FPeq(box1->low.y, box2->low.y));
513 }
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:303
Point high
Definition: geo_decls.h:104
Datum box_send ( PG_FUNCTION_ARGS  )

Definition at line 428 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.

429 {
430  BOX *box = PG_GETARG_BOX_P(0);
432 
433  pq_begintypsend(&buf);
434  pq_sendfloat8(&buf, box->high.x);
435  pq_sendfloat8(&buf, box->high.y);
436  pq_sendfloat8(&buf, box->low.x);
437  pq_sendfloat8(&buf, box->low.y);
439 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:359
void pq_sendfloat8(StringInfo buf, float8 f)
Definition: pqformat.c:324
double y
Definition: geo_decls.h:60
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:313
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:379
double x
Definition: geo_decls.h:60
static char * buf
Definition: pg_test_fsync.c:65
Point low
Definition: geo_decls.h:104
Point high
Definition: geo_decls.h:104
Datum box_sub ( PG_FUNCTION_ARGS  )

Definition at line 4130 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.

4131 {
4132  BOX *box = PG_GETARG_BOX_P(0);
4133  Point *p = PG_GETARG_POINT_P(1);
4134 
4135  PG_RETURN_BOX_P(box_construct((box->high.x - p->x),
4136  (box->low.x - p->x),
4137  (box->high.y - p->y),
4138  (box->low.y - p->y)));
4139 }
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:445
static double box_wd ( BOX box)
static

Definition at line 832 of file geo_ops.c.

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

Referenced by box_ar().

833 {
834  return box->high.x - box->low.x;
835 }
double x
Definition: geo_decls.h:60
Point low
Definition: geo_decls.h:104
Point high
Definition: geo_decls.h:104
Datum box_width ( PG_FUNCTION_ARGS  )

Definition at line 757 of file geo_ops.c.

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

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

Definition at line 4206 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.

4207 {
4208  BOX *box1 = PG_GETARG_BOX_P(0),
4209  *box2 = PG_GETARG_BOX_P(1),
4210  *container;
4211 
4212  container = (BOX *) palloc(sizeof(BOX));
4213 
4214  container->high.x = Max(box1->high.x, box2->high.x);
4215  container->low.x = Min(box1->low.x, box2->low.x);
4216  container->high.y = Max(box1->high.y, box2->high.y);
4217  container->low.y = Min(box1->low.y, box2->low.y);
4218 
4219  PG_RETURN_BOX_P(container);
4220 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
#define Min(x, y)
Definition: c.h:802
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:796
Point high
Definition: geo_decls.h:104
void * palloc(Size size)
Definition: mcxt.c:891
Datum circle_above ( PG_FUNCTION_ARGS  )

Definition at line 4771 of file geo_ops.c.

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

4772 {
4773  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4774  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4775 
4776  PG_RETURN_BOOL(FPgt((circle1->center.y - circle1->radius),
4777  (circle2->center.y + circle2->radius)));
4778 }
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:303
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126
Datum circle_add_pt ( PG_FUNCTION_ARGS  )

Definition at line 4887 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.

4888 {
4889  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4890  Point *point = PG_GETARG_POINT_P(1);
4891  CIRCLE *result;
4892 
4893  result = circle_copy(circle);
4894 
4895  result->center.x += point->x;
4896  result->center.y += point->y;
4897 
4898  PG_RETURN_CIRCLE_P(result);
4899 }
double y
Definition: geo_decls.h:60
static CIRCLE * circle_copy(CIRCLE *circle)
Definition: geo_ops.c:4870
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
static double circle_ar ( CIRCLE circle)
static

Definition at line 5087 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().

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

Definition at line 4964 of file geo_ops.c.

References circle_ar(), PG_GETARG_CIRCLE_P, and PG_RETURN_FLOAT8.

4965 {
4966  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4967 
4968  PG_RETURN_FLOAT8(circle_ar(circle));
4969 }
static double circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5087
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:310
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Datum circle_below ( PG_FUNCTION_ARGS  )

Definition at line 4759 of file geo_ops.c.

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

4760 {
4761  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4762  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4763 
4764  PG_RETURN_BOOL(FPlt((circle1->center.y + circle1->radius),
4765  (circle2->center.y - circle2->radius)));
4766 }
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
#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
Datum circle_box ( PG_FUNCTION_ARGS  )

Definition at line 5114 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.

5115 {
5116  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5117  BOX *box;
5118  double delta;
5119 
5120  box = (BOX *) palloc(sizeof(BOX));
5121 
5122  delta = circle->radius / sqrt(2.0);
5123 
5124  box->high.x = circle->center.x + delta;
5125  box->low.x = circle->center.x - delta;
5126  box->high.y = circle->center.y + delta;
5127  box->low.y = circle->center.y - delta;
5128 
5129  PG_RETURN_BOX_P(box);
5130 }
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:891
Datum circle_center ( PG_FUNCTION_ARGS  )

Definition at line 5071 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().

5072 {
5073  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5074  Point *result;
5075 
5076  result = (Point *) palloc(sizeof(Point));
5077  result->x = circle->center.x;
5078  result->y = circle->center.y;
5079 
5080  PG_RETURN_POINT_P(result);
5081 }
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:891
Datum circle_contain ( PG_FUNCTION_ARGS  )

Definition at line 4747 of file geo_ops.c.

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

4748 {
4749  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4750  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4751 
4752  PG_RETURN_BOOL(FPle((point_dt(&circle1->center, &circle2->center) + circle2->radius), circle1->radius));
4753 }
double radius
Definition: geo_decls.h:127
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
#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:1906
#define FPle(A, B)
Definition: geo_decls.h:40
Datum circle_contain_pt ( PG_FUNCTION_ARGS  )

Definition at line 5013 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().

5014 {
5015  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5016  Point *point = PG_GETARG_POINT_P(1);
5017  double d;
5018 
5019  d = point_dt(&circle->center, point);
5020  PG_RETURN_BOOL(d <= circle->radius);
5021 }
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
#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:1906
Datum circle_contained ( PG_FUNCTION_ARGS  )

Definition at line 4736 of file geo_ops.c.

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

4737 {
4738  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4739  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4740 
4741  PG_RETURN_BOOL(FPle((point_dt(&circle1->center, &circle2->center) + circle1->radius), circle2->radius));
4742 }
double radius
Definition: geo_decls.h:127
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
#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:1906
#define FPle(A, B)
Definition: geo_decls.h:40
static CIRCLE * circle_copy ( CIRCLE circle)
static

Definition at line 4870 of file geo_ops.c.

References NULL, palloc(), and PointerIsValid.

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

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

Definition at line 4975 of file geo_ops.c.

References PG_GETARG_CIRCLE_P, PG_RETURN_FLOAT8, and CIRCLE::radius.

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

Definition at line 4998 of file geo_ops.c.

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

4999 {
5000  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
5001  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
5002  float8 result;
5003 
5004  result = point_dt(&circle1->center, &circle2->center)
5005  - (circle1->radius + circle2->radius);
5006  if (result < 0)
5007  result = 0;
5008  PG_RETURN_FLOAT8(result);
5009 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:310
double radius
Definition: geo_decls.h:127
double float8
Definition: c.h:378
#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:1906
Datum circle_div_pt ( PG_FUNCTION_ARGS  )

Definition at line 4941 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.

4942 {
4943  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4944  Point *point = PG_GETARG_POINT_P(1);
4945  CIRCLE *result;
4946  Point *p;
4947 
4948  result = circle_copy(circle);
4949 
4951  PointPGetDatum(&circle->center),
4952  PointPGetDatum(point)));
4953  result->center.x = p->x;
4954  result->center.y = p->y;
4955  result->radius /= HYPOT(point->x, point->y);
4956 
4957  PG_RETURN_CIRCLE_P(result);
4958 }
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
static CIRCLE * circle_copy(CIRCLE *circle)
Definition: geo_ops.c:4870
double x
Definition: geo_decls.h:60
Datum point_div(PG_FUNCTION_ARGS)
Definition: geo_ops.c:4079
#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:557
#define PointPGetDatum(X)
Definition: geo_decls.h:138
Datum circle_eq ( PG_FUNCTION_ARGS  )

Definition at line 4811 of file geo_ops.c.

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

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

Definition at line 4856 of file geo_ops.c.

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

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

Definition at line 4838 of file geo_ops.c.

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

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

Definition at line 4533 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(), Point::x, and Point::y.

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

Definition at line 4847 of file geo_ops.c.

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

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

Definition at line 4699 of file geo_ops.c.

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

4700 {
4701  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4702  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4703 
4704  PG_RETURN_BOOL(FPlt((circle1->center.x + circle1->radius),
4705  (circle2->center.x - circle2->radius)));
4706 }
double radius
Definition: geo_decls.h:127
double x
Definition: geo_decls.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
#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
Datum circle_lt ( PG_FUNCTION_ARGS  )

Definition at line 4829 of file geo_ops.c.

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

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

Definition at line 4921 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.

4922 {
4923  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4924  Point *point = PG_GETARG_POINT_P(1);
4925  CIRCLE *result;
4926  Point *p;
4927 
4928  result = circle_copy(circle);
4929 
4931  PointPGetDatum(&circle->center),
4932  PointPGetDatum(point)));
4933  result->center.x = p->x;
4934  result->center.y = p->y;
4935  result->radius *= HYPOT(point->x, point->y);
4936 
4937  PG_RETURN_CIRCLE_P(result);
4938 }
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
static CIRCLE * circle_copy(CIRCLE *circle)
Definition: geo_ops.c:4870
double x
Definition: geo_decls.h:60
Datum point_mul(PG_FUNCTION_ARGS)
Definition: geo_ops.c:4064
#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:557
#define PointPGetDatum(X)
Definition: geo_decls.h:138
Datum circle_ne ( PG_FUNCTION_ARGS  )

Definition at line 4820 of file geo_ops.c.

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

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

Definition at line 4595 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(), Point::x, and Point::y.

4596 {
4597  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4598  StringInfoData str;
4599 
4600  initStringInfo(&str);
4601 
4604  pair_encode(circle->center.x, circle->center.y, &str);
4606  appendStringInfoChar(&str, DELIM);
4607  single_encode(circle->radius, &str);
4609 
4610  PG_RETURN_CSTRING(str.data);
4611 }
static void single_encode(float8 x, StringInfo str)
Definition: geo_ops.c:132
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:183
double x
Definition: geo_decls.h:60
#define DELIM
Definition: geo_ops.c:92
#define LDELIM
Definition: geo_ops.c:90
#define RDELIM
Definition: geo_ops.c:91
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:201
void initStringInfo(StringInfo str)
Definition: stringinfo.c:65
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:306
#define LDELIM_C
Definition: geo_ops.c:95
Point center
Definition: geo_decls.h:126
#define RDELIM_C
Definition: geo_ops.c:96
Datum circle_overabove ( PG_FUNCTION_ARGS  )

Definition at line 4797 of file geo_ops.c.

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

4798 {
4799  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4800  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4801 
4802  PG_RETURN_BOOL(FPge((circle1->center.y - circle1->radius),
4803  (circle2->center.y - circle2->radius)));
4804 }
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
#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
Datum circle_overbelow ( PG_FUNCTION_ARGS  )

Definition at line 4784 of file geo_ops.c.

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

4785 {
4786  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4787  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4788 
4789  PG_RETURN_BOOL(FPle((circle1->center.y + circle1->radius),
4790  (circle2->center.y + circle2->radius)));
4791 }
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
#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
Datum circle_overlap ( PG_FUNCTION_ARGS  )

Definition at line 4674 of file geo_ops.c.

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

4675 {
4676  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4677  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4678 
4679  PG_RETURN_BOOL(FPle(point_dt(&circle1->center, &circle2->center),
4680  circle1->radius + circle2->radius));
4681 }
double radius
Definition: geo_decls.h:127
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
#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:1906
#define FPle(A, B)
Definition: geo_decls.h:40
Datum circle_overleft ( PG_FUNCTION_ARGS  )

Definition at line 4687 of file geo_ops.c.

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

4688 {
4689  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4690  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4691 
4692  PG_RETURN_BOOL(FPle((circle1->center.x + circle1->radius),
4693  (circle2->center.x + circle2->radius)));
4694 }
double radius
Definition: geo_decls.h:127
double x
Definition: geo_decls.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
#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
Datum circle_overright ( PG_FUNCTION_ARGS  )

Definition at line 4724 of file geo_ops.c.

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

4725 {
4726  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4727  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4728 
4729  PG_RETURN_BOOL(FPge((circle1->center.x - circle1->radius),
4730  (circle2->center.x - circle2->radius)));
4731 }
double radius
Definition: geo_decls.h:127
double x
Definition: geo_decls.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
#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
Datum circle_poly ( PG_FUNCTION_ARGS  )

Definition at line 5153 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.

5154 {
5155  int32 npts = PG_GETARG_INT32(0);
5156  CIRCLE *circle = PG_GETARG_CIRCLE_P(1);
5157  POLYGON *poly;
5158  int base_size,
5159  size;
5160  int i;
5161  double angle;
5162  double anglestep;
5163 
5164  if (FPzero(circle->radius))
5165  ereport(ERROR,
5166  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5167  errmsg("cannot convert circle with radius zero to polygon")));
5168 
5169  if (npts < 2)
5170  ereport(ERROR,
5171  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5172  errmsg("must request at least 2 points")));
5173 
5174  base_size = sizeof(poly->p[0]) * npts;
5175  size = offsetof(POLYGON, p) +base_size;
5176 
5177  /* Check for integer overflow */
5178  if (base_size / npts != sizeof(poly->p[0]) || size <= base_size)
5179  ereport(ERROR,
5180  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
5181  errmsg("too many points requested")));
5182 
5183  poly = (POLYGON *) palloc0(size); /* zero any holes */
5184  SET_VARSIZE(poly, size);
5185  poly->npts = npts;
5186 
5187  anglestep = (2.0 * M_PI) / npts;
5188 
5189  for (i = 0; i < npts; i++)
5190  {
5191  angle = i * anglestep;
5192  poly->p[i].x = circle->center.x - (circle->radius * cos(angle));
5193  poly->p[i].y = circle->center.y + (circle->radius * sin(angle));
5194  }
5195 
5196  make_bound_box(poly);
5197 
5198  PG_RETURN_POLYGON_P(poly);
5199 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:225
#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:253
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:920
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
static void make_bound_box(POLYGON *poly)
Definition: geo_ops.c:3377
#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:330
#define offsetof(type, field)
Definition: c.h:551
Datum circle_radius ( PG_FUNCTION_ARGS  )

Definition at line 4986 of file geo_ops.c.

References PG_GETARG_CIRCLE_P, PG_RETURN_FLOAT8, and CIRCLE::radius.

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

Definition at line 4617 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.

4618 {
4620  CIRCLE *circle;
4621 
4622  circle = (CIRCLE *) palloc(sizeof(CIRCLE));
4623 
4624  circle->center.x = pq_getmsgfloat8(buf);
4625  circle->center.y = pq_getmsgfloat8(buf);
4626  circle->radius = pq_getmsgfloat8(buf);
4627 
4628  if (circle->radius < 0)
4629  ereport(ERROR,
4630  (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
4631  errmsg("invalid radius in external \"circle\" value")));
4632 
4633  PG_RETURN_CIRCLE_P(circle);
4634 }
StringInfoData * StringInfo
Definition: stringinfo.h:46
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:232
double x
Definition: geo_decls.h:60
#define ERROR
Definition: elog.h:43
static char * buf
Definition: pg_test_fsync.c:65
#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:530
Point center
Definition: geo_decls.h:126
void * palloc(Size size)
Definition: mcxt.c:891
int errmsg(const char *fmt,...)
Definition: elog.c:797
Datum circle_right ( PG_FUNCTION_ARGS  )

Definition at line 4711 of file geo_ops.c.

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

4712 {
4713  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4714  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4715 
4716  PG_RETURN_BOOL(FPgt((circle1->center.x - circle1->radius),
4717  (circle2->center.x + circle2->radius)));
4718 }
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:303
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126
Datum circle_same ( PG_FUNCTION_ARGS  )

Definition at line 4661 of file geo_ops.c.

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

4662 {
4663  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4664  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4665 
4666  PG_RETURN_BOOL(FPeq(circle1->radius, circle2->radius) &&
4667  FPeq(circle1->center.x, circle2->center.x) &&
4668  FPeq(circle1->center.y, circle2->center.y));
4669 }
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:303
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126
Datum circle_send ( PG_FUNCTION_ARGS  )

Definition at line 4640 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.

4641 {
4642  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4644 
4645  pq_begintypsend(&buf);
4646  pq_sendfloat8(&buf, circle->center.x);
4647  pq_sendfloat8(&buf, circle->center.y);
4648  pq_sendfloat8(&buf, circle->radius);
4650 }
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:359
void pq_sendfloat8(StringInfo buf, float8 f)
Definition: pqformat.c:324
double radius
Definition: geo_decls.h:127
double y
Definition: geo_decls.h:60
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:313
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:379
double x
Definition: geo_decls.h:60
static char * buf
Definition: pg_test_fsync.c:65
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:173
Point center
Definition: geo_decls.h:126
Datum circle_sub_pt ( PG_FUNCTION_ARGS  )

Definition at line 4902 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.

4903 {
4904  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4905  Point *point = PG_GETARG_POINT_P(1);
4906  CIRCLE *result;
4907 
4908  result = circle_copy(circle);
4909 
4910  result->center.x -= point->x;
4911  result->center.y -= point->y;
4912 
4913  PG_RETURN_CIRCLE_P(result);
4914 }
double y
Definition: geo_decls.h:60
static CIRCLE * circle_copy(CIRCLE *circle)
Definition: geo_ops.c:4870
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
Datum close_lb ( PG_FUNCTION_ARGS  )

Definition at line 3107 of file geo_ops.c.

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

3108 {
3109 #ifdef NOT_USED
3110  LINE *line = PG_GETARG_LINE_P(0);
3111  BOX *box = PG_GETARG_BOX_P(1);
3112 #endif
3113 
3114  /* think about this one for a while */
3115  ereport(ERROR,
3116  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3117  errmsg("function \"close_lb\" not implemented")));
3118 
3119  PG_RETURN_NULL();
3120 }
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:289
Datum close_ls ( PG_FUNCTION_ARGS  )

Definition at line 3024 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().

3025 {
3026  LINE *line = PG_GETARG_LINE_P(0);
3027  LSEG *lseg = PG_GETARG_LSEG_P(1);
3028  Point *result;
3029  float8 d1,
3030  d2;
3031 
3032  result = interpt_sl(lseg, line);
3033  if (result)
3034  PG_RETURN_POINT_P(result);
3035 
3036  d1 = dist_pl_internal(&lseg->p[0], line);
3037  d2 = dist_pl_internal(&lseg->p[1], line);
3038  if (d1 < d2)
3039  result = point_copy(&lseg->p[0]);
3040  else
3041  result = point_copy(&lseg->p[1]);
3042 
3043  PG_RETURN_POINT_P(result);
3044 }
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:144
static Point * interpt_sl(LSEG *lseg, LINE *line)
Definition: geo_ops.c:2661
Definition: geo_decls.h:68
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:156
double float8
Definition: c.h:378
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:1796
Point p[2]
Definition: geo_decls.h:70
static double dist_pl_internal(Point *pt, LINE *line)
Definition: geo_ops.c:2348
Datum close_lseg ( PG_FUNCTION_ARGS  )

Definition at line 2880 of file geo_ops.c.

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

Referenced by close_sb().

2881 {
2882  LSEG *l1 = PG_GETARG_LSEG_P(0);
2883  LSEG *l2 = PG_GETARG_LSEG_P(1);
2884  Point *result = NULL;
2885  Point point;
2886  double dist;
2887  double d;
2888 
2889  d = dist_ps_internal(&l1->p[0], l2);
2890  dist = d;
2891  memcpy(&point, &l1->p[0], sizeof(Point));
2892 
2893  if ((d = dist_ps_internal(&l1->p[1], l2)) < dist)
2894  {
2895  dist = d;
2896  memcpy(&point, &l1->p[1], sizeof(Point));
2897  }
2898 
2899  if (dist_ps_internal(&l2->p[0], l1) < dist)
2900  {
2902  PointPGetDatum(&l2->p[0]),
2903  LsegPGetDatum(l1)));
2904  memcpy(&point, result, sizeof(Point));
2906  PointPGetDatum(&point),
2907  LsegPGetDatum(l2)));
2908  }
2909 
2910  if (dist_ps_internal(&l2->p[1], l1) < dist)
2911  {
2913  PointPGetDatum(&l2->p[1]),
2914  LsegPGetDatum(l1)));
2915  memcpy(&point, result, sizeof(Point));
2917  PointPGetDatum(&point),
2918  LsegPGetDatum(l2)));
2919  }
2920 
2921  if (result == NULL)
2922  result = point_copy(&point);
2923 
2924  PG_RETURN_POINT_P(result);
2925 }
#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:1796
#define NULL
Definition: c.h:226
static double dist_ps_internal(Point *pt, LSEG *lseg)
Definition: geo_ops.c:2367
#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:2758
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:557
#define PointPGetDatum(X)
Definition: geo_decls.h:138
Datum close_pb ( PG_FUNCTION_ARGS  )

Definition at line 2931 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().

2932 {
2933  Point *pt = PG_GETARG_POINT_P(0);
2934  BOX *box = PG_GETARG_BOX_P(1);
2935  LSEG lseg,
2936  seg;
2937  Point point;
2938  double dist,
2939  d;
2940 
2942  PointPGetDatum(pt),
2943  BoxPGetDatum(box))))
2944  PG_RETURN_POINT_P(pt);
2945 
2946  /* pairwise check lseg distances */
2947  point.x = box->low.x;
2948  point.y = box->high.y;
2949  statlseg_construct(&lseg, &box->low, &point);
2950  dist = dist_ps_internal(pt, &lseg);
2951 
2952  statlseg_construct(&seg, &box->high, &point);
2953  if ((d = dist_ps_internal(pt, &seg)) < dist)
2954  {
2955  dist = d;
2956  memcpy(&lseg, &seg, sizeof(lseg));
2957  }
2958 
2959  point.x = box->high.x;
2960  point.y = box->low.y;
2961  statlseg_construct(&seg, &box->low, &point);
2962  if ((d = dist_ps_internal(pt, &seg)) < dist)
2963  {
2964  dist = d;
2965  memcpy(&lseg, &seg, sizeof(lseg));
2966  }
2967 
2968  statlseg_construct(&seg, &box->high, &point);
2969  if ((d = dist_ps_internal(pt, &seg)) < dist)
2970  {
2971  dist = d;
2972  memcpy(&lseg, &seg, sizeof(lseg));
2973  }
2974 
2976  PointPGetDatum(pt),
2977  LsegPGetDatum(&lseg)));
2978 }
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:2026
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:401
Datum on_pb(PG_FUNCTION_ARGS)
Definition: geo_ops.c:3161
Point low
Definition: geo_decls.h:104
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:297
#define BoxPGetDatum(X)
Definition: geo_decls.h:160
static double dist_ps_internal(Point *pt, LSEG *lseg)
Definition: geo_ops.c:2367
Point high
Definition: geo_decls.h:104
Datum close_ps(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2758
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:557
#define PointPGetDatum(X)
Definition: geo_decls.h:138
Datum close_pl ( PG_FUNCTION_ARGS  )

Definition at line 2714 of file geo_ops.c.

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

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

Definition at line 2758 of file geo_ops.c.

References LINE::A, LINE::B, LINE::C, FPeq, interpt_sl(), line_construct_pm(), NULL, 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().

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

Definition at line 3050 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().

3051 {
3052  LSEG *lseg = PG_GETARG_LSEG_P(0);
3053  BOX *box = PG_GETARG_BOX_P(1);
3054  Point point;
3055  LSEG bseg,
3056  seg;
3057  double dist,
3058  d;
3059 
3060  /* segment intersects box? then just return closest point to center */
3062  LsegPGetDatum(lseg),
3063  BoxPGetDatum(box))))
3064  {
3065  box_cn(&point, box);
3067  PointPGetDatum(&point),
3068  LsegPGetDatum(lseg)));
3069  }
3070 
3071  /* pairwise check lseg distances */
3072  point.x = box->low.x;
3073  point.y = box->high.y;
3074  statlseg_construct(&bseg, &box->low, &point);
3075  dist = lseg_dt(lseg, &bseg);
3076 
3077  statlseg_construct(&seg, &box->high, &point);
3078  if ((d = lseg_dt(lseg, &seg)) < dist)
3079  {
3080  dist = d;
3081  memcpy(&bseg, &seg, sizeof(bseg));
3082  }
3083 
3084  point.x = box->high.x;
3085  point.y = box->low.y;
3086  statlseg_construct(&seg, &box->low, &point);
3087  if ((d = lseg_dt(lseg, &seg)) < dist)
3088  {
3089  dist = d;
3090  memcpy(&bseg, &seg, sizeof(bseg));
3091  }
3092 
3093  statlseg_construct(&seg, &box->high, &point);
3094  if ((d = lseg_dt(lseg, &seg)) < dist)
3095  {
3096  dist = d;
3097  memcpy(&bseg, &seg, sizeof(bseg));
3098  }
3099 
3100  /* OK, we now have the closest line segment on the box boundary */
3102  LsegPGetDatum(lseg),
3103  LsegPGetDatum(&bseg)));
3104 }
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:2026
Definition: geo_decls.h:68
Datum inter_sb(PG_FUNCTION_ARGS)
Definition: geo_ops.c:3274
double y
Definition: geo_decls.h:60
static void box_cn(Point *center, BOX *box)
Definition: geo_ops.c:821
double x
Definition: geo_decls.h:60
static double lseg_dt(LSEG *l1, LSEG *l2)
Definition: geo_ops.c:2223
#define LsegPGetDatum(X)
Definition: geo_decls.h:143
#define DatumGetBool(X)
Definition: postgres.h:401
Point low
Definition: geo_decls.h:104
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:297
#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:2758
Datum close_lseg(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2880
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:557
#define PointPGetDatum(X)
Definition: geo_decls.h:138
Datum close_sl ( PG_FUNCTION_ARGS  )

Definition at line 2990 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().

2991 {
2992 #ifdef NOT_USED
2993  LSEG *lseg = PG_GETARG_LSEG_P(0);
2994  LINE *line = PG_GETARG_LINE_P(1);
2995  Point *result;
2996  float8 d1,
2997  d2;
2998 
2999  result = interpt_sl(lseg, line);
3000  if (result)
3001  PG_RETURN_POINT_P(result);
3002 
3003  d1 = dist_pl_internal(&lseg->p[0], line);
3004  d2 = dist_pl_internal(&lseg->p[1], line);
3005  if (d1 < d2)
3006  result = point_copy(&lseg->p[0]);
3007  else
3008  result = point_copy(&lseg->p[1]);
3009 
3010  PG_RETURN_POINT_P(result);
3011 #endif
3012 
3013  ereport(ERROR,
3014  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3015  errmsg("function \"close_sl\" not implemented")));
3016 
3017  PG_RETURN_NULL();
3018 }
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:144
static Point * interpt_sl(LSEG *lseg, LINE *line)
Definition: geo_ops.c:2661
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:378
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:1796
#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:2348
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_RETURN_NULL()
Definition: fmgr.h:289
Datum construct_point ( PG_FUNCTION_ARGS  )

Definition at line 4025 of file geo_ops.c.

References PG_GETARG_FLOAT8, PG_RETURN_POINT_P, and point_construct().

4026 {
4027  float8 x = PG_GETARG_FLOAT8(0);
4028  float8 y = PG_GETARG_FLOAT8(1);
4029 
4031 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:237
static Point * point_construct(double x, double y)
Definition: geo_ops.c:1785
double float8
Definition: c.h:378
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:140
Datum cr_circle ( PG_FUNCTION_ARGS  )

Definition at line 5098 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.

5099 {
5100  Point *center = PG_GETARG_POINT_P(0);
5101  float8 radius = PG_GETARG_FLOAT8(1);
5102  CIRCLE *result;
5103 
5104  result = (CIRCLE *) palloc(sizeof(CIRCLE));
5105 
5106  result->center.x = center->x;
5107  result->center.y = center->y;
5108  result->radius = radius;
5109 
5110  PG_RETURN_CIRCLE_P(result);
5111 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:237
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:378
#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:891
Datum dist_cpoint ( PG_FUNCTION_ARGS  )

Definition at line 5056 of file geo_ops.c.

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

5057 {
5058  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5059  Point *point = PG_GETARG_POINT_P(1);
5060  float8 result;
5061 
5062  result = point_dt(point, &circle->center) - circle->radius;
5063  if (result < 0)
5064  result = 0;
5065  PG_RETURN_FLOAT8(result);
5066 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:310
double radius
Definition: geo_decls.h:127
double float8
Definition: c.h:378
#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:1906
Datum dist_cpoly ( PG_FUNCTION_ARGS  )

Definition at line 2564 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.

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

Definition at line 2545 of file geo_ops.c.

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

2546 {
2547 #ifdef NOT_USED
2548  LINE *line = PG_GETARG_LINE_P(0);
2549  BOX *box = PG_GETARG_BOX_P(1);
2550 #endif
2551 
2552  /* need to think about this one for a while */
2553  ereport(ERROR,
2554  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2555  errmsg("function \"dist_lb\" not implemented")));
2556 
2557  PG_RETURN_NULL();
2558 }
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:289
Datum dist_pb ( PG_FUNCTION_ARGS  )

Definition at line 2480 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().

2481 {
2482  Point *pt = PG_GETARG_POINT_P(0);
2483  BOX *box = PG_GETARG_BOX_P(1);
2484  float8 result;
2485  Point *near;
2486 
2488  PointPGetDatum(pt),
2489  BoxPGetDatum(box)));
2490  result = point_dt(near, pt);
2491 
2492  PG_RETURN_FLOAT8(result);
2493 }
Definition: geo_decls.h:102
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:310
double float8
Definition: c.h:378
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
Datum close_pb(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2931
#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:1906
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:557
#define PointPGetDatum(X)
Definition: geo_decls.h:138
Datum dist_pc ( PG_FUNCTION_ARGS  )

Definition at line 5040 of file geo_ops.c.

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

5041 {
5042  Point *point = PG_GETARG_POINT_P(0);
5043  CIRCLE *circle = PG_GETARG_CIRCLE_P(1);
5044  float8 result;
5045 
5046  result = point_dt(point, &circle->center) - circle->radius;
5047  if (result < 0)
5048  result = 0;
5049  PG_RETURN_FLOAT8(result);
5050 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:310
double radius
Definition: geo_decls.h:127
double float8
Definition: c.h:378
#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:1906
Datum dist_pl ( PG_FUNCTION_ARGS  )

Definition at line 2339 of file geo_ops.c.

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

2340 {
2341  Point *pt = PG_GETARG_POINT_P(0);
2342  LINE *line = PG_GETARG_LINE_P(1);
2343 
2345 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:310
#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:2348
static double dist_pl_internal ( Point pt,
LINE line 
)
static

Definition at line 2348 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().

2349 {
2350  return fabs((line->A * pt->x + line->B * pt->y + line->C) /
2351  HYPOT(line->A, line->B));
2352 }
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
Datum dist_polyp ( PG_FUNCTION_ARGS  )

Definition at line 2596 of file geo_ops.c.

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

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

Definition at line 2423 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().

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

Definition at line 2584 of file geo_ops.c.

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

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

Definition at line 2608 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().

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

Definition at line 2358 of file geo_ops.c.

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

Referenced by regress_dist_ptpath().

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

Definition at line 2367 of file geo_ops.c.

References LINE::A, LINE::B, LINE::C, interpt_sl(), line_construct_pm(), NULL, 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().

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

Definition at line 2524 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.

2525 {
2526  LSEG *lseg = PG_GETARG_LSEG_P(0);
2527  BOX *box = PG_GETARG_BOX_P(1);
2528  Point *tmp;
2529  Datum result;
2530 
2532  LsegPGetDatum(lseg),
2533  BoxPGetDatum(box)));
2534  result = DirectFunctionCall2(dist_pb,
2535  PointPGetDatum(tmp),
2536  BoxPGetDatum(box));
2537 
2538  PG_RETURN_DATUM(result);
2539 }
Datum dist_pb(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2480
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:374
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:297
#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:3050
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:557
#define PointPGetDatum(X)
Definition: geo_decls.h:138
Datum dist_sl ( PG_FUNCTION_ARGS  )

Definition at line 2499 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.

2500 {
2501  LSEG *lseg = PG_GETARG_LSEG_P(0);
2502  LINE *line = PG_GETARG_LINE_P(1);
2503  float8 result,
2504  d2;
2505 
2506  if (has_interpt_sl(lseg, line))
2507  result = 0.0;
2508  else
2509  {
2510  result = dist_pl_internal(&lseg->p[0], line);
2511  d2 = dist_pl_internal(&lseg->p[1], line);
2512  /* XXX shouldn't we take the min not max? */
2513  if (d2 > result)
2514  result = d2;
2515  }
2516 
2517  PG_RETURN_FLOAT8(result);
2518 }
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:144
Definition: geo_decls.h:68
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:310
static bool has_interpt_sl(LSEG *lseg, LINE *line)
Definition: geo_ops.c:2694
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:156
double float8
Definition: c.h:378
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:2348
static bool has_interpt_sl ( LSEG lseg,
LINE line 
)
static

Definition at line 2694 of file geo_ops.c.

References interpt_sl().

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

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

Definition at line 3329 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.

3330 {
3331  LINE *line = PG_GETARG_LINE_P(0);
3332  BOX *box = PG_GETARG_BOX_P(1);
3333  LSEG bseg;
3334  Point p1,
3335  p2;
3336 
3337  /* pairwise check lseg intersections */
3338  p1.x = box->low.x;
3339  p1.y = box->low.y;
3340  p2.x = box->low.x;
3341  p2.y = box->high.y;
3342  statlseg_construct(&bseg, &p1, &p2);
3343  if (has_interpt_sl(&bseg, line))
3344  PG_RETURN_BOOL(true);
3345  p1.x = box->high.x;
3346  p1.y = box->high.y;
3347  statlseg_construct(&bseg, &p1, &p2);
3348  if (has_interpt_sl(&bseg, line))
3349  PG_RETURN_BOOL(true);
3350  p2.x = box->high.x;
3351  p2.y = box->low.y;
3352  statlseg_construct(&bseg, &p1, &p2);
3353  if (has_interpt_sl(&bseg, line))
3354  PG_RETURN_BOOL(true);
3355  p1.x = box->low.x;
3356  p1.y = box->low.y;
3357  statlseg_construct(&bseg, &p1, &p2);
3358  if (has_interpt_sl(&bseg, line))
3359  PG_RETURN_BOOL(true);
3360 
3361  /* if we dropped through, no intersection */
3362  PG_RETURN_BOOL(false);
3363 }
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:2026
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:2694
#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:303
Point high
Definition: geo_decls.h:104
Datum inter_sb ( PG_FUNCTION_ARGS  )

Definition at line 3274 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().

3275 {
3276  LSEG *lseg = PG_GETARG_LSEG_P(0);
3277  BOX *box = PG_GETARG_BOX_P(1);
3278  BOX lbox;
3279  LSEG bseg;
3280  Point point;
3281 
3282  lbox.low.x = Min(lseg->p[0].x, lseg->p[1].x);
3283  lbox.low.y = Min(lseg->p[0].y, lseg->p[1].y);
3284  lbox.high.x = Max(lseg->p[0].x, lseg->p[1].x);
3285  lbox.high.y = Max(lseg->p[0].y, lseg->p[1].y);
3286 
3287  /* nothing close to overlap? then not going to intersect */
3288  if (!box_ov(&lbox, box))
3289  PG_RETURN_BOOL(false);
3290 
3291  /* an endpoint of segment is inside box? then clearly intersects */
3293  PointPGetDatum(&lseg->p[0]),
3294  BoxPGetDatum(box))) ||
3296  PointPGetDatum(&lseg->p[1]),
3297  BoxPGetDatum(box))))
3298  PG_RETURN_BOOL(true);
3299 
3300  /* pairwise check lseg intersections */
3301  point.x = box->low.x;
3302  point.y = box->high.y;
3303  statlseg_construct(&bseg, &box->low, &point);
3304  if (lseg_intersect_internal(&bseg, lseg))
3305  PG_RETURN_BOOL(true);
3306 
3307  statlseg_construct(&bseg, &box->high, &point);
3308  if (lseg_intersect_internal(&bseg, lseg))
3309  PG_RETURN_BOOL(true);
3310 
3311  point.x = box->high.x;
3312  point.y = box->low.y;
3313  statlseg_construct(&bseg, &box->low, &point);
3314  if (lseg_intersect_internal(&bseg, lseg))
3315  PG_RETURN_BOOL(true);
3316 
3317  statlseg_construct(&bseg, &box->high, &point);
3318  if (lseg_intersect_internal(&bseg, lseg))
3319  PG_RETURN_BOOL(true);
3320 
3321  /* if we dropped through, no two segs intersected */
3322  PG_RETURN_BOOL(false);
3323 }
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:2026
Definition: geo_decls.h:68
#define Min(x, y)
Definition: c.h:802
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:527
#define DatumGetBool(X)
Definition: postgres.h:401
Datum on_pb(PG_FUNCTION_ARGS)
Definition: geo_ops.c:3161
Point low
Definition: geo_decls.h:104
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
#define BoxPGetDatum(X)
Definition: geo_decls.h:160
#define Max(x, y)
Definition: c.h:796
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:2060
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:557
#define PointPGetDatum(X)
Definition: geo_decls.h:138
Datum inter_sl ( PG_FUNCTION_ARGS  )

Definition at line 3255 of file geo_ops.c.

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

3256 {
3257  LSEG *lseg = PG_GETARG_LSEG_P(0);
3258  LINE *line = PG_GETARG_LINE_P(1);
3259 
3260  PG_RETURN_BOOL(has_interpt_sl(lseg, line));
3261 }
#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:2694
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:156
Definition: geo_decls.h:90
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
static Point * interpt_sl ( LSEG lseg,
LINE line 
)
static

Definition at line 2661 of file geo_ops.c.

References LINE::A, LINE::B, LINE::C, line_construct_pts(), line_interpt_internal(), NULL, 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().

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

Definition at line 1011 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().

1012 {
1013  LINE *result = (LINE *) palloc(sizeof(LINE));
1014 
1015  if (m == DBL_MAX)
1016  {
1017  /* vertical - use "x = C" */
1018  result->A = -1;
1019  result->B = 0;
1020  result->C = pt->x;
1021  }
1022  else
1023  {
1024  /* use "mx - y + yinter = 0" */
1025  result->A = m;
1026  result->B = -1.0;
1027  result->C = pt->y - m * pt->x;
1028  }
1029 
1030  return result;
1031 }
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:891
Datum line_construct_pp ( PG_FUNCTION_ARGS  )

Definition at line 1079 of file geo_ops.c.

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

1080 {
1081  Point *pt1 = PG_GETARG_POINT_P(0);
1082  Point *pt2 = PG_GETARG_POINT_P(1);
1083  LINE *result = (LINE *) palloc(sizeof(LINE));
1084 
1085  line_construct_pts(result, pt1, pt2);
1086  PG_RETURN_LINE_P(result);
1087 }
#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:1037
#define PG_RETURN_LINE_P(x)
Definition: geo_decls.h:157
void * palloc(Size size)
Definition: mcxt.c:891
static void line_construct_pts ( LINE line,
Point pt1,
Point pt2 
)
static

Definition at line 1037 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().

1038 {
1039  if (FPeq(pt1->x, pt2->x))
1040  { /* vertical */
1041  /* use "x = C" */
1042  line->A = -1;
1043  line->B = 0;
1044  line->C = pt1->x;
1045 #ifdef GEODEBUG
1046  printf("line_construct_pts- line is vertical\n");
1047 #endif
1048  }
1049  else if (FPeq(pt1->y, pt2->y))
1050  { /* horizontal */
1051  /* use "y = C" */
1052  line->A = 0;
1053  line->B = -1;
1054  line->C = pt1->y;
1055 #ifdef GEODEBUG
1056  printf("line_construct_pts- line is horizontal\n");
1057 #endif
1058  }
1059  else
1060  {
1061  /* use "mx - y + yinter = 0" */
1062  line->A = (pt2->y - pt1->y) / (pt2->x - pt1->x);
1063  line->B = -1.0;
1064  line->C = pt1->y - line->A * pt1->x;
1065  /* on some platforms, the preceding expression tends to produce -0 */
1066  if (line->C == 0.0)
1067  line->C = 0.0;
1068 #ifdef GEODEBUG
1069  printf("line_construct_pts- line is neither vertical nor horizontal (diffs x=%.*g, y=%.*g\n",
1070  DBL_DIG, (pt2->x - pt1->x), DBL_DIG, (pt2->y - pt1->y));
1071 #endif
1072  }
1073 }
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
static bool line_decode ( char *  s,
const char *  str,
LINE line 
)
static

Definition at line 899 of file geo_ops.c.

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

Referenced by line_in().

900 {
901  /* s was already advanced over leading '{' */
902  line->A = single_decode(s, &s, "line", str);
903  if (*s++ != DELIM)
904  return false;
905  line->B = single_decode(s, &s, "line", str);
906  if (*s++ != DELIM)
907  return false;
908  line->C = single_decode(s, &s, "line", str);
909  if (*s++ != '}')
910  return false;
911  while (isspace((unsigned char) *s))
912  s++;
913  if (*s != '\0')
914  return false;
915  return true;
916 }
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:125
double B
Definition: geo_decls.h:92
#define DELIM
Definition: geo_ops.c:92
double C
Definition: geo_decls.h:92
Datum line_distance ( PG_FUNCTION_ARGS  )

Definition at line 1177 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().

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

Definition at line 1148 of file geo_ops.c.

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

1149 {
1150  LINE *l1 = PG_GETARG_LINE_P(0);
1151  LINE *l2 = PG_GETARG_LINE_P(1);
1152  double k;
1153 
1154  if (!FPzero(l2->A))
1155  k = l1->A / l2->A;
1156  else if (!FPzero(l2->B))
1157  k = l1->B / l2->B;
1158  else if (!FPzero(l2->C))
1159  k = l1->C / l2->C;
1160  else
1161  k = 1.0;
1162 
1163  PG_RETURN_BOOL(FPeq(l1->A, k * l2->A) &&
1164  FPeq(l1->B, k * l2->B) &&
1165  FPeq(l1->C, k * l2->C));
1166 }
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:303
double C
Definition: geo_decls.h:92
Datum line_horizontal ( PG_FUNCTION_ARGS  )

Definition at line 1140 of file geo_ops.c.

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

1141 {
1142  LINE *line = PG_GETARG_LINE_P(0);
1143 
1144  PG_RETURN_BOOL(FPzero(line->A));
1145 }
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:303
Datum line_in ( PG_FUNCTION_ARGS  )

Definition at line 919 of file geo_ops.c.

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

920 {
921  char *str = PG_GETARG_CSTRING(0);
922  LINE *line = (LINE *) palloc(sizeof(LINE));
923  LSEG lseg;
924  bool isopen;
925  char *s;
926 
927  s = str;
928  while (isspace((unsigned char) *s))
929  s++;
930  if (*s == '{')
931  {
932  if (!line_decode(s + 1, str, line))
933  ereport(ERROR,
934  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
935  errmsg("invalid input syntax for type %s: \"%s\"",
936  "line", str)));
937  if (FPzero(line->A) && FPzero(line->B))
938  ereport(ERROR,
939  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
940  errmsg("invalid line specification: A and B cannot both be zero")));
941  }
942  else
943  {
944  path_decode(s, true, 2, &(lseg.p[0]), &isopen, NULL, "line", str);
945  if (FPeq(lseg.p[0].x, lseg.p[1].x) && FPeq(lseg.p[0].y, lseg.p[1].y))
946  ereport(ERROR,
947  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
948  errmsg("invalid line specification: must be two distinct points")));
949  line_construct_pts(line, &lseg.p[0], &lseg.p[1]);
950  }
951 
952  PG_RETURN_LINE_P(line);
953 }
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:1037
static bool line_decode(char *s, const char *str, LINE *line)
Definition: geo_ops.c:899
#define NULL
Definition: c.h:226
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:891
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:233
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:194
Datum line_interpt ( PG_FUNCTION_ARGS  )

Definition at line 1199 of file geo_ops.c.

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

1200 {
1201  LINE *l1 = PG_GETARG_LINE_P(0);
1202  LINE *l2 = PG_GETARG_LINE_P(1);
1203  Point *result;
1204 
1205  result = line_interpt_internal(l1, l2);
1206 
1207  if (result == NULL)
1208  PG_RETURN_NULL();
1209  PG_RETURN_POINT_P(result);
1210 }
static Point * line_interpt_internal(LINE *l1, LINE *l2)
Definition: geo_ops.c:1218
#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 NULL
Definition: c.h:226
#define PG_RETURN_NULL()
Definition: fmgr.h:289
static Point * line_interpt_internal ( LINE l1,
LINE l2 
)
static

Definition at line 1218 of file geo_ops.c.

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

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

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

Definition at line 1095 of file geo_ops.c.

References DatumGetBool, DirectFunctionCall2, line_parallel(), LinePGetDatum, PG_GETARG_LINE_P, and PG_RETURN_BOOL.

1096 {
1097  LINE *l1 = PG_GETARG_LINE_P(0);
1098  LINE *l2 = PG_GETARG_LINE_P(1);
1099 
1101  LinePGetDatum(l1),
1102  LinePGetDatum(l2))));
1103 }
Datum line_parallel(PG_FUNCTION_ARGS)
Definition: geo_ops.c:1106
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:156
Definition: geo_decls.h:90
#define DatumGetBool(X)
Definition: postgres.h:401
#define LinePGetDatum(X)
Definition: geo_decls.h:155
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:557
Datum line_out ( PG_FUNCTION_ARGS  )

Definition at line 957 of file geo_ops.c.

References LINE::A, LINE::B, LINE::C, float8out_internal(), PG_GETARG_LINE_P, PG_RETURN_CSTRING, and psprintf().

958 {
959  LINE *line = PG_GETARG_LINE_P(0);
960  char *astr = float8out_internal(line->A);
961  char *bstr = float8out_internal(line->B);
962  char *cstr = float8out_internal(line->C);
963 
964  PG_RETURN_CSTRING(psprintf("{%s,%s,%s}", astr, bstr, cstr));
965 }
double A
Definition: geo_decls.h:92
char * float8out_internal(double num)
Definition: float.c:596
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
double B
Definition: geo_decls.h:92
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:156
Definition: geo_decls.h:90
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:306
double C
Definition: geo_decls.h:92
Datum line_parallel ( PG_FUNCTION_ARGS  )

Definition at line 1106 of file geo_ops.c.

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

Referenced by line_distance(), line_interpt_internal(), and line_intersect().

1107 {
1108  LINE *l1 = PG_GETARG_LINE_P(0);
1109  LINE *l2 = PG_GETARG_LINE_P(1);
1110 
1111  if (FPzero(l1->B))
1112  PG_RETURN_BOOL(FPzero(l2->B));
1113 
1114  PG_RETURN_BOOL(FPeq(l2->A, l1->A * (l2->B / l1->B)));
1115 }
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:303
Datum line_perp (