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

Go to the source code of this file.

Macros

#define LDELIM   '('
 
#define RDELIM   ')'
 
#define DELIM   ','
 
#define LDELIM_EP   '['
 
#define RDELIM_EP   ']'
 
#define LDELIM_C   '<'
 
#define RDELIM_C   '>'
 
#define LDELIM_L   '{'
 
#define RDELIM_L   '}'
 
#define POINT_ON_POLYGON   INT_MAX
 

Enumerations

enum  path_delim { PATH_NONE, PATH_OPEN, PATH_CLOSED }
 

Functions

static void point_construct (Point *result, float8 x, float8 y)
 
static void point_add_point (Point *result, Point *pt1, Point *pt2)
 
static void point_sub_point (Point *result, Point *pt1, Point *pt2)
 
static void point_mul_point (Point *result, Point *pt1, Point *pt2)
 
static void point_div_point (Point *result, Point *pt1, Point *pt2)
 
static bool point_eq_point (Point *pt1, Point *pt2)
 
static float8 point_dt (Point *pt1, Point *pt2)
 
static float8 point_sl (Point *pt1, Point *pt2)
 
static int point_inside (Point *p, int npts, Point *plist)
 
static void line_construct (LINE *result, Point *pt, float8 m)
 
static float8 line_sl (LINE *line)
 
static float8 line_invsl (LINE *line)
 
static bool line_interpt_line (Point *result, LINE *l1, LINE *l2)
 
static bool line_contain_point (LINE *line, Point *point)
 
static float8 line_closept_point (Point *result, LINE *line, Point *pt)
 
static void statlseg_construct (LSEG *lseg, Point *pt1, Point *pt2)
 
static float8 lseg_sl (LSEG *lseg)
 
static float8 lseg_invsl (LSEG *lseg)
 
static bool lseg_interpt_line (Point *result, LSEG *lseg, LINE *line)
 
static bool lseg_interpt_lseg (Point *result, LSEG *l1, LSEG *l2)
 
static int lseg_crossing (float8 x, float8 y, float8 px, float8 py)
 
static bool lseg_contain_point (LSEG *lseg, Point *point)
 
static float8 lseg_closept_point (Point *result, LSEG *lseg, Point *pt)
 
static float8 lseg_closept_line (Point *result, LSEG *lseg, LINE *line)
 
static float8 lseg_closept_lseg (Point *result, LSEG *on_lseg, LSEG *to_lseg)
 
static void box_construct (BOX *result, Point *pt1, Point *pt2)
 
static void box_cn (Point *center, BOX *box)
 
static bool box_ov (BOX *box1, BOX *box2)
 
static float8 box_ar (BOX *box)
 
static float8 box_ht (BOX *box)
 
static float8 box_wd (BOX *box)
 
static bool box_contain_point (BOX *box, Point *point)
 
static bool box_contain_box (BOX *contains_box, BOX *contained_box)
 
static bool box_contain_lseg (BOX *box, LSEG *lseg)
 
static bool box_interpt_lseg (Point *result, BOX *box, LSEG *lseg)
 
static float8 box_closept_point (Point *result, BOX *box, Point *point)
 
static float8 box_closept_lseg (Point *result, BOX *box, LSEG *lseg)
 
static float8 circle_ar (CIRCLE *circle)
 
static void make_bound_box (POLYGON *poly)
 
static void poly_to_circle (CIRCLE *result, POLYGON *poly)
 
static bool lseg_inside_poly (Point *a, Point *b, POLYGON *poly, int start)
 
static bool poly_contain_poly (POLYGON *contains_poly, POLYGON *contained_poly)
 
static bool plist_same (int npts, Point *p1, Point *p2)
 
static float8 dist_ppoly_internal (Point *pt, POLYGON *poly)
 
static float8 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, float8 *x, float8 *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 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)
 
Datum point_slope (PG_FUNCTION_ARGS)
 
static float8 point_invsl (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_lp (PG_FUNCTION_ARGS)
 
Datum dist_ps (PG_FUNCTION_ARGS)
 
Datum dist_sp (PG_FUNCTION_ARGS)
 
static float8 dist_ppath_internal (Point *pt, PATH *path)
 
Datum dist_ppath (PG_FUNCTION_ARGS)
 
Datum dist_pathp (PG_FUNCTION_ARGS)
 
Datum dist_pb (PG_FUNCTION_ARGS)
 
Datum dist_bp (PG_FUNCTION_ARGS)
 
Datum dist_sl (PG_FUNCTION_ARGS)
 
Datum dist_ls (PG_FUNCTION_ARGS)
 
Datum dist_sb (PG_FUNCTION_ARGS)
 
Datum dist_bs (PG_FUNCTION_ARGS)
 
Datum dist_lb (PG_FUNCTION_ARGS)
 
Datum dist_bl (PG_FUNCTION_ARGS)
 
static float8 dist_cpoly_internal (CIRCLE *circle, POLYGON *poly)
 
Datum dist_cpoly (PG_FUNCTION_ARGS)
 
Datum dist_polyc (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)
 
float8 pg_hypot (float8 x, float8 y)
 

Macro Definition Documentation

◆ DELIM

#define DELIM   ','

◆ LDELIM

#define LDELIM   '('

Definition at line 152 of file geo_ops.c.

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

◆ LDELIM_C

#define LDELIM_C   '<'

Definition at line 157 of file geo_ops.c.

Referenced by circle_in(), and circle_out().

◆ LDELIM_EP

#define LDELIM_EP   '['

Definition at line 155 of file geo_ops.c.

Referenced by path_decode(), and path_encode().

◆ LDELIM_L

#define LDELIM_L   '{'

Definition at line 159 of file geo_ops.c.

Referenced by line_in(), and line_out().

◆ POINT_ON_POLYGON

#define POINT_ON_POLYGON   INT_MAX

Definition at line 5344 of file geo_ops.c.

Referenced by lseg_crossing(), and point_inside().

◆ RDELIM

#define RDELIM   ')'

Definition at line 153 of file geo_ops.c.

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

◆ RDELIM_C

#define RDELIM_C   '>'

Definition at line 158 of file geo_ops.c.

Referenced by circle_in(), and circle_out().

◆ RDELIM_EP

#define RDELIM_EP   ']'

Definition at line 156 of file geo_ops.c.

Referenced by path_decode(), and path_encode().

◆ RDELIM_L

#define RDELIM_L   '}'

Definition at line 160 of file geo_ops.c.

Referenced by line_decode(), and line_out().

Enumeration Type Documentation

◆ path_delim

enum path_delim
Enumerator
PATH_NONE 
PATH_OPEN 
PATH_CLOSED 

Definition at line 71 of file geo_ops.c.

Function Documentation

◆ box_above()

Datum box_above ( PG_FUNCTION_ARGS  )

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

647 {
648  BOX *box1 = PG_GETARG_BOX_P(0);
649  BOX *box2 = PG_GETARG_BOX_P(1);
650 
651  PG_RETURN_BOOL(FPgt(box1->low.y, box2->high.y));
652 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
Point low
Definition: geo_decls.h:142
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
float8 y
Definition: geo_decls.h:98
static bool FPgt(double A, double B)
Definition: geo_decls.h:71
Point high
Definition: geo_decls.h:142

◆ box_above_eq()

Datum box_above_eq ( PG_FUNCTION_ARGS  )

Definition at line 719 of file geo_ops.c.

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

720 {
721  BOX *box1 = PG_GETARG_BOX_P(0);
722  BOX *box2 = PG_GETARG_BOX_P(1);
723 
724  PG_RETURN_BOOL(FPge(box1->low.y, box2->high.y));
725 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
Point low
Definition: geo_decls.h:142
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
float8 y
Definition: geo_decls.h:98
Point high
Definition: geo_decls.h:142
static bool FPge(double A, double B)
Definition: geo_decls.h:77

◆ box_add()

Datum box_add ( PG_FUNCTION_ARGS  )

Definition at line 4229 of file geo_ops.c.

References BOX::high, BOX::low, palloc(), PG_GETARG_BOX_P, PG_GETARG_POINT_P, PG_RETURN_BOX_P, and point_add_point().

4230 {
4231  BOX *box = PG_GETARG_BOX_P(0);
4232  Point *p = PG_GETARG_POINT_P(1);
4233  BOX *result;
4234 
4235  result = (BOX *) palloc(sizeof(BOX));
4236 
4237  point_add_point(&result->high, &box->high, p);
4238  point_add_point(&result->low, &box->low, p);
4239 
4240  PG_RETURN_BOX_P(result);
4241 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
Point low
Definition: geo_decls.h:142
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:200
static void point_add_point(Point *result, Point *pt1, Point *pt2)
Definition: geo_ops.c:4109
Point high
Definition: geo_decls.h:142
void * palloc(Size size)
Definition: mcxt.c:950

◆ box_ar()

static float8 box_ar ( BOX box)
static

Definition at line 851 of file geo_ops.c.

References box_ht(), box_wd(), and float8_mul().

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

852 {
853  return float8_mul(box_wd(box), box_ht(box));
854 }
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:207
static float8 box_ht(BOX *box)
Definition: geo_ops.c:881
static float8 box_wd(BOX *box)
Definition: geo_ops.c:871

◆ box_area()

Datum box_area ( PG_FUNCTION_ARGS  )

Definition at line 784 of file geo_ops.c.

References box_ar(), PG_GETARG_BOX_P, and PG_RETURN_FLOAT8.

785 {
786  BOX *box = PG_GETARG_BOX_P(0);
787 
788  PG_RETURN_FLOAT8(box_ar(box));
789 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static float8 box_ar(BOX *box)
Definition: geo_ops.c:851

◆ box_below()

Datum box_below ( PG_FUNCTION_ARGS  )

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

624 {
625  BOX *box1 = PG_GETARG_BOX_P(0);
626  BOX *box2 = PG_GETARG_BOX_P(1);
627 
628  PG_RETURN_BOOL(FPlt(box1->high.y, box2->low.y));
629 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
Point low
Definition: geo_decls.h:142
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
float8 y
Definition: geo_decls.h:98
Point high
Definition: geo_decls.h:142
static bool FPlt(double A, double B)
Definition: geo_decls.h:59

◆ box_below_eq()

Datum box_below_eq ( PG_FUNCTION_ARGS  )

Definition at line 710 of file geo_ops.c.

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

711 {
712  BOX *box1 = PG_GETARG_BOX_P(0);
713  BOX *box2 = PG_GETARG_BOX_P(1);
714 
715  PG_RETURN_BOOL(FPle(box1->high.y, box2->low.y));
716 }
static bool FPle(double A, double B)
Definition: geo_decls.h:65
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
Point low
Definition: geo_decls.h:142
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
float8 y
Definition: geo_decls.h:98
Point high
Definition: geo_decls.h:142

◆ box_center()

Datum box_center ( PG_FUNCTION_ARGS  )

Definition at line 837 of file geo_ops.c.

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

838 {
839  BOX *box = PG_GETARG_BOX_P(0);
840  Point *result = (Point *) palloc(sizeof(Point));
841 
842  box_cn(result, box);
843 
844  PG_RETURN_POINT_P(result);
845 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
static void box_cn(Point *center, BOX *box)
Definition: geo_ops.c:860
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:178
void * palloc(Size size)
Definition: mcxt.c:950

◆ box_circle()

Datum box_circle ( PG_FUNCTION_ARGS  )

Definition at line 5215 of file geo_ops.c.

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

5216 {
5217  BOX *box = PG_GETARG_BOX_P(0);
5218  CIRCLE *circle;
5219 
5220  circle = (CIRCLE *) palloc(sizeof(CIRCLE));
5221 
5222  circle->center.x = float8_div(float8_pl(box->high.x, box->low.x), 2.0);
5223  circle->center.y = float8_div(float8_pl(box->high.y, box->low.y), 2.0);
5224 
5225  circle->radius = point_dt(&circle->center, &box->high);
5226 
5227  PG_RETURN_CIRCLE_P(circle);
5228 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
float8 x
Definition: geo_decls.h:98
float8 radius
Definition: geo_decls.h:165
static float8 point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1971
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157
Point low
Definition: geo_decls.h:142
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:212
float8 y
Definition: geo_decls.h:98
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:237
Point high
Definition: geo_decls.h:142
Point center
Definition: geo_decls.h:164
void * palloc(Size size)
Definition: mcxt.c:950

◆ box_closept_lseg()

static float8 box_closept_lseg ( Point result,
BOX box,
LSEG lseg 
)
static

Definition at line 3058 of file geo_ops.c.

References box_interpt_lseg(), float8_lt(), BOX::high, BOX::low, lseg_closept_lseg(), statlseg_construct(), Point::x, and Point::y.

Referenced by close_sb(), dist_bs(), and dist_sb().

3059 {
3060  float8 dist,
3061  d;
3062  Point point,
3063  closept;
3064  LSEG bseg;
3065 
3066  if (box_interpt_lseg(result, box, lseg))
3067  return 0.0;
3068 
3069  /* pairwise check lseg distances */
3070  point.x = box->low.x;
3071  point.y = box->high.y;
3072  statlseg_construct(&bseg, &box->low, &point);
3073  dist = lseg_closept_lseg(result, &bseg, lseg);
3074 
3075  statlseg_construct(&bseg, &box->high, &point);
3076  d = lseg_closept_lseg(&closept, &bseg, lseg);
3077  if (float8_lt(d, dist))
3078  {
3079  dist = d;
3080  if (result != NULL)
3081  *result = closept;
3082  }
3083 
3084  point.x = box->high.x;
3085  point.y = box->low.y;
3086  statlseg_construct(&bseg, &box->low, &point);
3087  d = lseg_closept_lseg(&closept, &bseg, lseg);
3088  if (float8_lt(d, dist))
3089  {
3090  dist = d;
3091  if (result != NULL)
3092  *result = closept;
3093  }
3094 
3095  statlseg_construct(&bseg, &box->high, &point);
3096  d = lseg_closept_lseg(&closept, &bseg, lseg);
3097  if (float8_lt(d, dist))
3098  {
3099  dist = d;
3100  if (result != NULL)
3101  *result = closept;
3102  }
3103 
3104  return dist;
3105 }
static float8 lseg_closept_lseg(Point *result, LSEG *on_lseg, LSEG *to_lseg)
Definition: geo_ops.c:2813
float8 x
Definition: geo_decls.h:98
static void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: geo_ops.c:2107
double float8
Definition: c.h:553
static bool box_interpt_lseg(Point *result, BOX *box, LSEG *lseg)
Definition: geo_ops.c:3324
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:291
Point low
Definition: geo_decls.h:142
float8 y
Definition: geo_decls.h:98
Point high
Definition: geo_decls.h:142

◆ box_closept_point()

static float8 box_closept_point ( Point result,
BOX box,
Point point 
)
static

Definition at line 2881 of file geo_ops.c.

References box_contain_point(), float8_lt(), BOX::high, BOX::low, lseg_closept_point(), statlseg_construct(), Point::x, and Point::y.

Referenced by close_pb(), dist_bp(), and dist_pb().

2882 {
2883  float8 dist,
2884  d;
2885  Point point,
2886  closept;
2887  LSEG lseg;
2888 
2889  if (box_contain_point(box, pt))
2890  {
2891  if (result != NULL)
2892  *result = *pt;
2893 
2894  return 0.0;
2895  }
2896 
2897  /* pairwise check lseg distances */
2898  point.x = box->low.x;
2899  point.y = box->high.y;
2900  statlseg_construct(&lseg, &box->low, &point);
2901  dist = lseg_closept_point(result, &lseg, pt);
2902 
2903  statlseg_construct(&lseg, &box->high, &point);
2904  d = lseg_closept_point(&closept, &lseg, pt);
2905  if (float8_lt(d, dist))
2906  {
2907  dist = d;
2908  if (result != NULL)
2909  *result = closept;
2910  }
2911 
2912  point.x = box->high.x;
2913  point.y = box->low.y;
2914  statlseg_construct(&lseg, &box->low, &point);
2915  d = lseg_closept_point(&closept, &lseg, pt);
2916  if (float8_lt(d, dist))
2917  {
2918  dist = d;
2919  if (result != NULL)
2920  *result = closept;
2921  }
2922 
2923  statlseg_construct(&lseg, &box->high, &point);
2924  d = lseg_closept_point(&closept, &lseg, pt);
2925  if (float8_lt(d, dist))
2926  {
2927  dist = d;
2928  if (result != NULL)
2929  *result = closept;
2930  }
2931 
2932  return dist;
2933 }
static bool box_contain_point(BOX *box, Point *point)
Definition: geo_ops.c:3191
float8 x
Definition: geo_decls.h:98
static void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: geo_ops.c:2107
double float8
Definition: c.h:553
static float8 lseg_closept_point(Point *result, LSEG *lseg, Point *pt)
Definition: geo_ops.c:2775
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:291
Point low
Definition: geo_decls.h:142
float8 y
Definition: geo_decls.h:98
Point high
Definition: geo_decls.h:142

◆ box_cn()

static void box_cn ( Point center,
BOX box 
)
static

Definition at line 860 of file geo_ops.c.

References float8_div(), float8_pl(), BOX::high, BOX::low, Point::x, and Point::y.

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

861 {
862  center->x = float8_div(float8_pl(box->high.x, box->low.x), 2.0);
863  center->y = float8_div(float8_pl(box->high.y, box->low.y), 2.0);
864 }
float8 x
Definition: geo_decls.h:98
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157
Point low
Definition: geo_decls.h:142
float8 y
Definition: geo_decls.h:98
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:237
Point high
Definition: geo_decls.h:142

◆ box_construct()

static void box_construct ( BOX result,
Point pt1,
Point pt2 
)
inlinestatic

Definition at line 506 of file geo_ops.c.

References float8_gt(), BOX::high, BOX::low, Point::x, and Point::y.

Referenced by box_div(), box_mul(), box_poly(), and points_box().

507 {
508  if (float8_gt(pt1->x, pt2->x))
509  {
510  result->high.x = pt1->x;
511  result->low.x = pt2->x;
512  }
513  else
514  {
515  result->high.x = pt2->x;
516  result->low.x = pt1->x;
517  }
518  if (float8_gt(pt1->y, pt2->y))
519  {
520  result->high.y = pt1->y;
521  result->low.y = pt2->y;
522  }
523  else
524  {
525  result->high.y = pt2->y;
526  result->low.y = pt1->y;
527  }
528 }
float8 x
Definition: geo_decls.h:98
Point low
Definition: geo_decls.h:142
static bool float8_gt(const float8 val1, const float8 val2)
Definition: float.h:315
float8 y
Definition: geo_decls.h:98
Point high
Definition: geo_decls.h:142

◆ box_contain()

Datum box_contain ( PG_FUNCTION_ARGS  )

Definition at line 680 of file geo_ops.c.

References box_contain_box(), PG_GETARG_BOX_P, and PG_RETURN_BOOL.

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

681 {
682  BOX *box1 = PG_GETARG_BOX_P(0);
683  BOX *box2 = PG_GETARG_BOX_P(1);
684 
685  PG_RETURN_BOOL(box_contain_box(box1, box2));
686 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
static bool box_contain_box(BOX *contains_box, BOX *contained_box)
Definition: geo_ops.c:692
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ box_contain_box()

static bool box_contain_box ( BOX contains_box,
BOX contained_box 
)
static

Definition at line 692 of file geo_ops.c.

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

Referenced by box_contain(), box_contained(), and poly_contain_poly().

693 {
694  return FPge(contains_box->high.x, contained_box->high.x) &&
695  FPle(contains_box->low.x, contained_box->low.x) &&
696  FPge(contains_box->high.y, contained_box->high.y) &&
697  FPle(contains_box->low.y, contained_box->low.y);
698 }
static bool FPle(double A, double B)
Definition: geo_decls.h:65
float8 x
Definition: geo_decls.h:98
Point low
Definition: geo_decls.h:142
float8 y
Definition: geo_decls.h:98
Point high
Definition: geo_decls.h:142
static bool FPge(double A, double B)
Definition: geo_decls.h:77

◆ box_contain_lseg()

static bool box_contain_lseg ( BOX box,
LSEG lseg 
)
static

Definition at line 3278 of file geo_ops.c.

References box_contain_point(), and LSEG::p.

Referenced by on_sb().

3279 {
3280  return box_contain_point(box, &lseg->p[0]) &&
3281  box_contain_point(box, &lseg->p[1]);
3282 }
static bool box_contain_point(BOX *box, Point *point)
Definition: geo_ops.c:3191
Point p[2]
Definition: geo_decls.h:108

◆ box_contain_point()

static bool box_contain_point ( BOX box,
Point point 
)
static

Definition at line 3191 of file geo_ops.c.

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

Referenced by box_closept_point(), box_contain_lseg(), box_contain_pt(), box_interpt_lseg(), and on_pb().

3192 {
3193  return box->high.x >= point->x && box->low.x <= point->x &&
3194  box->high.y >= point->y && box->low.y <= point->y;
3195 }
float8 x
Definition: geo_decls.h:98
Point low
Definition: geo_decls.h:142
float8 y
Definition: geo_decls.h:98
Point high
Definition: geo_decls.h:142

◆ box_contain_pt()

Datum box_contain_pt ( PG_FUNCTION_ARGS  )

Definition at line 3207 of file geo_ops.c.

References box_contain_point(), PG_GETARG_BOX_P, PG_GETARG_POINT_P, and PG_RETURN_BOOL.

Referenced by spg_quad_inner_consistent(), and spg_quad_leaf_consistent().

3208 {
3209  BOX *box = PG_GETARG_BOX_P(0);
3210  Point *pt = PG_GETARG_POINT_P(1);
3211 
3213 }
Definition: geo_decls.h:140
static bool box_contain_point(BOX *box, Point *point)
Definition: geo_ops.c:3191
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ box_contained()

Datum box_contained ( PG_FUNCTION_ARGS  )

Definition at line 669 of file geo_ops.c.

References box_contain_box(), PG_GETARG_BOX_P, and PG_RETURN_BOOL.

Referenced by gist_box_leaf_consistent(), and spg_box_quad_leaf_consistent().

670 {
671  BOX *box1 = PG_GETARG_BOX_P(0);
672  BOX *box2 = PG_GETARG_BOX_P(1);
673 
674  PG_RETURN_BOOL(box_contain_box(box2, box1));
675 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
static bool box_contain_box(BOX *contains_box, BOX *contained_box)
Definition: geo_ops.c:692
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ box_diagonal()

Datum box_diagonal ( PG_FUNCTION_ARGS  )

Definition at line 921 of file geo_ops.c.

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

922 {
923  BOX *box = PG_GETARG_BOX_P(0);
924  LSEG *result = (LSEG *) palloc(sizeof(LSEG));
925 
926  statlseg_construct(result, &box->high, &box->low);
927 
928  PG_RETURN_LSEG_P(result);
929 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
static void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: geo_ops.c:2107
#define PG_RETURN_LSEG_P(x)
Definition: geo_decls.h:183
Point low
Definition: geo_decls.h:142
Point high
Definition: geo_decls.h:142
void * palloc(Size size)
Definition: mcxt.c:950

◆ box_distance()

Datum box_distance ( PG_FUNCTION_ARGS  )

Definition at line 820 of file geo_ops.c.

References box_cn(), PG_GETARG_BOX_P, PG_RETURN_FLOAT8, and point_dt().

821 {
822  BOX *box1 = PG_GETARG_BOX_P(0);
823  BOX *box2 = PG_GETARG_BOX_P(1);
824  Point a,
825  b;
826 
827  box_cn(&a, box1);
828  box_cn(&b, box2);
829 
830  PG_RETURN_FLOAT8(point_dt(&a, &b));
831 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static void box_cn(Point *center, BOX *box)
Definition: geo_ops.c:860
static float8 point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1971

◆ box_div()

Datum box_div ( PG_FUNCTION_ARGS  )

Definition at line 4278 of file geo_ops.c.

References box_construct(), BOX::high, BOX::low, palloc(), PG_GETARG_BOX_P, PG_GETARG_POINT_P, PG_RETURN_BOX_P, and point_div_point().

4279 {
4280  BOX *box = PG_GETARG_BOX_P(0);
4281  Point *p = PG_GETARG_POINT_P(1);
4282  BOX *result;
4283  Point high,
4284  low;
4285 
4286  result = (BOX *) palloc(sizeof(BOX));
4287 
4288  point_div_point(&high, &box->high, p);
4289  point_div_point(&low, &box->low, p);
4290 
4291  box_construct(result, &high, &low);
4292 
4293  PG_RETURN_BOX_P(result);
4294 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
static void box_construct(BOX *result, Point *pt1, Point *pt2)
Definition: geo_ops.c:506
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
static void point_div_point(Point *result, Point *pt1, Point *pt2)
Definition: geo_ops.c:4180
Point low
Definition: geo_decls.h:142
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:200
Point high
Definition: geo_decls.h:142
void * palloc(Size size)
Definition: mcxt.c:950

◆ box_eq()

Datum box_eq ( PG_FUNCTION_ARGS  )

Definition at line 750 of file geo_ops.c.

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

751 {
752  BOX *box1 = PG_GETARG_BOX_P(0);
753  BOX *box2 = PG_GETARG_BOX_P(1);
754 
755  PG_RETURN_BOOL(FPeq(box_ar(box1), box_ar(box2)));
756 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
static float8 box_ar(BOX *box)
Definition: geo_ops.c:851
static bool FPeq(double A, double B)
Definition: geo_decls.h:47

◆ box_ge()

Datum box_ge ( PG_FUNCTION_ARGS  )

Definition at line 768 of file geo_ops.c.

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

769 {
770  BOX *box1 = PG_GETARG_BOX_P(0);
771  BOX *box2 = PG_GETARG_BOX_P(1);
772 
773  PG_RETURN_BOOL(FPge(box_ar(box1), box_ar(box2)));
774 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
static float8 box_ar(BOX *box)
Definition: geo_ops.c:851
static bool FPge(double A, double B)
Definition: geo_decls.h:77

◆ box_gt()

Datum box_gt ( PG_FUNCTION_ARGS  )

Definition at line 741 of file geo_ops.c.

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

742 {
743  BOX *box1 = PG_GETARG_BOX_P(0);
744  BOX *box2 = PG_GETARG_BOX_P(1);
745 
746  PG_RETURN_BOOL(FPgt(box_ar(box1), box_ar(box2)));
747 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
static bool FPgt(double A, double B)
Definition: geo_decls.h:71
static float8 box_ar(BOX *box)
Definition: geo_ops.c:851

◆ box_height()

Datum box_height ( PG_FUNCTION_ARGS  )

Definition at line 808 of file geo_ops.c.

References box_ht(), PG_GETARG_BOX_P, and PG_RETURN_FLOAT8.

809 {
810  BOX *box = PG_GETARG_BOX_P(0);
811 
812  PG_RETURN_FLOAT8(box_ht(box));
813 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static float8 box_ht(BOX *box)
Definition: geo_ops.c:881

◆ box_ht()

static float8 box_ht ( BOX box)
static

Definition at line 881 of file geo_ops.c.

References float8_mi(), BOX::high, BOX::low, and Point::y.

Referenced by box_ar(), and box_height().

882 {
883  return float8_mi(box->high.y, box->low.y);
884 }
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
Point low
Definition: geo_decls.h:142
float8 y
Definition: geo_decls.h:98
Point high
Definition: geo_decls.h:142

◆ box_in()

Datum box_in ( PG_FUNCTION_ARGS  )

Definition at line 413 of file geo_ops.c.

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

414 {
415  char *str = PG_GETARG_CSTRING(0);
416  BOX *box = (BOX *) palloc(sizeof(BOX));
417  bool isopen;
418  float8 x,
419  y;
420 
421  path_decode(str, false, 2, &(box->high), &isopen, NULL, "box", str);
422 
423  /* reorder corners if necessary... */
424  if (float8_lt(box->high.x, box->low.x))
425  {
426  x = box->high.x;
427  box->high.x = box->low.x;
428  box->low.x = x;
429  }
430  if (float8_lt(box->high.y, box->low.y))
431  {
432  y = box->high.y;
433  box->high.y = box->low.y;
434  box->low.y = y;
435  }
436 
437  PG_RETURN_BOX_P(box);
438 }
Definition: geo_decls.h:140
float8 x
Definition: geo_decls.h:98
double float8
Definition: c.h:553
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:291
Point low
Definition: geo_decls.h:142
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:200
float8 y
Definition: geo_decls.h:98
Point high
Definition: geo_decls.h:142
void * palloc(Size size)
Definition: mcxt.c:950
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
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:258

◆ box_interpt_lseg()

static bool box_interpt_lseg ( Point result,
BOX box,
LSEG lseg 
)
static

Definition at line 3324 of file geo_ops.c.

References box_cn(), box_contain_point(), box_ov(), float8_max(), float8_min(), BOX::high, BOX::low, lseg_closept_point(), lseg_interpt_lseg(), LSEG::p, statlseg_construct(), Point::x, and Point::y.

Referenced by box_closept_lseg(), and inter_sb().

3325 {
3326  BOX lbox;
3327  LSEG bseg;
3328  Point point;
3329 
3330  lbox.low.x = float8_min(lseg->p[0].x, lseg->p[1].x);
3331  lbox.low.y = float8_min(lseg->p[0].y, lseg->p[1].y);
3332  lbox.high.x = float8_max(lseg->p[0].x, lseg->p[1].x);
3333  lbox.high.y = float8_max(lseg->p[0].y, lseg->p[1].y);
3334 
3335  /* nothing close to overlap? then not going to intersect */
3336  if (!box_ov(&lbox, box))
3337  return false;
3338 
3339  if (result != NULL)
3340  {
3341  box_cn(&point, box);
3342  lseg_closept_point(result, lseg, &point);
3343  }
3344 
3345  /* an endpoint of segment is inside box? then clearly intersects */
3346  if (box_contain_point(box, &lseg->p[0]) ||
3347  box_contain_point(box, &lseg->p[1]))
3348  return true;
3349 
3350  /* pairwise check lseg intersections */
3351  point.x = box->low.x;
3352  point.y = box->high.y;
3353  statlseg_construct(&bseg, &box->low, &point);
3354  if (lseg_interpt_lseg(NULL, &bseg, lseg))
3355  return true;
3356 
3357  statlseg_construct(&bseg, &box->high, &point);
3358  if (lseg_interpt_lseg(NULL, &bseg, lseg))
3359  return true;
3360 
3361  point.x = box->high.x;
3362  point.y = box->low.y;
3363  statlseg_construct(&bseg, &box->low, &point);
3364  if (lseg_interpt_lseg(NULL, &bseg, lseg))
3365  return true;
3366 
3367  statlseg_construct(&bseg, &box->high, &point);
3368  if (lseg_interpt_lseg(NULL, &bseg, lseg))
3369  return true;
3370 
3371  /* if we dropped through, no two segs intersected */
3372  return false;
3373 }
Definition: geo_decls.h:140
static bool box_contain_point(BOX *box, Point *point)
Definition: geo_ops.c:3191
float8 x
Definition: geo_decls.h:98
static void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: geo_ops.c:2107
static float8 float8_min(const float8 val1, const float8 val2)
Definition: float.h:339
static void box_cn(Point *center, BOX *box)
Definition: geo_ops.c:860
static bool box_ov(BOX *box1, BOX *box2)
Definition: geo_ops.c:560
static float8 lseg_closept_point(Point *result, LSEG *lseg, Point *pt)
Definition: geo_ops.c:2775
Point low
Definition: geo_decls.h:142
static bool lseg_interpt_lseg(Point *result, LSEG *l1, LSEG *l2)
Definition: geo_ops.c:2303
float8 y
Definition: geo_decls.h:98
Point p[2]
Definition: geo_decls.h:108
Point high
Definition: geo_decls.h:142
static float8 float8_max(const float8 val1, const float8 val2)
Definition: float.h:351

◆ box_intersect()

Datum box_intersect ( PG_FUNCTION_ARGS  )

Definition at line 896 of file geo_ops.c.

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

897 {
898  BOX *box1 = PG_GETARG_BOX_P(0);
899  BOX *box2 = PG_GETARG_BOX_P(1);
900  BOX *result;
901 
902  if (!box_ov(box1, box2))
903  PG_RETURN_NULL();
904 
905  result = (BOX *) palloc(sizeof(BOX));
906 
907  result->high.x = float8_min(box1->high.x, box2->high.x);
908  result->low.x = float8_max(box1->low.x, box2->low.x);
909  result->high.y = float8_min(box1->high.y, box2->high.y);
910  result->low.y = float8_max(box1->low.y, box2->low.y);
911 
912  PG_RETURN_BOX_P(result);
913 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
float8 x
Definition: geo_decls.h:98
static float8 float8_min(const float8 val1, const float8 val2)
Definition: float.h:339
static bool box_ov(BOX *box1, BOX *box2)
Definition: geo_ops.c:560
Point low
Definition: geo_decls.h:142
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:200
float8 y
Definition: geo_decls.h:98
Point high
Definition: geo_decls.h:142
void * palloc(Size size)
Definition: mcxt.c:950
static float8 float8_max(const float8 val1, const float8 val2)
Definition: float.h:351
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ box_le()

Datum box_le ( PG_FUNCTION_ARGS  )

Definition at line 759 of file geo_ops.c.

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

760 {
761  BOX *box1 = PG_GETARG_BOX_P(0);
762  BOX *box2 = PG_GETARG_BOX_P(1);
763 
764  PG_RETURN_BOOL(FPle(box_ar(box1), box_ar(box2)));
765 }
static bool FPle(double A, double B)
Definition: geo_decls.h:65
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
static float8 box_ar(BOX *box)
Definition: geo_ops.c:851

◆ box_left()

Datum box_left ( PG_FUNCTION_ARGS  )

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

572 {
573  BOX *box1 = PG_GETARG_BOX_P(0);
574  BOX *box2 = PG_GETARG_BOX_P(1);
575 
576  PG_RETURN_BOOL(FPlt(box1->high.x, box2->low.x));
577 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
float8 x
Definition: geo_decls.h:98
Point low
Definition: geo_decls.h:142
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
Point high
Definition: geo_decls.h:142
static bool FPlt(double A, double B)
Definition: geo_decls.h:59

◆ box_lt()

Datum box_lt ( PG_FUNCTION_ARGS  )

Definition at line 732 of file geo_ops.c.

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

733 {
734  BOX *box1 = PG_GETARG_BOX_P(0);
735  BOX *box2 = PG_GETARG_BOX_P(1);
736 
737  PG_RETURN_BOOL(FPlt(box_ar(box1), box_ar(box2)));
738 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
static float8 box_ar(BOX *box)
Definition: geo_ops.c:851
static bool FPlt(double A, double B)
Definition: geo_decls.h:59

◆ box_mul()

Datum box_mul ( PG_FUNCTION_ARGS  )

Definition at line 4259 of file geo_ops.c.

References box_construct(), BOX::high, BOX::low, palloc(), PG_GETARG_BOX_P, PG_GETARG_POINT_P, PG_RETURN_BOX_P, and point_mul_point().

4260 {
4261  BOX *box = PG_GETARG_BOX_P(0);
4262  Point *p = PG_GETARG_POINT_P(1);
4263  BOX *result;
4264  Point high,
4265  low;
4266 
4267  result = (BOX *) palloc(sizeof(BOX));
4268 
4269  point_mul_point(&high, &box->high, p);
4270  point_mul_point(&low, &box->low, p);
4271 
4272  box_construct(result, &high, &low);
4273 
4274  PG_RETURN_BOX_P(result);
4275 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
static void box_construct(BOX *result, Point *pt1, Point *pt2)
Definition: geo_ops.c:506
static void point_mul_point(Point *result, Point *pt1, Point *pt2)
Definition: geo_ops.c:4155
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
Point low
Definition: geo_decls.h:142
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:200
Point high
Definition: geo_decls.h:142
void * palloc(Size size)
Definition: mcxt.c:950

◆ box_out()

Datum box_out ( PG_FUNCTION_ARGS  )

Definition at line 443 of file geo_ops.c.

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

444 {
445  BOX *box = PG_GETARG_BOX_P(0);
446 
448 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
Point high
Definition: geo_decls.h:142
static char * path_encode(enum path_delim path_delim, int npts, Point *pt)

◆ box_ov()

static bool box_ov ( BOX box1,
BOX box2 
)
static

Definition at line 560 of file geo_ops.c.

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

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

561 {
562  return (FPle(box1->low.x, box2->high.x) &&
563  FPle(box2->low.x, box1->high.x) &&
564  FPle(box1->low.y, box2->high.y) &&
565  FPle(box2->low.y, box1->high.y));
566 }
static bool FPle(double A, double B)
Definition: geo_decls.h:65
float8 x
Definition: geo_decls.h:98
Point low
Definition: geo_decls.h:142
float8 y
Definition: geo_decls.h:98
Point high
Definition: geo_decls.h:142

◆ box_overabove()

Datum box_overabove ( PG_FUNCTION_ARGS  )

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

659 {
660  BOX *box1 = PG_GETARG_BOX_P(0);
661  BOX *box2 = PG_GETARG_BOX_P(1);
662 
663  PG_RETURN_BOOL(FPge(box1->low.y, box2->low.y));
664 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
Point low
Definition: geo_decls.h:142
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
float8 y
Definition: geo_decls.h:98
static bool FPge(double A, double B)
Definition: geo_decls.h:77

◆ box_overbelow()

Datum box_overbelow ( PG_FUNCTION_ARGS  )

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

636 {
637  BOX *box1 = PG_GETARG_BOX_P(0);
638  BOX *box2 = PG_GETARG_BOX_P(1);
639 
640  PG_RETURN_BOOL(FPle(box1->high.y, box2->high.y));
641 }
static bool FPle(double A, double B)
Definition: geo_decls.h:65
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
float8 y
Definition: geo_decls.h:98
Point high
Definition: geo_decls.h:142

◆ box_overlap()

Datum box_overlap ( PG_FUNCTION_ARGS  )

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

552 {
553  BOX *box1 = PG_GETARG_BOX_P(0);
554  BOX *box2 = PG_GETARG_BOX_P(1);
555 
556  PG_RETURN_BOOL(box_ov(box1, box2));
557 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
static bool box_ov(BOX *box1, BOX *box2)
Definition: geo_ops.c:560
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ box_overleft()

Datum box_overleft ( PG_FUNCTION_ARGS  )

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

587 {
588  BOX *box1 = PG_GETARG_BOX_P(0);
589  BOX *box2 = PG_GETARG_BOX_P(1);
590 
591  PG_RETURN_BOOL(FPle(box1->high.x, box2->high.x));
592 }
static bool FPle(double A, double B)
Definition: geo_decls.h:65
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
float8 x
Definition: geo_decls.h:98
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
Point high
Definition: geo_decls.h:142

◆ box_overright()

Datum box_overright ( PG_FUNCTION_ARGS  )

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

613 {
614  BOX *box1 = PG_GETARG_BOX_P(0);
615  BOX *box2 = PG_GETARG_BOX_P(1);
616 
617  PG_RETURN_BOOL(FPge(box1->low.x, box2->low.x));
618 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
float8 x
Definition: geo_decls.h:98
Point low
Definition: geo_decls.h:142
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
static bool FPge(double A, double B)
Definition: geo_decls.h:77

◆ box_poly()

Datum box_poly ( PG_FUNCTION_ARGS  )

Definition at line 4547 of file geo_ops.c.

References POLYGON::boundbox, box_construct(), 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.

4548 {
4549  BOX *box = PG_GETARG_BOX_P(0);
4550  POLYGON *poly;
4551  int size;
4552 
4553  /* map four corners of the box to a polygon */
4554  size = offsetof(POLYGON, p) + sizeof(poly->p[0]) * 4;
4555  poly = (POLYGON *) palloc(size);
4556 
4557  SET_VARSIZE(poly, size);
4558  poly->npts = 4;
4559 
4560  poly->p[0].x = box->low.x;
4561  poly->p[0].y = box->low.y;
4562  poly->p[1].x = box->low.x;
4563  poly->p[1].y = box->high.y;
4564  poly->p[2].x = box->high.x;
4565  poly->p[2].y = box->high.y;
4566  poly->p[3].x = box->high.x;
4567  poly->p[3].y = box->low.y;
4568 
4569  box_construct(&poly->boundbox, &box->high, &box->low);
4570 
4571  PG_RETURN_POLYGON_P(poly);
4572 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
float8 x
Definition: geo_decls.h:98
static void box_construct(BOX *result, Point *pt1, Point *pt2)
Definition: geo_ops.c:506
int32 npts
Definition: geo_decls.h:154
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:156
Point low
Definition: geo_decls.h:142
BOX boundbox
Definition: geo_decls.h:155
float8 y
Definition: geo_decls.h:98
#define PG_RETURN_POLYGON_P(x)
Definition: geo_decls.h:207
Point high
Definition: geo_decls.h:142
void * palloc(Size size)
Definition: mcxt.c:950
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
#define offsetof(type, field)
Definition: c.h:723

◆ box_recv()

Datum box_recv ( PG_FUNCTION_ARGS  )

Definition at line 454 of file geo_ops.c.

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

455 {
457  BOX *box;
458  float8 x,
459  y;
460 
461  box = (BOX *) palloc(sizeof(BOX));
462 
463  box->high.x = pq_getmsgfloat8(buf);
464  box->high.y = pq_getmsgfloat8(buf);
465  box->low.x = pq_getmsgfloat8(buf);
466  box->low.y = pq_getmsgfloat8(buf);
467 
468  /* reorder corners if necessary... */
469  if (float8_lt(box->high.x, box->low.x))
470  {
471  x = box->high.x;
472  box->high.x = box->low.x;
473  box->low.x = x;
474  }
475  if (float8_lt(box->high.y, box->low.y))
476  {
477  y = box->high.y;
478  box->high.y = box->low.y;
479  box->low.y = y;
480  }
481 
482  PG_RETURN_BOX_P(box);
483 }
Definition: geo_decls.h:140
float8 x
Definition: geo_decls.h:98
StringInfoData * StringInfo
Definition: stringinfo.h:44
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
double float8
Definition: c.h:553
static char * buf
Definition: pg_test_fsync.c:68
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:291
Point low
Definition: geo_decls.h:142
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:200
float8 pq_getmsgfloat8(StringInfo msg)
Definition: pqformat.c:490
float8 y
Definition: geo_decls.h:98
Point high
Definition: geo_decls.h:142
void * palloc(Size size)
Definition: mcxt.c:950

◆ box_right()

Datum box_right ( PG_FUNCTION_ARGS  )

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

598 {
599  BOX *box1 = PG_GETARG_BOX_P(0);
600  BOX *box2 = PG_GETARG_BOX_P(1);
601 
602  PG_RETURN_BOOL(FPgt(box1->low.x, box2->high.x));
603 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
float8 x
Definition: geo_decls.h:98
Point low
Definition: geo_decls.h:142
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
static bool FPgt(double A, double B)
Definition: geo_decls.h:71
Point high
Definition: geo_decls.h:142

◆ box_same()

Datum box_same ( PG_FUNCTION_ARGS  )

Definition at line 539 of file geo_ops.c.

References BOX::high, BOX::low, PG_GETARG_BOX_P, PG_RETURN_BOOL, and point_eq_point().

Referenced by gist_box_leaf_consistent(), and spg_box_quad_leaf_consistent().

540 {
541  BOX *box1 = PG_GETARG_BOX_P(0);
542  BOX *box2 = PG_GETARG_BOX_P(1);
543 
544  PG_RETURN_BOOL(point_eq_point(&box1->high, &box2->high) &&
545  point_eq_point(&box1->low, &box2->low));
546 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
static bool point_eq_point(Point *pt1, Point *pt2)
Definition: geo_ops.c:1946
Point low
Definition: geo_decls.h:142
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
Point high
Definition: geo_decls.h:142

◆ box_send()

Datum box_send ( PG_FUNCTION_ARGS  )

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

490 {
491  BOX *box = PG_GETARG_BOX_P(0);
493 
494  pq_begintypsend(&buf);
495  pq_sendfloat8(&buf, box->high.x);
496  pq_sendfloat8(&buf, box->high.y);
497  pq_sendfloat8(&buf, box->low.x);
498  pq_sendfloat8(&buf, box->low.y);
500 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
float8 x
Definition: geo_decls.h:98
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
void pq_sendfloat8(StringInfo buf, float8 f)
Definition: pqformat.c:278
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:371
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static char * buf
Definition: pg_test_fsync.c:68
Point low
Definition: geo_decls.h:142
float8 y
Definition: geo_decls.h:98
Point high
Definition: geo_decls.h:142

◆ box_sub()

Datum box_sub ( PG_FUNCTION_ARGS  )

Definition at line 4244 of file geo_ops.c.

References BOX::high, BOX::low, palloc(), PG_GETARG_BOX_P, PG_GETARG_POINT_P, PG_RETURN_BOX_P, and point_sub_point().

4245 {
4246  BOX *box = PG_GETARG_BOX_P(0);
4247  Point *p = PG_GETARG_POINT_P(1);
4248  BOX *result;
4249 
4250  result = (BOX *) palloc(sizeof(BOX));
4251 
4252  point_sub_point(&result->high, &box->high, p);
4253  point_sub_point(&result->low, &box->low, p);
4254 
4255  PG_RETURN_BOX_P(result);
4256 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
static void point_sub_point(Point *result, Point *pt1, Point *pt2)
Definition: geo_ops.c:4132
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
Point low
Definition: geo_decls.h:142
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:200
Point high
Definition: geo_decls.h:142
void * palloc(Size size)
Definition: mcxt.c:950

◆ box_wd()

static float8 box_wd ( BOX box)
static

Definition at line 871 of file geo_ops.c.

References float8_mi(), BOX::high, BOX::low, and Point::x.

Referenced by box_ar(), and box_width().

872 {
873  return float8_mi(box->high.x, box->low.x);
874 }
float8 x
Definition: geo_decls.h:98
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
Point low
Definition: geo_decls.h:142
Point high
Definition: geo_decls.h:142

◆ box_width()

Datum box_width ( PG_FUNCTION_ARGS  )

Definition at line 796 of file geo_ops.c.

References box_wd(), PG_GETARG_BOX_P, and PG_RETURN_FLOAT8.

797 {
798  BOX *box = PG_GETARG_BOX_P(0);
799 
800  PG_RETURN_FLOAT8(box_wd(box));
801 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static float8 box_wd(BOX *box)
Definition: geo_ops.c:871

◆ boxes_bound_box()

Datum boxes_bound_box ( PG_FUNCTION_ARGS  )

Definition at line 4319 of file geo_ops.c.

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

4320 {
4321  BOX *box1 = PG_GETARG_BOX_P(0),
4322  *box2 = PG_GETARG_BOX_P(1),
4323  *container;
4324 
4325  container = (BOX *) palloc(sizeof(BOX));
4326 
4327  container->high.x = float8_max(box1->high.x, box2->high.x);
4328  container->low.x = float8_min(box1->low.x, box2->low.x);
4329  container->high.y = float8_max(box1->high.y, box2->high.y);
4330  container->low.y = float8_min(box1->low.y, box2->low.y);
4331 
4332  PG_RETURN_BOX_P(container);
4333 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
float8 x
Definition: geo_decls.h:98
static float8 float8_min(const float8 val1, const float8 val2)
Definition: float.h:339
Point low
Definition: geo_decls.h:142
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:200
float8 y
Definition: geo_decls.h:98
Point high
Definition: geo_decls.h:142
void * palloc(Size size)
Definition: mcxt.c:950
static float8 float8_max(const float8 val1, const float8 val2)
Definition: float.h:351

◆ circle_above()

Datum circle_above ( PG_FUNCTION_ARGS  )

Definition at line 4870 of file geo_ops.c.

References CIRCLE::center, float8_mi(), float8_pl(), FPgt(), PG_GETARG_CIRCLE_P, PG_RETURN_BOOL, CIRCLE::radius, and Point::y.

4871 {
4872  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4873  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4874 
4875  PG_RETURN_BOOL(FPgt(float8_mi(circle1->center.y, circle1->radius),
4876  float8_pl(circle2->center.y, circle2->radius)));
4877 }
float8 radius
Definition: geo_decls.h:165
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
float8 y
Definition: geo_decls.h:98
static bool FPgt(double A, double B)
Definition: geo_decls.h:71
Point center
Definition: geo_decls.h:164

◆ circle_add_pt()

Datum circle_add_pt ( PG_FUNCTION_ARGS  )

Definition at line 4972 of file geo_ops.c.

References CIRCLE::center, palloc(), PG_GETARG_CIRCLE_P, PG_GETARG_POINT_P, PG_RETURN_CIRCLE_P, point_add_point(), and CIRCLE::radius.

4973 {
4974  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4975  Point *point = PG_GETARG_POINT_P(1);
4976  CIRCLE *result;
4977 
4978  result = (CIRCLE *) palloc(sizeof(CIRCLE));
4979 
4980  point_add_point(&result->center, &circle->center, point);
4981  result->radius = circle->radius;
4982 
4983  PG_RETURN_CIRCLE_P(result);
4984 }
float8 radius
Definition: geo_decls.h:165
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:212
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
static void point_add_point(Point *result, Point *pt1, Point *pt2)
Definition: geo_ops.c:4109
Point center
Definition: geo_decls.h:164
void * palloc(Size size)
Definition: mcxt.c:950

◆ circle_ar()

static float8 circle_ar ( CIRCLE circle)
static

Definition at line 5166 of file geo_ops.c.

References float8_mul(), M_PI, and CIRCLE::radius.

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

5167 {
5168  return float8_mul(float8_mul(circle->radius, circle->radius), M_PI);
5169 }
float8 radius
Definition: geo_decls.h:165
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:207
#define M_PI
Definition: earthdistance.c:10

◆ circle_area()

Datum circle_area ( PG_FUNCTION_ARGS  )

Definition at line 5039 of file geo_ops.c.

References circle_ar(), PG_GETARG_CIRCLE_P, and PG_RETURN_FLOAT8.

5040 {
5041  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5042 
5043  PG_RETURN_FLOAT8(circle_ar(circle));
5044 }
static float8 circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5166
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211

◆ circle_below()

Datum circle_below ( PG_FUNCTION_ARGS  )

Definition at line 4858 of file geo_ops.c.

References CIRCLE::center, float8_mi(), float8_pl(), FPlt(), PG_GETARG_CIRCLE_P, PG_RETURN_BOOL, CIRCLE::radius, and Point::y.

4859 {
4860  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4861  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4862 
4863  PG_RETURN_BOOL(FPlt(float8_pl(circle1->center.y, circle1->radius),
4864  float8_mi(circle2->center.y, circle2->radius)));
4865 }
float8 radius
Definition: geo_decls.h:165
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
float8 y
Definition: geo_decls.h:98
Point center
Definition: geo_decls.h:164
static bool FPlt(double A, double B)
Definition: geo_decls.h:59

◆ circle_box()

Datum circle_box ( PG_FUNCTION_ARGS  )

Definition at line 5193 of file geo_ops.c.

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

5194 {
5195  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5196  BOX *box;
5197  float8 delta;
5198 
5199  box = (BOX *) palloc(sizeof(BOX));
5200 
5201  delta = float8_div(circle->radius, sqrt(2.0));
5202 
5203  box->high.x = float8_pl(circle->center.x, delta);
5204  box->low.x = float8_mi(circle->center.x, delta);
5205  box->high.y = float8_pl(circle->center.y, delta);
5206  box->low.y = float8_mi(circle->center.y, delta);
5207 
5208  PG_RETURN_BOX_P(box);
5209 }
Definition: geo_decls.h:140
float8 x
Definition: geo_decls.h:98
float8 radius
Definition: geo_decls.h:165
double float8
Definition: c.h:553
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
Point low
Definition: geo_decls.h:142
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:200
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
float8 y
Definition: geo_decls.h:98
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:237
Point high
Definition: geo_decls.h:142
Point center
Definition: geo_decls.h:164
void * palloc(Size size)
Definition: mcxt.c:950

◆ circle_center()

Datum circle_center ( PG_FUNCTION_ARGS  )

Definition at line 5150 of file geo_ops.c.

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

5151 {
5152  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5153  Point *result;
5154 
5155  result = (Point *) palloc(sizeof(Point));
5156  result->x = circle->center.x;
5157  result->y = circle->center.y;
5158 
5159  PG_RETURN_POINT_P(result);
5160 }
float8 x
Definition: geo_decls.h:98
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:178
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
float8 y
Definition: geo_decls.h:98
Point center
Definition: geo_decls.h:164
void * palloc(Size size)
Definition: mcxt.c:950

◆ circle_contain()

Datum circle_contain ( PG_FUNCTION_ARGS  )

Definition at line 4845 of file geo_ops.c.

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

4846 {
4847  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4848  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4849 
4850  PG_RETURN_BOOL(FPle(point_dt(&circle1->center, &circle2->center),
4851  float8_mi(circle1->radius, circle2->radius)));
4852 }
static bool FPle(double A, double B)
Definition: geo_decls.h:65
float8 radius
Definition: geo_decls.h:165
static float8 point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1971
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
Point center
Definition: geo_decls.h:164

◆ circle_contain_pt()

Datum circle_contain_pt ( PG_FUNCTION_ARGS  )

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

5090 {
5091  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5092  Point *point = PG_GETARG_POINT_P(1);
5093  float8 d;
5094 
5095  d = point_dt(&circle->center, point);
5096  PG_RETURN_BOOL(d <= circle->radius);
5097 }
static float8 point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1971
double float8
Definition: c.h:553
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
Point center
Definition: geo_decls.h:164

◆ circle_contained()

Datum circle_contained ( PG_FUNCTION_ARGS  )

Definition at line 4833 of file geo_ops.c.

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

4834 {
4835  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4836  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4837 
4838  PG_RETURN_BOOL(FPle(point_dt(&circle1->center, &circle2->center),
4839  float8_mi(circle2->radius, circle1->radius)));
4840 }
static bool FPle(double A, double B)
Definition: geo_decls.h:65
float8 radius
Definition: geo_decls.h:165
static float8 point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1971
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
Point center
Definition: geo_decls.h:164

◆ circle_diameter()

Datum circle_diameter ( PG_FUNCTION_ARGS  )

Definition at line 5050 of file geo_ops.c.

References float8_mul(), PG_GETARG_CIRCLE_P, PG_RETURN_FLOAT8, and CIRCLE::radius.

5051 {
5052  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5053 
5054  PG_RETURN_FLOAT8(float8_mul(circle->radius, 2.0));
5055 }
float8 radius
Definition: geo_decls.h:165
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:207
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211

◆ circle_distance()

Datum circle_distance ( PG_FUNCTION_ARGS  )

Definition at line 5073 of file geo_ops.c.

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

5074 {
5075  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
5076  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
5077  float8 result;
5078 
5079  result = float8_mi(point_dt(&circle1->center, &circle2->center),
5080  float8_pl(circle1->radius, circle2->radius));
5081  if (result < 0.0)
5082  result = 0.0;
5083 
5084  PG_RETURN_FLOAT8(result);
5085 }
float8 radius
Definition: geo_decls.h:165
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static float8 point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1971
double float8
Definition: c.h:553
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
Point center
Definition: geo_decls.h:164

◆ circle_div_pt()

Datum circle_div_pt ( PG_FUNCTION_ARGS  )

Definition at line 5021 of file geo_ops.c.

References CIRCLE::center, float8_div(), HYPOT, palloc(), PG_GETARG_CIRCLE_P, PG_GETARG_POINT_P, PG_RETURN_CIRCLE_P, point_div_point(), CIRCLE::radius, Point::x, and Point::y.

5022 {
5023  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5024  Point *point = PG_GETARG_POINT_P(1);
5025  CIRCLE *result;
5026 
5027  result = (CIRCLE *) palloc(sizeof(CIRCLE));
5028 
5029  point_div_point(&result->center, &circle->center, point);
5030  result->radius = float8_div(circle->radius, HYPOT(point->x, point->y));
5031 
5032  PG_RETURN_CIRCLE_P(result);
5033 }
float8 x
Definition: geo_decls.h:98
float8 radius
Definition: geo_decls.h:165
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
static void point_div_point(Point *result, Point *pt1, Point *pt2)
Definition: geo_ops.c:4180
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:212
#define HYPOT(A, B)
Definition: geo_decls.h:91
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
float8 y
Definition: geo_decls.h:98
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:237
Point center
Definition: geo_decls.h:164
void * palloc(Size size)
Definition: mcxt.c:950

◆ circle_eq()

Datum circle_eq ( PG_FUNCTION_ARGS  )

Definition at line 4910 of file geo_ops.c.

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

4911 {
4912  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4913  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4914 
4915  PG_RETURN_BOOL(FPeq(circle_ar(circle1), circle_ar(circle2)));
4916 }
static float8 circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5166
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
static bool FPeq(double A, double B)
Definition: geo_decls.h:47

◆ circle_ge()

Datum circle_ge ( PG_FUNCTION_ARGS  )

Definition at line 4955 of file geo_ops.c.

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

4956 {
4957  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4958  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4959 
4960  PG_RETURN_BOOL(FPge(circle_ar(circle1), circle_ar(circle2)));
4961 }
static float8 circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5166
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
static bool FPge(double A, double B)
Definition: geo_decls.h:77

◆ circle_gt()

Datum circle_gt ( PG_FUNCTION_ARGS  )

Definition at line 4937 of file geo_ops.c.

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

4938 {
4939  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4940  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4941 
4942  PG_RETURN_BOOL(FPgt(circle_ar(circle1), circle_ar(circle2)));
4943 }
static float8 circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5166
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
static bool FPgt(double A, double B)
Definition: geo_decls.h:71

◆ circle_in()

Datum circle_in ( PG_FUNCTION_ARGS  )

Definition at line 4623 of file geo_ops.c.

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

4624 {
4625  char *str = PG_GETARG_CSTRING(0);
4626  CIRCLE *circle = (CIRCLE *) palloc(sizeof(CIRCLE));
4627  char *s,
4628  *cp;
4629  int depth = 0;
4630 
4631  s = str;
4632  while (isspace((unsigned char) *s))
4633  s++;
4634  if (*s == LDELIM_C)
4635  depth++, s++;
4636  else if (*s == LDELIM)
4637  {
4638  /* If there are two left parens, consume the first one */
4639  cp = (s + 1);
4640  while (isspace((unsigned char) *cp))
4641  cp++;
4642  if (*cp == LDELIM)
4643  depth++, s = cp;
4644  }
4645 
4646  /* pair_decode will consume parens around the pair, if any */
4647  pair_decode(s, &circle->center.x, &circle->center.y, &s, "circle", str);
4648 
4649  if (*s == DELIM)
4650  s++;
4651 
4652  circle->radius = single_decode(s, &s, "circle", str);
4653  /* We have to accept NaN. */
4654  if (circle->radius < 0.0)
4655  ereport(ERROR,
4656  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
4657  errmsg("invalid input syntax for type %s: \"%s\"",
4658  "circle", str)));
4659 
4660  while (depth > 0)
4661  {
4662  if ((*s == RDELIM) || ((*s == RDELIM_C) && (depth == 1)))
4663  {
4664  depth--;
4665  s++;
4666  while (isspace((unsigned char) *s))
4667  s++;
4668  }
4669  else
4670  ereport(ERROR,
4671  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
4672  errmsg("invalid input syntax for type %s: \"%s\"",
4673  "circle", str)));
4674  }
4675 
4676  if (*s != '\0')
4677  ereport(ERROR,
4678  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
4679  errmsg("invalid input syntax for type %s: \"%s\"",
4680  "circle", str)));
4681 
4682  PG_RETURN_CIRCLE_P(circle);
4683 }
static float8 single_decode(char *num, char **endptr_p, const char *type_name, const char *orig_string)
Definition: geo_ops.c:189
float8 x
Definition: geo_decls.h:98
float8 radius
Definition: geo_decls.h:165
int errcode(int sqlerrcode)
Definition: elog.c:691
#define DELIM
Definition: geo_ops.c:154
#define ERROR
Definition: elog.h:43
#define LDELIM
Definition: geo_ops.c:152
#define RDELIM
Definition: geo_ops.c:153
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:212
#define ereport(elevel,...)
Definition: elog.h:155
float8 y
Definition: geo_decls.h:98
#define LDELIM_C
Definition: geo_ops.c:157
Point center
Definition: geo_decls.h:164
#define RDELIM_C
Definition: geo_ops.c:158
void * palloc(Size size)
Definition: mcxt.c:950
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
static void pair_decode(char *str, float8 *x, float8 *y, char **endptr_p, const char *type_name, const char *orig_string)
Definition: geo_ops.c:205

◆ circle_le()

Datum circle_le ( PG_FUNCTION_ARGS  )

Definition at line 4946 of file geo_ops.c.

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

4947 {
4948  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4949  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4950 
4951  PG_RETURN_BOOL(FPle(circle_ar(circle1), circle_ar(circle2)));
4952 }
static bool FPle(double A, double B)
Definition: geo_decls.h:65
static float8 circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5166
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211

◆ circle_left()

Datum circle_left ( PG_FUNCTION_ARGS  )

Definition at line 4796 of file geo_ops.c.

References CIRCLE::center, float8_mi(), float8_pl(), FPlt(), PG_GETARG_CIRCLE_P, PG_RETURN_BOOL, CIRCLE::radius, and Point::x.

4797 {
4798  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4799  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4800 
4801  PG_RETURN_BOOL(FPlt(float8_pl(circle1->center.x, circle1->radius),
4802  float8_mi(circle2->center.x, circle2->radius)));
4803 }
float8 x
Definition: geo_decls.h:98
float8 radius
Definition: geo_decls.h:165
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
Point center
Definition: geo_decls.h:164
static bool FPlt(double A, double B)
Definition: geo_decls.h:59

◆ circle_lt()

Datum circle_lt ( PG_FUNCTION_ARGS  )

Definition at line 4928 of file geo_ops.c.

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

4929 {
4930  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4931  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4932 
4933  PG_RETURN_BOOL(FPlt(circle_ar(circle1), circle_ar(circle2)));
4934 }
static float8 circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5166
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
static bool FPlt(double A, double B)
Definition: geo_decls.h:59

◆ circle_mul_pt()

Datum circle_mul_pt ( PG_FUNCTION_ARGS  )

Definition at line 5006 of file geo_ops.c.

References CIRCLE::center, float8_mul(), HYPOT, palloc(), PG_GETARG_CIRCLE_P, PG_GETARG_POINT_P, PG_RETURN_CIRCLE_P, point_mul_point(), CIRCLE::radius, Point::x, and Point::y.

5007 {
5008  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5009  Point *point = PG_GETARG_POINT_P(1);
5010  CIRCLE *result;
5011 
5012  result = (CIRCLE *) palloc(sizeof(CIRCLE));
5013 
5014  point_mul_point(&result->center, &circle->center, point);
5015  result->radius = float8_mul(circle->radius, HYPOT(point->x, point->y));
5016 
5017  PG_RETURN_CIRCLE_P(result);
5018 }
float8 x
Definition: geo_decls.h:98
float8 radius
Definition: geo_decls.h:165
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:207
static void point_mul_point(Point *result, Point *pt1, Point *pt2)
Definition: geo_ops.c:4155
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:212
#define HYPOT(A, B)
Definition: geo_decls.h:91
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
float8 y
Definition: geo_decls.h:98
Point center
Definition: geo_decls.h:164
void * palloc(Size size)
Definition: mcxt.c:950

◆ circle_ne()

Datum circle_ne ( PG_FUNCTION_ARGS  )

Definition at line 4919 of file geo_ops.c.

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

4920 {
4921  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4922  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4923 
4924  PG_RETURN_BOOL(FPne(circle_ar(circle1), circle_ar(circle2)));
4925 }
static float8 circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5166
static bool FPne(double A, double B)
Definition: geo_decls.h:53
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211

◆ circle_out()

Datum circle_out ( PG_FUNCTION_ARGS  )

Definition at line 4688 of file geo_ops.c.

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

4689 {
4690  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4692 
4693  initStringInfo(&str);
4694 
4697  pair_encode(circle->center.x, circle->center.y, &str);
4699  appendStringInfoChar(&str, DELIM);
4700  single_encode(circle->radius, &str);
4702 
4703  PG_RETURN_CSTRING(str.data);
4704 }
float8 x
Definition: geo_decls.h:98
float8 radius
Definition: geo_decls.h:165
static void single_encode(float8 x, StringInfo str)
Definition: geo_ops.c:196
static void pair_encode(float8 x, float8 y, StringInfo str)
Definition: geo_ops.c:247
#define DELIM
Definition: geo_ops.c:154
#define LDELIM
Definition: geo_ops.c:152
#define RDELIM
Definition: geo_ops.c:153
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:188
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
float8 y
Definition: geo_decls.h:98
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
#define LDELIM_C
Definition: geo_ops.c:157
Point center
Definition: geo_decls.h:164
#define RDELIM_C
Definition: geo_ops.c:158

◆ circle_overabove()

Datum circle_overabove ( PG_FUNCTION_ARGS  )

Definition at line 4896 of file geo_ops.c.

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

4897 {
4898  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4899  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4900 
4901  PG_RETURN_BOOL(FPge(float8_mi(circle1->center.y, circle1->radius),
4902  float8_mi(circle2->center.y, circle2->radius)));
4903 }
float8 radius
Definition: geo_decls.h:165
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
float8 y
Definition: geo_decls.h:98
Point center
Definition: geo_decls.h:164
static bool FPge(double A, double B)
Definition: geo_decls.h:77

◆ circle_overbelow()

Datum circle_overbelow ( PG_FUNCTION_ARGS  )

Definition at line 4883 of file geo_ops.c.

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

4884 {
4885  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4886  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4887 
4888  PG_RETURN_BOOL(FPle(float8_pl(circle1->center.y, circle1->radius),
4889  float8_pl(circle2->center.y, circle2->radius)));
4890 }
static bool FPle(double A, double B)
Definition: geo_decls.h:65
float8 radius
Definition: geo_decls.h:165
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
float8 y
Definition: geo_decls.h:98
Point center
Definition: geo_decls.h:164

◆ circle_overlap()

Datum circle_overlap ( PG_FUNCTION_ARGS  )

Definition at line 4771 of file geo_ops.c.

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

4772 {
4773  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4774  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4775 
4776  PG_RETURN_BOOL(FPle(point_dt(&circle1->center, &circle2->center),
4777  float8_pl(circle1->radius, circle2->radius)));
4778 }
static bool FPle(double A, double B)
Definition: geo_decls.h:65
float8 radius
Definition: geo_decls.h:165
static float8 point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1971
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
Point center
Definition: geo_decls.h:164

◆ circle_overleft()

Datum circle_overleft ( PG_FUNCTION_ARGS  )

Definition at line 4784 of file geo_ops.c.

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

4785 {
4786  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4787  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4788 
4789  PG_RETURN_BOOL(FPle(float8_pl(circle1->center.x, circle1->radius),
4790  float8_pl(circle2->center.x, circle2->radius)));
4791 }
static bool FPle(double A, double B)
Definition: geo_decls.h:65
float8 x
Definition: geo_decls.h:98
float8 radius
Definition: geo_decls.h:165
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
Point center
Definition: geo_decls.h:164

◆ circle_overright()

Datum circle_overright ( PG_FUNCTION_ARGS  )

Definition at line 4821 of file geo_ops.c.

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

4822 {
4823  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4824  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4825 
4826  PG_RETURN_BOOL(FPge(float8_mi(circle1->center.x, circle1->radius),
4827  float8_mi(circle2->center.x, circle2->radius)));
4828 }
float8 x
Definition: geo_decls.h:98
float8 radius
Definition: geo_decls.h:165
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
Point center
Definition: geo_decls.h:164
static bool FPge(double A, double B)
Definition: geo_decls.h:77

◆ circle_poly()

Datum circle_poly ( PG_FUNCTION_ARGS  )

Definition at line 5232 of file geo_ops.c.

References CIRCLE::center, ereport, errcode(), errmsg(), ERROR, float8_div(), float8_mi(), float8_mul(), float8_pl(), 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.

5233 {
5234  int32 npts = PG_GETARG_INT32(0);
5235  CIRCLE *circle = PG_GETARG_CIRCLE_P(1);
5236  POLYGON *poly;
5237  int base_size,
5238  size;
5239  int i;
5240  float8 angle;
5241  float8 anglestep;
5242 
5243  if (FPzero(circle->radius))
5244  ereport(ERROR,
5245  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5246  errmsg("cannot convert circle with radius zero to polygon")));
5247 
5248  if (npts < 2)
5249  ereport(ERROR,
5250  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5251  errmsg("must request at least 2 points")));
5252 
5253  base_size = sizeof(poly->p[0]) * npts;
5254  size = offsetof(POLYGON, p) + base_size;
5255 
5256  /* Check for integer overflow */
5257  if (base_size / npts != sizeof(poly->p[0]) || size <= base_size)
5258  ereport(ERROR,
5259  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
5260  errmsg("too many points requested")));
5261 
5262  poly = (POLYGON *) palloc0(size); /* zero any holes */
5263  SET_VARSIZE(poly, size);
5264  poly->npts = npts;
5265 
5266  anglestep = float8_div(2.0 * M_PI, npts);
5267 
5268  for (i = 0; i < npts; i++)
5269  {
5270  angle = float8_mul(anglestep, i);
5271 
5272  poly->p[i].x = float8_mi(circle->center.x,
5273  float8_mul(circle->radius, cos(angle)));
5274  poly->p[i].y = float8_pl(circle->center.y,
5275  float8_mul(circle->radius, sin(angle)));
5276  }
5277 
5278  make_bound_box(poly);
5279 
5280  PG_RETURN_POLYGON_P(poly);
5281 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define FPzero(A)
Definition: geo_decls.h:44
float8 x
Definition: geo_decls.h:98
float8 radius
Definition: geo_decls.h:165
int errcode(int sqlerrcode)
Definition: elog.c:691
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:207
int32 npts
Definition: geo_decls.h:154
signed int int32
Definition: c.h:417
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:156
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
void * palloc0(Size size)
Definition: mcxt.c:981
#define ereport(elevel,...)
Definition: elog.h:155
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
static void make_bound_box(POLYGON *poly)
Definition: geo_ops.c:3437
float8 y
Definition: geo_decls.h:98
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:237
#define PG_RETURN_POLYGON_P(x)
Definition: geo_decls.h:207
Point center
Definition: geo_decls.h:164
int errmsg(const char *fmt,...)
Definition: elog.c:902
int i
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
#define offsetof(type, field)
Definition: c.h:723
#define M_PI
Definition: earthdistance.c:10

◆ circle_radius()

Datum circle_radius ( PG_FUNCTION_ARGS  )

Definition at line 5061 of file geo_ops.c.

References PG_GETARG_CIRCLE_P, PG_RETURN_FLOAT8, and CIRCLE::radius.

5062 {
5063  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5064 
5065  PG_RETURN_FLOAT8(circle->radius);
5066 }
float8 radius
Definition: geo_decls.h:165
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211

◆ circle_recv()

Datum circle_recv ( PG_FUNCTION_ARGS  )

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

4711 {
4713  CIRCLE *circle;
4714 
4715  circle = (CIRCLE *) palloc(sizeof(CIRCLE));
4716 
4717  circle->center.x = pq_getmsgfloat8(buf);
4718  circle->center.y = pq_getmsgfloat8(buf);
4719  circle->radius = pq_getmsgfloat8(buf);
4720 
4721  /* We have to accept NaN. */
4722  if (circle->radius < 0.0)
4723  ereport(ERROR,
4724  (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
4725  errmsg("invalid radius in external \"circle\" value")));
4726 
4727  PG_RETURN_CIRCLE_P(circle);
4728 }
float8 x
Definition: geo_decls.h:98
float8 radius
Definition: geo_decls.h:165
StringInfoData * StringInfo
Definition: stringinfo.h:44
int errcode(int sqlerrcode)
Definition: elog.c:691
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define ERROR
Definition: elog.h:43
static char * buf
Definition: pg_test_fsync.c:68
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:212
#define ereport(elevel,...)
Definition: elog.h:155
float8 pq_getmsgfloat8(StringInfo msg)
Definition: pqformat.c:490
float8 y
Definition: geo_decls.h:98
Point center
Definition: geo_decls.h:164
void * palloc(Size size)
Definition: mcxt.c:950
int errmsg(const char *fmt,...)
Definition: elog.c:902

◆ circle_right()

Datum circle_right ( PG_FUNCTION_ARGS  )

Definition at line 4808 of file geo_ops.c.

References CIRCLE::center, float8_mi(), float8_pl(), FPgt(), PG_GETARG_CIRCLE_P, PG_RETURN_BOOL, CIRCLE::radius, and Point::x.

4809 {
4810  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4811  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4812 
4813  PG_RETURN_BOOL(FPgt(float8_mi(circle1->center.x, circle1->radius),
4814  float8_pl(circle2->center.x, circle2->radius)));
4815 }
float8 x
Definition: geo_decls.h:98
float8 radius
Definition: geo_decls.h:165
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
static bool FPgt(double A, double B)
Definition: geo_decls.h:71
Point center
Definition: geo_decls.h:164

◆ circle_same()

Datum circle_same ( PG_FUNCTION_ARGS  )

Definition at line 4758 of file geo_ops.c.

References CIRCLE::center, FPeq(), PG_GETARG_CIRCLE_P, PG_RETURN_BOOL, point_eq_point(), and CIRCLE::radius.

4759 {
4760  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4761  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4762 
4763  PG_RETURN_BOOL(((isnan(circle1->radius) && isnan(circle1->radius)) ||
4764  FPeq(circle1->radius, circle2->radius)) &&
4765  point_eq_point(&circle1->center, &circle2->center));
4766 }
float8 radius
Definition: geo_decls.h:165
static bool point_eq_point(Point *pt1, Point *pt2)
Definition: geo_ops.c:1946
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
Point center
Definition: geo_decls.h:164
static bool FPeq(double A, double B)
Definition: geo_decls.h:47

◆ circle_send()

Datum circle_send ( PG_FUNCTION_ARGS  )

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

4735 {
4736  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4738 
4739  pq_begintypsend(&buf);
4740  pq_sendfloat8(&buf, circle->center.x);
4741  pq_sendfloat8(&buf, circle->center.y);
4742  pq_sendfloat8(&buf, circle->radius);
4744 }
float8 x
Definition: geo_decls.h:98
float8 radius
Definition: geo_decls.h:165
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
void pq_sendfloat8(StringInfo buf, float8 f)
Definition: pqformat.c:278
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:371
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static char * buf
Definition: pg_test_fsync.c:68
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
float8 y
Definition: geo_decls.h:98
Point center
Definition: geo_decls.h:164

◆ circle_sub_pt()

Datum circle_sub_pt ( PG_FUNCTION_ARGS  )

Definition at line 4987 of file geo_ops.c.

References CIRCLE::center, palloc(), PG_GETARG_CIRCLE_P, PG_GETARG_POINT_P, PG_RETURN_CIRCLE_P, point_sub_point(), and CIRCLE::radius.

4988 {
4989  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4990  Point *point = PG_GETARG_POINT_P(1);
4991  CIRCLE *result;
4992 
4993  result = (CIRCLE *) palloc(sizeof(CIRCLE));
4994 
4995  point_sub_point(&result->center, &circle->center, point);
4996  result->radius = circle->radius;
4997 
4998  PG_RETURN_CIRCLE_P(result);
4999 }
float8 radius
Definition: geo_decls.h:165
static void point_sub_point(Point *result, Point *pt1, Point *pt2)
Definition: geo_ops.c:4132
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:212
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
Point center
Definition: geo_decls.h:164
void * palloc(Size size)
Definition: mcxt.c:950

◆ close_lb()

Datum close_lb ( PG_FUNCTION_ARGS  )

Definition at line 3124 of file geo_ops.c.

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

3125 {
3126 #ifdef NOT_USED
3127  LINE *line = PG_GETARG_LINE_P(0);
3128  BOX *box = PG_GETARG_BOX_P(1);
3129 #endif
3130 
3131  /* think about this one for a while */
3132  ereport(ERROR,
3133  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3134  errmsg("function \"close_lb\" not implemented")));
3135 
3136  PG_RETURN_NULL();
3137 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
int errcode(int sqlerrcode)
Definition: elog.c:691
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:194
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ close_ls()

Datum close_ls ( PG_FUNCTION_ARGS  )

Definition at line 3033 of file geo_ops.c.

References line_sl(), lseg_closept_line(), lseg_sl(), palloc(), PG_GETARG_LINE_P, PG_GETARG_LSEG_P, PG_RETURN_NULL, and PG_RETURN_POINT_P.

3034 {
3035  LINE *line = PG_GETARG_LINE_P(0);
3036  LSEG *lseg = PG_GETARG_LSEG_P(1);
3037  Point *result;
3038 
3039  if (lseg_sl(lseg) == line_sl(line))
3040  PG_RETURN_NULL();
3041 
3042  result = (Point *) palloc(sizeof(Point));
3043 
3044  if (isnan(lseg_closept_line(result, lseg, line)))
3045  PG_RETURN_NULL();
3046 
3047  PG_RETURN_POINT_P(result);
3048 }
static float8 lseg_closept_line(Point *result, LSEG *lseg, LINE *line)
Definition: geo_ops.c:3005
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:182
static float8 lseg_sl(LSEG *lseg)
Definition: geo_ops.c:2120
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:194
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:178
void * palloc(Size size)
Definition: mcxt.c:950
static float8 line_sl(LINE *line)
Definition: geo_ops.c:1206
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ close_lseg()

Datum close_lseg ( PG_FUNCTION_ARGS  )

Definition at line 2856 of file geo_ops.c.

References lseg_closept_lseg(), lseg_sl(), palloc(), PG_GETARG_LSEG_P, PG_RETURN_NULL, and PG_RETURN_POINT_P.

2857 {
2858  LSEG *l1 = PG_GETARG_LSEG_P(0);
2859  LSEG *l2 = PG_GETARG_LSEG_P(1);
2860  Point *result;
2861 
2862  if (lseg_sl(l1) == lseg_sl(l2))
2863  PG_RETURN_NULL();
2864 
2865  result = (Point *) palloc(sizeof(Point));
2866 
2867  if (isnan(lseg_closept_lseg(result, l2, l1)))
2868  PG_RETURN_NULL();
2869 
2870  PG_RETURN_POINT_P(result);
2871 }
static float8 lseg_closept_lseg(Point *result, LSEG *on_lseg, LSEG *to_lseg)
Definition: geo_ops.c:2813
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:182
static float8 lseg_sl(LSEG *lseg)
Definition: geo_ops.c:2120
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:178
void * palloc(Size size)
Definition: mcxt.c:950
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ close_pb()

Datum close_pb ( PG_FUNCTION_ARGS  )

Definition at line 2936 of file geo_ops.c.

References box_closept_point(), palloc(), PG_GETARG_BOX_P, PG_GETARG_POINT_P, PG_RETURN_NULL, and PG_RETURN_POINT_P.

2937 {
2938  Point *pt = PG_GETARG_POINT_P(0);
2939  BOX *box = PG_GETARG_BOX_P(1);
2940  Point *result;
2941 
2942  result = (Point *) palloc(sizeof(Point));
2943 
2944  if (isnan(box_closept_point(result, box, pt)))
2945  PG_RETURN_NULL();
2946 
2947  PG_RETURN_POINT_P(result);
2948 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:178
static float8 box_closept_point(Point *result, BOX *box, Point *point)
Definition: geo_ops.c:2881
void * palloc(Size size)
Definition: mcxt.c:950
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ close_pl()

Datum close_pl ( PG_FUNCTION_ARGS  )

Definition at line 2753 of file geo_ops.c.

References line_closept_point(), palloc(), PG_GETARG_LINE_P, PG_GETARG_POINT_P, PG_RETURN_NULL, and PG_RETURN_POINT_P.

2754 {
2755  Point *pt = PG_GETARG_POINT_P(0);
2756  LINE *line = PG_GETARG_LINE_P(1);
2757  Point *result;
2758 
2759  result = (Point *) palloc(sizeof(Point));
2760 
2761  if (isnan(line_closept_point(result, line, pt)))
2762  PG_RETURN_NULL();
2763 
2764  PG_RETURN_POINT_P(result);
2765 }
static float8 line_closept_point(Point *result, LINE *line, Point *pt)
Definition: geo_ops.c:2727
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:194
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:178
void * palloc(Size size)
Definition: mcxt.c:950
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ close_ps()

Datum close_ps ( PG_FUNCTION_ARGS  )

Definition at line 2794 of file geo_ops.c.

References lseg_closept_point(), palloc(), PG_GETARG_LSEG_P, PG_GETARG_POINT_P, PG_RETURN_NULL, and PG_RETURN_POINT_P.

2795 {
2796  Point *pt = PG_GETARG_POINT_P(0);
2797  LSEG *lseg = PG_GETARG_LSEG_P(1);
2798  Point *result;
2799 
2800  result = (Point *) palloc(sizeof(Point));
2801 
2802  if (isnan(lseg_closept_point(result, lseg, pt)))
2803  PG_RETURN_NULL();
2804 
2805  PG_RETURN_POINT_P(result);
2806 }
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:182
static float8 lseg_closept_point(Point *result, LSEG *lseg, Point *pt)
Definition: geo_ops.c:2775
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:178
void * palloc(Size size)
Definition: mcxt.c:950
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ close_sb()

Datum close_sb ( PG_FUNCTION_ARGS  )

Definition at line 3108 of file geo_ops.c.

References box_closept_lseg(), palloc(), PG_GETARG_BOX_P, PG_GETARG_LSEG_P, PG_RETURN_NULL, and PG_RETURN_POINT_P.

3109 {
3110  LSEG *lseg = PG_GETARG_LSEG_P(0);
3111  BOX *box = PG_GETARG_BOX_P(1);
3112  Point *result;
3113 
3114  result = (Point *) palloc(sizeof(Point));
3115 
3116  if (isnan(box_closept_lseg(result, box, lseg)))
3117  PG_RETURN_NULL();
3118 
3119  PG_RETURN_POINT_P(result);
3120 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:182
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:178
void * palloc(Size size)
Definition: mcxt.c:950
static float8 box_closept_lseg(Point *result, BOX *box, LSEG *lseg)
Definition: geo_ops.c:3058
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ close_sl()

Datum close_sl ( PG_FUNCTION_ARGS  )

Definition at line 2961 of file geo_ops.c.

References ereport, errcode(), errmsg(), ERROR, float8_lt(), line_closept_point(), lseg_interpt_line(), LSEG::p, palloc(), PG_GETARG_LINE_P, PG_GETARG_LSEG_P, PG_RETURN_NULL, and PG_RETURN_POINT_P.

2962 {
2963 #ifdef NOT_USED
2964  LSEG *lseg = PG_GETARG_LSEG_P(0);
2965  LINE *line = PG_GETARG_LINE_P(1);
2966  Point *result;
2967  float8 d1,
2968  d2;
2969 
2970  result = (Point *) palloc(sizeof(Point));
2971 
2972  if (lseg_interpt_line(result, lseg, line))
2973  PG_RETURN_POINT_P(result);
2974 
2975  d1 = line_closept_point(NULL, line, &lseg->p[0]);
2976  d2 = line_closept_point(NULL, line, &lseg->p[1]);
2977  if (float8_lt(d1, d2))
2978  *result = lseg->p[0];
2979  else
2980  *result = lseg->p[1];
2981 
2982  PG_RETURN_POINT_P(result);
2983 #endif
2984 
2985  ereport(ERROR,
2986  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2987  errmsg("function \"close_sl\" not implemented")));
2988 
2989  PG_RETURN_NULL();
2990 }
static bool lseg_interpt_line(Point *result, LSEG *lseg, LINE *line)
Definition: geo_ops.c:2678
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:182
int errcode(int sqlerrcode)
Definition: elog.c:691
static float8 line_closept_point(Point *result, LINE *line, Point *pt)
Definition: geo_ops.c:2727
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:194
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:553
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:178
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:291
#define ereport(elevel,...)
Definition: elog.h:155
Point p[2]
Definition: geo_decls.h:108
void * palloc(Size size)
Definition: mcxt.c:950
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ construct_point()

Datum construct_point ( PG_FUNCTION_ARGS  )

Definition at line 4094 of file geo_ops.c.

References palloc(), PG_GETARG_FLOAT8, PG_RETURN_POINT_P, and point_construct().

4095 {
4096  float8 x = PG_GETARG_FLOAT8(0);
4097  float8 y = PG_GETARG_FLOAT8(1);
4098  Point *result;
4099 
4100  result = (Point *) palloc(sizeof(Point));
4101 
4102  point_construct(result, x, y);
4103 
4104  PG_RETURN_POINT_P(result);
4105 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
static void point_construct(Point *result, float8 x, float8 y)
Definition: geo_ops.c:1853
double float8
Definition: c.h:553
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:178
void * palloc(Size size)
Definition: mcxt.c:950

◆ cr_circle()

Datum cr_circle ( PG_FUNCTION_ARGS  )

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

5178 {
5179  Point *center = PG_GETARG_POINT_P(0);
5180  float8 radius = PG_GETARG_FLOAT8(1);
5181  CIRCLE *result;
5182 
5183  result = (CIRCLE *) palloc(sizeof(CIRCLE));
5184 
5185  result->center.x = center->x;
5186  result->center.y = center->y;
5187  result->radius = radius;
5188 
5189  PG_RETURN_CIRCLE_P(result);
5190 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
float8 x
Definition: geo_decls.h:98
float8 radius
Definition: geo_decls.h:165
double float8
Definition: c.h:553
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:212
float8 y
Definition: geo_decls.h:98
Point center
Definition: geo_decls.h:164
void * palloc(Size size)
Definition: mcxt.c:950

◆ dist_bl()

Datum dist_bl ( PG_FUNCTION_ARGS  )

Definition at line 2558 of file geo_ops.c.

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

2559 {
2560 #ifdef NOT_USED
2561  BOX *box = PG_GETARG_BOX_P(0);
2562  LINE *line = PG_GETARG_LINE_P(1);
2563 #endif
2564 
2565  /* need to think about this one for a while */
2566  ereport(ERROR,
2567  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2568  errmsg("function \"dist_bl\" not implemented")));
2569 
2570  PG_RETURN_NULL();
2571 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
int errcode(int sqlerrcode)
Definition: elog.c:691
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:194
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ dist_bp()

Datum dist_bp ( PG_FUNCTION_ARGS  )

Definition at line 2479 of file geo_ops.c.

References box_closept_point(), PG_GETARG_BOX_P, PG_GETARG_POINT_P, and PG_RETURN_FLOAT8.

2480 {
2481  BOX *box = PG_GETARG_BOX_P(0);
2482  Point *pt = PG_GETARG_POINT_P(1);
2483 
2484  PG_RETURN_FLOAT8(box_closept_point(NULL, box, pt));
2485 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
static float8 box_closept_point(Point *result, BOX *box, Point *point)
Definition: geo_ops.c:2881

◆ dist_bs()

Datum dist_bs ( PG_FUNCTION_ARGS  )

Definition at line 2527 of file geo_ops.c.

References box_closept_lseg(), PG_GETARG_BOX_P, PG_GETARG_LSEG_P, and PG_RETURN_FLOAT8.

2528 {
2529  BOX *box = PG_GETARG_BOX_P(0);
2530  LSEG *lseg = PG_GETARG_LSEG_P(1);
2531 
2532  PG_RETURN_FLOAT8(box_closept_lseg(NULL, box, lseg));
2533 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:182
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static float8 box_closept_lseg(Point *result, BOX *box, LSEG *lseg)
Definition: geo_ops.c:3058

◆ dist_cpoint()

Datum dist_cpoint ( PG_FUNCTION_ARGS  )

Definition at line 5134 of file geo_ops.c.

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

5135 {
5136  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5137  Point *point = PG_GETARG_POINT_P(1);
5138  float8 result;
5139 
5140  result = float8_mi(point_dt(point, &circle->center), circle->radius);
5141  if (result < 0.0)
5142  result = 0.0;
5143 
5144  PG_RETURN_FLOAT8(result);
5145 }
float8 radius
Definition: geo_decls.h:165
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static float8 point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1971
double float8
Definition: c.h:553
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
Point center
Definition: geo_decls.h:164

◆ dist_cpoly()

Datum dist_cpoly ( PG_FUNCTION_ARGS  )

Definition at line 2591 of file geo_ops.c.

References dist_cpoly_internal(), PG_GETARG_CIRCLE_P, PG_GETARG_POLYGON_P, and PG_RETURN_FLOAT8.

2592 {
2593  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
2594  POLYGON *poly = PG_GETARG_POLYGON_P(1);
2595 
2596  PG_RETURN_FLOAT8(dist_cpoly_internal(circle, poly));
2597 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_POLYGON_P(n)
Definition: geo_decls.h:205
static float8 dist_cpoly_internal(CIRCLE *circle, POLYGON *poly)
Definition: geo_ops.c:2574
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211

◆ dist_cpoly_internal()

static float8 dist_cpoly_internal ( CIRCLE circle,
POLYGON poly 
)
static

Definition at line 2574 of file geo_ops.c.

References CIRCLE::center, dist_ppoly_internal(), float8_mi(), and CIRCLE::radius.

Referenced by dist_cpoly(), and dist_polyc().

2575 {
2576  float8 result;
2577 
2578  /* calculate distance to center, and subtract radius */
2579  result = float8_mi(dist_ppoly_internal(&circle->center, poly),
2580  circle->radius);
2581  if (result < 0.0)
2582  result = 0.0;
2583 
2584  return result;
2585 }
static float8 dist_ppoly_internal(Point *pt, POLYGON *poly)
Definition: geo_ops.c:2633
float8 radius
Definition: geo_decls.h:165
double float8
Definition: c.h:553
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
Point center
Definition: geo_decls.h:164

◆ dist_lb()

Datum dist_lb ( PG_FUNCTION_ARGS  )

Definition at line 2539 of file geo_ops.c.

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

2540 {
2541 #ifdef NOT_USED
2542  LINE *line = PG_GETARG_LINE_P(0);
2543  BOX *box = PG_GETARG_BOX_P(1);
2544 #endif
2545 
2546  /* need to think about this one for a while */
2547  ereport(ERROR,
2548  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2549  errmsg("function \"dist_lb\" not implemented")));
2550 
2551  PG_RETURN_NULL();
2552 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
int errcode(int sqlerrcode)
Definition: elog.c:691
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:194
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:155
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ dist_lp()

Datum dist_lp ( PG_FUNCTION_ARGS  )

Definition at line 2367 of file geo_ops.c.

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

2368 {
2369  LINE *line = PG_GETARG_LINE_P(0);
2370  Point *pt = PG_GETARG_POINT_P(1);
2371 
2372  PG_RETURN_FLOAT8(line_closept_point(NULL, line, pt));
2373 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static float8 line_closept_point(Point *result, LINE *line, Point *pt)
Definition: geo_ops.c:2727
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:194
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177

◆ dist_ls()

Datum dist_ls ( PG_FUNCTION_ARGS  )

Definition at line 2503 of file geo_ops.c.

References lseg_closept_line(), PG_GETARG_LINE_P, PG_GETARG_LSEG_P, and PG_RETURN_FLOAT8.

2504 {
2505  LINE *line = PG_GETARG_LINE_P(0);
2506  LSEG *lseg = PG_GETARG_LSEG_P(1);
2507 
2508  PG_RETURN_FLOAT8(lseg_closept_line(NULL, lseg, line));
2509 }
static float8 lseg_closept_line(Point *result, LSEG *lseg, LINE *line)
Definition: geo_ops.c:3005
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:182
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:194

◆ dist_pathp()

Datum dist_pathp ( PG_FUNCTION_ARGS  )

Definition at line 2455 of file geo_ops.c.

References dist_ppath_internal(), PG_GETARG_PATH_P, PG_GETARG_POINT_P, and PG_RETURN_FLOAT8.

2456 {
2457  PATH *path = PG_GETARG_PATH_P(0);
2458  Point *pt = PG_GETARG_POINT_P(1);
2459 
2461 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
static float8 dist_ppath_internal(Point *pt, PATH *path)
Definition: geo_ops.c:2400
#define PG_GETARG_PATH_P(n)
Definition: geo_decls.h:188

◆ dist_pb()

Datum dist_pb ( PG_FUNCTION_ARGS  )

Definition at line 2467 of file geo_ops.c.

References box_closept_point(), PG_GETARG_BOX_P, PG_GETARG_POINT_P, and PG_RETURN_FLOAT8.

2468 {
2469  Point *pt = PG_GETARG_POINT_P(0);
2470  BOX *box = PG_GETARG_BOX_P(1);
2471 
2472  PG_RETURN_FLOAT8(box_closept_point(NULL, box, pt));
2473 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
static float8 box_closept_point(Point *result, BOX *box, Point *point)
Definition: geo_ops.c:2881

◆ dist_pc()

Datum dist_pc ( PG_FUNCTION_ARGS  )

Definition at line 5116 of file geo_ops.c.

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

5117 {
5118  Point *point = PG_GETARG_POINT_P(0);
5119  CIRCLE *circle = PG_GETARG_CIRCLE_P(1);
5120  float8 result;
5121 
5122  result = float8_mi(point_dt(point, &circle->center),
5123  circle->radius);
5124  if (result < 0.0)
5125  result = 0.0;
5126 
5127  PG_RETURN_FLOAT8(result);
5128 }
float8 radius
Definition: geo_decls.h:165
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static float8 point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1971
double float8
Definition: c.h:553
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211
Point center
Definition: geo_decls.h:164

◆ dist_pl()

Datum dist_pl ( PG_FUNCTION_ARGS  )

Definition at line 2355 of file geo_ops.c.

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

2356 {
2357  Point *pt = PG_GETARG_POINT_P(0);
2358  LINE *line = PG_GETARG_LINE_P(1);
2359 
2360  PG_RETURN_FLOAT8(line_closept_point(NULL, line, pt));
2361 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static float8 line_closept_point(Point *result, LINE *line, Point *pt)
Definition: geo_ops.c:2727
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:194
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177

◆ dist_polyc()

Datum dist_polyc ( PG_FUNCTION_ARGS  )

Definition at line 2603 of file geo_ops.c.

References dist_cpoly_internal(), PG_GETARG_CIRCLE_P, PG_GETARG_POLYGON_P, and PG_RETURN_FLOAT8.

2604 {
2605  POLYGON *poly = PG_GETARG_POLYGON_P(0);
2606  CIRCLE *circle = PG_GETARG_CIRCLE_P(1);
2607 
2608  PG_RETURN_FLOAT8(dist_cpoly_internal(circle, poly));
2609 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_POLYGON_P(n)
Definition: geo_decls.h:205
static float8 dist_cpoly_internal(CIRCLE *circle, POLYGON *poly)
Definition: geo_ops.c:2574
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:211

◆ dist_polyp()

Datum dist_polyp ( PG_FUNCTION_ARGS  )

Definition at line 2624 of file geo_ops.c.

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

2625 {
2626  POLYGON *poly = PG_GETARG_POLYGON_P(0);
2627  Point *point = PG_GETARG_POINT_P(1);
2628 
2629  PG_RETURN_FLOAT8(dist_ppoly_internal(point, poly));
2630 }
static float8 dist_ppoly_internal(Point *pt, POLYGON *poly)
Definition: geo_ops.c:2633
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_POLYGON_P(n)
Definition: geo_decls.h:205
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177

◆ dist_ppath()

Datum dist_ppath ( PG_FUNCTION_ARGS  )

Definition at line 2443 of file geo_ops.c.

References dist_ppath_internal(), PG_GETARG_PATH_P, PG_GETARG_POINT_P, and PG_RETURN_FLOAT8.

2444 {
2445  Point *pt = PG_GETARG_POINT_P(0);
2446  PATH *path = PG_GETARG_PATH_P(1);
2447 
2449 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
static float8 dist_ppath_internal(Point *pt, PATH *path)
Definition: geo_ops.c:2400
#define PG_GETARG_PATH_P(n)
Definition: geo_decls.h:188

◆ dist_ppath_internal()

static float8 dist_ppath_internal ( Point pt,
PATH path 
)
static

Definition at line 2400 of file geo_ops.c.

References Assert, PATH::closed, float8_lt(), i, lseg_closept_point(), PATH::npts, PATH::p, and statlseg_construct().

Referenced by dist_pathp(), and dist_ppath().

2401 {
2402  float8 result = 0.0; /* keep compiler quiet */
2403  bool have_min = false;
2404  float8 tmp;
2405  int i;
2406  LSEG lseg;
2407 
2408  Assert(path->npts > 0);
2409 
2410  /*
2411  * The distance from a point to a path is the smallest distance from the
2412  * point to any of its constituent segments.
2413  */
2414  for (i = 0; i < path->npts; i++)
2415  {
2416  int iprev;
2417 
2418  if (i > 0)
2419  iprev = i - 1;
2420  else
2421  {
2422  if (!path->closed)
2423  continue;
2424  iprev = path->npts - 1; /* Include the closure segment */
2425  }
2426 
2427  statlseg_construct(&lseg, &path->p[iprev], &path->p[i]);
2428  tmp = lseg_closept_point(NULL, &lseg, pt);
2429  if (!have_min || float8_lt(tmp, result))
2430  {
2431  result = tmp;
2432  have_min = true;
2433  }
2434  }
2435 
2436  return result;
2437 }
int32 closed
Definition: geo_decls.h:119
static void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: geo_ops.c:2107
double float8
Definition: c.h:553
static float8 lseg_closept_point(Point *result, LSEG *lseg, Point *pt)
Definition: geo_ops.c:2775
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:121
int32 npts
Definition: geo_decls.h:118
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:291
#define Assert(condition)
Definition: c.h:800
int i

◆ dist_ppoly()

Datum dist_ppoly ( PG_FUNCTION_ARGS  )

Definition at line 2615 of file geo_ops.c.

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

2616 {
2617  Point *point = PG_GETARG_POINT_P(0);
2618  POLYGON *poly = PG_GETARG_POLYGON_P(1);
2619 
2620  PG_RETURN_FLOAT8(dist_ppoly_internal(point, poly));
2621 }
static float8 dist_ppoly_internal(Point *pt, POLYGON *poly)
Definition: geo_ops.c:2633
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_POLYGON_P(n)
Definition: geo_decls.h:205
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177

◆ dist_ppoly_internal()

static float8 dist_ppoly_internal ( Point pt,
POLYGON poly 
)
static

Definition at line 2633 of file geo_ops.c.

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

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

2634 {
2635  float8 result;
2636  float8 d;
2637  int i;
2638  LSEG seg;
2639 
2640  if (point_inside(pt, poly->npts, poly->p) != 0)
2641  return 0.0;
2642 
2643  /* initialize distance with segment between first and last points */
2644  seg.p[0].x = poly->p[0].x;
2645  seg.p[0].y = poly->p[0].y;
2646  seg.p[1].x = poly->p[poly->npts - 1].x;
2647  seg.p[1].y = poly->p[poly->npts - 1].y;
2648  result = lseg_closept_point(NULL, &seg, pt);
2649 
2650  /* check distances for other segments */
2651  for (i = 0; i < poly->npts - 1; i++)
2652  {
2653  seg.p[0].x = poly->p[i].x;
2654  seg.p[0].y = poly->p[i].y;
2655  seg.p[1].x = poly->p[i + 1].x;
2656  seg.p[1].y = poly->p[i + 1].y;
2657  d = lseg_closept_point(NULL, &seg, pt);
2658  if (float8_lt(d, result))
2659  result = d;
2660  }
2661 
2662  return result;
2663 }
float8 x
Definition: geo_decls.h:98
static int point_inside(Point *p, int npts, Point *plist)
Definition: geo_ops.c:5347
int32 npts
Definition: geo_decls.h:154
double float8
Definition: c.h:553
static float8 lseg_closept_point(Point *result, LSEG *lseg, Point *pt)
Definition: geo_ops.c:2775
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:156
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:291
float8 y
Definition: geo_decls.h:98
Point p[2]
Definition: geo_decls.h:108
int i

◆ dist_ps()

Datum dist_ps ( PG_FUNCTION_ARGS  )

Definition at line 2379 of file geo_ops.c.

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

2380 {
2381  Point *pt = PG_GETARG_POINT_P(0);
2382  LSEG *lseg = PG_GETARG_LSEG_P(1);
2383 
2384  PG_RETURN_FLOAT8(lseg_closept_point(NULL, lseg, pt));
2385 }
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:182
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static float8 lseg_closept_point(Point *result, LSEG *lseg, Point *pt)
Definition: geo_ops.c:2775
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177

◆ dist_sb()

Datum dist_sb ( PG_FUNCTION_ARGS  )

Definition at line 2515 of file geo_ops.c.

References box_closept_lseg(), PG_GETARG_BOX_P, PG_GETARG_LSEG_P, and PG_RETURN_FLOAT8.

2516 {
2517  LSEG *lseg = PG_GETARG_LSEG_P(0);
2518  BOX *box = PG_GETARG_BOX_P(1);
2519 
2520  PG_RETURN_FLOAT8(box_closept_lseg(NULL, box, lseg));
2521 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:182
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static float8 box_closept_lseg(Point *result, BOX *box, LSEG *lseg)
Definition: geo_ops.c:3058

◆ dist_sl()

Datum dist_sl ( PG_FUNCTION_ARGS  )

Definition at line 2491 of file geo_ops.c.

References lseg_closept_line(), PG_GETARG_LINE_P, PG_GETARG_LSEG_P, and PG_RETURN_FLOAT8.

2492 {
2493  LSEG *lseg = PG_GETARG_LSEG_P(0);
2494  LINE *line = PG_GETARG_LINE_P(1);
2495 
2496  PG_RETURN_FLOAT8(lseg_closept_line(NULL, lseg, line));
2497 }
static float8 lseg_closept_line(Point *result, LSEG *lseg, LINE *line)
Definition: geo_ops.c:3005
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:182
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:194

◆ dist_sp()

Datum dist_sp ( PG_FUNCTION_ARGS  )

Definition at line 2391 of file geo_ops.c.

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

2392 {
2393  LSEG *lseg = PG_GETARG_LSEG_P(0);
2394  Point *pt = PG_GETARG_POINT_P(1);
2395 
2396  PG_RETURN_FLOAT8(lseg_closept_point(NULL, lseg, pt));
2397 }
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:182
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static float8 lseg_closept_point(Point *result, LSEG *lseg, Point *pt)
Definition: geo_ops.c:2775
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177

◆ inter_lb()

Datum inter_lb ( PG_FUNCTION_ARGS  )

Definition at line 3389 of file geo_ops.c.

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

3390 {
3391  LINE *line = PG_GETARG_LINE_P(0);
3392  BOX *box = PG_GETARG_BOX_P(1);
3393  LSEG bseg;
3394  Point p1,
3395  p2;
3396 
3397  /* pairwise check lseg intersections */
3398  p1.x = box->low.x;
3399  p1.y = box->low.y;
3400  p2.x = box->low.x;
3401  p2.y = box->high.y;
3402  statlseg_construct(&bseg, &p1, &p2);
3403  if (lseg_interpt_line(NULL, &bseg, line))
3404  PG_RETURN_BOOL(true);
3405  p1.x = box->high.x;
3406  p1.y = box->high.y;
3407  statlseg_construct(&bseg, &p1, &p2);
3408  if (lseg_interpt_line(NULL, &bseg, line))
3409  PG_RETURN_BOOL(true);
3410  p2.x = box->high.x;
3411  p2.y = box->low.y;
3412  statlseg_construct(&bseg, &p1, &p2);
3413  if (lseg_interpt_line(NULL, &bseg, line))
3414  PG_RETURN_BOOL(true);
3415  p1.x = box->low.x;
3416  p1.y = box->low.y;
3417  statlseg_construct(&bseg, &p1, &p2);
3418  if (lseg_interpt_line(NULL, &bseg, line))
3419  PG_RETURN_BOOL(true);
3420 
3421  /* if we dropped through, no intersection */
3422  PG_RETURN_BOOL(false);
3423 }
Definition: geo_decls.h:140
static bool lseg_interpt_line(Point *result, LSEG *lseg, LINE *line)
Definition: geo_ops.c:2678
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
float8 x
Definition: geo_decls.h:98
static void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: geo_ops.c:2107
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:194
Point low
Definition: geo_decls.h:142
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
float8 y
Definition: geo_decls.h:98
Point high
Definition: geo_decls.h:142

◆ inter_sb()

Datum inter_sb ( PG_FUNCTION_ARGS  )

Definition at line 3376 of file geo_ops.c.

References box_interpt_lseg(), PG_GETARG_BOX_P, PG_GETARG_LSEG_P, and PG_RETURN_BOOL.

3377 {
3378  LSEG *lseg = PG_GETARG_LSEG_P(0);
3379  BOX *box = PG_GETARG_BOX_P(1);
3380 
3381  PG_RETURN_BOOL(box_interpt_lseg(NULL, box, lseg));
3382 }
Definition: geo_decls.h:140
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:199
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:182
static bool box_interpt_lseg(Point *result, BOX *box, LSEG *lseg)
Definition: geo_ops.c:3324
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ inter_sl()

Datum inter_sl ( PG_FUNCTION_ARGS  )

Definition at line 3299 of file geo_ops.c.

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

3300 {
3301  LSEG *lseg = PG_GETARG_LSEG_P(0);
3302  LINE *line = PG_GETARG_LINE_P(1);
3303 
3304  PG_RETURN_BOOL(lseg_interpt_line(NULL, lseg, line));
3305 }
static bool lseg_interpt_line(Point *result, LSEG *lseg, LINE *line)
Definition: geo_ops.c:2678
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:182
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:194
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ line_closept_point()

static float8 line_closept_point ( Point result,
LINE line,
Point pt 
)
static

Definition at line 2727 of file geo_ops.c.

References get_float8_nan(), line_construct(), line_interpt_line(), line_invsl(), and point_dt().

Referenced by close_pl(), close_sl(), dist_lp(), dist_pl(), and lseg_closept_line().

2728 {
2729  Point closept;
2730  LINE tmp;
2731 
2732  /*
2733  * We drop a perpendicular to find the intersection point. Ordinarily we
2734  * should always find it, but that can fail in the presence of NaN
2735  * coordinates, and perhaps even from simple roundoff issues.
2736  */
2737  line_construct(&tmp, point, line_invsl(line));
2738  if (!line_interpt_line(&closept, &tmp, line))
2739  {
2740  if (result != NULL)
2741  *result = *point;
2742 
2743  return get_float8_nan();
2744  }
2745 
2746  if (result != NULL)
2747  *result = closept;
2748 
2749  return point_dt(&closept, point);
2750 }
static bool line_interpt_line(Point *result, LINE *l1, LINE *l2)
Definition: geo_ops.c:1287
static float8 line_invsl(LINE *line)
Definition: geo_ops.c:1220
static void line_construct(LINE *result, Point *pt, float8 m)
Definition: geo_ops.c:1056
static float8 point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1971
static float8 get_float8_nan(void)
Definition: float.h:122

◆ line_construct()

static void line_construct ( LINE result,
Point pt,
float8  m 
)
inlinestatic

Definition at line 1056 of file geo_ops.c.

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

Referenced by line_closept_point(), line_construct_pp(), line_in(), lseg_closept_point(), lseg_interpt_line(), and lseg_interpt_lseg().

1057 {
1058  if (isinf(m))
1059  {
1060  /* vertical - use "x = C" */
1061  result->A = -1.0;
1062  result->B = 0.0;
1063  result->C = pt->x;
1064  }
1065  else if (m == 0)
1066  {
1067  /* horizontal - use "y = C" */
1068  result->A = 0.0;
1069  result->B = -1.0;
1070  result->C = pt->y;
1071  }
1072  else
1073  {
1074  /* use "mx - y + yinter = 0" */
1075  result->A = m;
1076  result->B = -1.0;
1077  result->C = float8_mi(pt->y, float8_mul(m, pt->x));
1078  /* on some platforms, the preceding expression tends to produce -0 */
1079  if (result->C == 0.0)
1080  result->C = 0.0;
1081  }
1082 }
float8 C
Definition: geo_decls.h:130
float8 x
Definition: geo_decls.h:98
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:207
float8 B
Definition: geo_decls.h:130
float8 A
Definition: geo_decls.h:130
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
float8 y
Definition: geo_decls.h:98

◆ line_construct_pp()

Datum line_construct_pp ( PG_FUNCTION_ARGS  )

Definition at line 1088 of file geo_ops.c.

References ereport, errcode(), errmsg(), ERROR, line_construct(), palloc(), PG_GETARG_POINT_P, PG_RETURN_LINE_P, point_eq_point(), and point_sl().

1089 {
1090  Point *pt1 = PG_GETARG_POINT_P(0);
1091  Point *pt2 = PG_GETARG_POINT_P(1);
1092  LINE *result = (LINE *) palloc(sizeof(LINE));
1093 
1094  if (point_eq_point(pt1, pt2))
1095  ereport(ERROR,
1096  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1097  errmsg("invalid line specification: must be two distinct points")));
1098 
1099  line_construct(result, pt1, point_sl(pt1, pt2));
1100 
1101  PG_RETURN_LINE_P(result);
1102 }
static void line_construct(LINE *result, Point *pt, float8 m)
Definition: geo_ops.c:1056
int errcode(int sqlerrcode)
Definition: elog.c:691
#define ERROR
Definition: elog.h:43
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
static bool point_eq_point(Point *pt1, Point *pt2)
Definition: geo_ops.c:1946
static float8 point_sl(Point *pt1, Point *pt2)
Definition: geo_ops.c:1992
#define ereport(elevel,...)
Definition: elog.h:155
#define PG_RETURN_LINE_P(x)
Definition: geo_decls.h:195
void * palloc(Size size)
Definition: mcxt.c:950
int errmsg(const char *fmt,...)
Definition: elog.c:902

◆ line_contain_point()

static bool line_contain_point ( LINE line,
Point point 
)
static

Definition at line 3148 of file geo_ops.c.

References LINE::A, LINE::B, LINE::C, float8_mul(), float8_pl(), FPzero, Point::x, and Point::y.

Referenced by on_pl(), and on_sl().

3149 {
3150  return FPzero(float8_pl(float8_pl(float8_mul(line->A, point->x),
3151  float8_mul(line->B, point->y)),
3152  line->C));
3153 }
float8 C
Definition: geo_decls.h:130
#define FPzero(A)
Definition: geo_decls.h:44
float8 x
Definition: geo_decls.h:98
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:207
float8 B
Definition: geo_decls.h:130
float8 A
Definition: geo_decls.h:130
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157
float8 y
Definition: geo_decls.h:98

◆ line_decode()

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

Definition at line 938 of file geo_ops.c.

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

Referenced by line_in().

939 {
940  /* s was already advanced over leading '{' */
941  line->A = single_decode(s, &s, "line", str);
942  if (*s++ != DELIM)
943  return false;
944  line->B = single_decode(s, &s, "line", str);
945  if (*s++ != DELIM)
946  return false;
947  line->C = single_decode(s, &s, "line", str);
948  if (*s++ != RDELIM_L)
949  return false;
950  while (isspace((unsigned char) *s))
951  s++;
952  if (*s != '\0')
953  return false;
954  return true;
955 }
static float8 single_decode(char *num, char **endptr_p, const char *type_name, const char *orig_string)
Definition: geo_ops.c:189
float8 C
Definition: geo_decls.h:130
#define DELIM
Definition: geo_ops.c:154
float8 B
Definition: geo_decls.h:130
float8 A
Definition: geo_decls.h:130
#define RDELIM_L
Definition: geo_ops.c:160

◆ line_distance()

Datum line_distance ( PG_FUNCTION_ARGS  )

Definition at line 1234 of file geo_ops.c.

References LINE::A, LINE::B, LINE::C, float8_div(), float8_mi(), float8_mul(), FPzero, HYPOT, line_interpt_line(), PG_GETARG_LINE_P, and PG_RETURN_FLOAT8.

1235 {
1236  LINE *l1 = PG_GETARG_LINE_P(0);
1237  LINE *l2 = PG_GETARG_LINE_P(1);
1238  float8 ratio;
1239 
1240  if (line_interpt_line(NULL, l1, l2)) /* intersecting? */
1241  PG_RETURN_FLOAT8(0.0);
1242 
1243  if (!FPzero(l1->A) && !isnan(l1->A) && !FPzero(l2->A) && !isnan(l2->A))
1244  ratio = float8_div(l1->A, l2->A);
1245  else if (!FPzero(l1->B) && !isnan(l1->B) && !FPzero(l2->B) && !isnan(l2->B))
1246  ratio = float8_div(l1->B, l2->B);
1247  else
1248  ratio = 1.0;
1249 
1251  float8_mul(ratio, l2->C))),
1252  HYPOT(l1->A, l1->B)));
1253 }
static bool line_interpt_line(Point *result, LINE *l1, LINE *l2)
Definition: geo_ops.c:1287
float8 C
Definition: geo_decls.h:130
#define FPzero(A)
Definition: geo_decls.h:44
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:207
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:194
double float8
Definition: c.h:553
float8 B
Definition: geo_decls.h:130
float8 A
Definition: geo_decls.h:130
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
#define HYPOT(A, B)
Definition: geo_decls.h:91
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:237

◆ line_eq()

Datum line_eq ( PG_FUNCTION_ARGS  )

Definition at line 1167 of file geo_ops.c.

References LINE::A, LINE::B, LINE::C, float8_div(), float8_eq(), float8_mul(), FPeq(), FPzero, PG_GETARG_LINE_P, PG_RETURN_BOOL, and unlikely.

1168 {
1169  LINE *l1 = PG_GETARG_LINE_P(0);
1170  LINE *l2 = PG_GETARG_LINE_P(1);
1171  float8 ratio;
1172 
1173  /* If any NaNs are involved, insist on exact equality */
1174  if (unlikely(isnan(l1->A) || isnan(l1->B) || isnan(l1->C) ||
1175  isnan(l2->A) || isnan(l2->B) || isnan(l2->C)))
1176  {
1177  PG_RETURN_BOOL(float8_eq(l1->A, l2->A) &&
1178  float8_eq(l1->B, l2->B) &&
1179  float8_eq(l1->C, l2->C));
1180  }
1181 
1182  /* Otherwise, lines whose parameters are proportional are the same */
1183  if (!FPzero(l2->A))
1184  ratio = float8_div(l1->A, l2->A);
1185  else if (!FPzero(l2->B))
1186  ratio = float8_div(l1->B, l2->B);
1187  else if (!FPzero(l2->C))
1188  ratio = float8_div(l1->C, l2->C);
1189  else
1190  ratio = 1.0;
1191 
1192  PG_RETURN_BOOL(FPeq(l1->A, float8_mul(ratio, l2->A)) &&
1193  FPeq(l1->B, float8_mul(ratio, l2->B)) &&
1194  FPeq(l1->C, float8_mul(ratio, l2->C)));
1195 }
float8 C
Definition: geo_decls.h:130
#define FPzero(A)
Definition: geo_decls.h:44
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:207
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:194
double float8
Definition: c.h:553
float8 B
Definition: geo_decls.h:130
float8 A
Definition: geo_decls.h:130
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:237
static bool float8_eq(const float8 val1, const float8 val2)
Definition: float.h:267
#define unlikely(x)
Definition: c.h:261
static bool FPeq(double A, double B)
Definition: geo_decls.h:47

◆ line_horizontal()

Datum line_horizontal ( PG_FUNCTION_ARGS  )

Definition at line 1155 of file geo_ops.c.

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

1156 {
1157  LINE *line = PG_GETARG_LINE_P(0);
1158 
1159  PG_RETURN_BOOL(FPzero(line->A));
1160 }
#define FPzero(A)
Definition: geo_decls.h:44
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:194
float8 A
Definition: geo_decls.h:130
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ line_in()

Datum line_in ( PG_FUNCTION_ARGS  )

Definition at line 958 of file geo_ops.c.

References LINE::A, LINE::B, ereport, errcode(), errmsg(), ERROR, FPzero, LDELIM_L, line_construct(), line_decode(), lseg_sl(), LSEG::p, palloc(), path_decode(), PG_GETARG_CSTRING, PG_RETURN_LINE_P, point_eq_point(), and generate_unaccent_rules::str.

959 {
960  char *str = PG_GETARG_CSTRING(0);
961  LINE *line = (LINE *) palloc(sizeof(LINE));
962  LSEG lseg;
963  bool isopen;
964  char *s;
965 
966  s = str;
967  while (isspace((unsigned char) *s))
968  s++;
969  if (*s == LDELIM_L)
970  {
971  if (!line_decode(s + 1, str, line))
972  ereport(ERROR,
973  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
974  errmsg("invalid input syntax for type %s: \"%s\"",
975  "line", str)));
976  if (FPzero(line->A) && FPzero(line->B))
977  ereport(ERROR,
978  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
979  errmsg("invalid line specification: A and B cannot both be zero")));
980  }
981  else
982  {
983  path_decode(s, true, 2, &lseg.p[0], &isopen, NULL, "line", str);
984  if (point_eq_point(&lseg.p[0], &lseg.p[1]))
985  ereport(ERROR,
986  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
987  errmsg("invalid line specification: must be two distinct points")));
988  line_construct(line, &lseg.p[0], lseg_sl(&lseg));
989  }
990 
991  PG_RETURN_LINE_P(line);
992 }
#define FPzero(A)
Definition: geo_decls.h:44
static float8 lseg_sl(LSEG *lseg)
Definition: geo_ops.c:2120
static void line_construct(LINE *result, Point *pt, float8 m)
Definition: geo_ops.c:1056
int errcode(int sqlerrcode)
Definition: elog.c:691
#define ERROR
Definition: elog.h:43
static bool point_eq_point(Point *pt1, Point *pt2)
Definition: geo_ops.c:1946
float8 B
Definition: geo_decls.h:130
#define LDELIM_L
Definition: geo_ops.c:159
float8 A
Definition: geo_decls.h:130
static bool line_decode(char *s, const char *str, LINE *line)
Definition: geo_ops.c:938
#define ereport(elevel,...)
Definition: elog.h:155
Point p[2]
Definition: geo_decls.h:108
#define PG_RETURN_LINE_P(x)
Definition: geo_decls.h:195
void * palloc(Size size)
Definition: mcxt.c:950
int errmsg(const char *fmt,...)
Definition: elog.c:902
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
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:258

◆ line_interpt()

Datum line_interpt ( PG_FUNCTION_ARGS  )

Definition at line 1259 of file geo_ops.c.

References line_interpt_line(), palloc(), PG_GETARG_LINE_P, PG_RETURN_NULL, and PG_RETURN_POINT_P.

1260 {
1261  LINE *l1 = PG_GETARG_LINE_P(0);
1262  LINE *l2 = PG_GETARG_LINE_P(1);
1263  Point *result;
1264 
1265  result = (Point *) palloc(sizeof(Point));
1266 
1267  if (!line_interpt_line(result, l1, l2))
1268  PG_RETURN_NULL();
1269  PG_RETURN_POINT_P(result);
1270 }
static bool line_interpt_line(Point *result, LINE *l1, LINE *l2)
Definition: geo_ops.c:1287
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:194
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:178
void * palloc(Size size)
Definition: mcxt.c:950
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ line_interpt_line()

static bool line_interpt_line ( Point result,
LINE l1,
LINE l2 
)
static

Definition at line 1287 of file geo_ops.c.

References LINE::A, LINE::B, LINE::C, float8_div(), float8_mi(), float8_mul(), float8_pl(), FPeq(), FPzero, and point_construct().

Referenced by line_closept_point(), line_distance(), line_interpt(), line_intersect(), line_parallel(), and lseg_interpt_line().

1288 {
1289  float8 x,
1290  y;
1291 
1292  if (!FPzero(l1->B))
1293  {
1294  if (FPeq(l2->A, float8_mul(l1->A, float8_div(l2->B, l1->B))))
1295  return false;
1296 
1297  x = float8_div(float8_mi(float8_mul(l1->B, l2->C),
1298  float8_mul(l2->B, l1->C)),
1299  float8_mi(float8_mul(l1->A, l2->B),
1300  float8_mul(l2->A, l1->B)));
1301  y = float8_div(-float8_pl(float8_mul(l1->A, x), l1->C), l1->B);
1302  }
1303  else if (!FPzero(l2->B))
1304  {
1305  if (FPeq(l1->A, float8_mul(l2->A, float8_div(l1->B, l2->B))))
1306  return false;
1307 
1308  x = float8_div(float8_mi(float8_mul(l2->B, l1->C),
1309  float8_mul(l1->B, l2->C)),
1310  float8_mi(float8_mul(l2->A, l1->B),
1311  float8_mul(l1->A, l2->B)));
1312  y = float8_div(-float8_pl(float8_mul(l2->A, x), l2->C), l2->B);
1313  }
1314  else
1315  return false;
1316 
1317  /* On some platforms, the preceding expressions tend to produce -0. */
1318  if (x == 0.0)
1319  x = 0.0;
1320  if (y == 0.0)
1321  y = 0.0;
1322 
1323  if (result != NULL)
1324  point_construct(result, x, y);
1325 
1326  return true;
1327 }
float8 C
Definition: geo_decls.h:130
#define FPzero(A)
Definition: geo_decls.h:44
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:207
static void point_construct(Point *result, float8 x, float8 y)
Definition: geo_ops.c:1853
double float8
Definition: c.h:553
float8 B
Definition: geo_decls.h:130
float8 A
Definition: geo_decls.h:130
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:157
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:181
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:237
static bool FPeq(double A, double B)
Definition: geo_decls.h:47

◆ line_intersect()

Datum line_intersect ( PG_FUNCTION_ARGS  )

Definition at line 1110 of file geo_ops.c.

References line_interpt_line(), PG_GETARG_LINE_P, and PG_RETURN_BOOL.

1111 {
1112  LINE *l1 = PG_GETARG_LINE_P(0);
1113  LINE *l2 = PG_GETARG_LINE_P(1);
1114 
1115  PG_RETURN_BOOL(line_interpt_line(NULL, l1, l2));
1116 }
static bool line_interpt_line(Point *result, LINE *l1, LINE *l2)
Definition: geo_ops.c:1287
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:194
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359

◆ line_invsl()

static float8 line_invsl ( LINE line)
inlinestatic

Definition at line 1220 of file geo_ops.c.

References LINE::A, LINE::B, float8_div(), FPzero, and get_float8_infinity().

Referenced by line_closept_point().

1221 {
1222  if (FPzero(line->A))
1223  return get_float8_infinity();
1224  if (FPzero(line->B))
1225  return 0.0;
1226  return float8_div(line->B, line->A);
1227 }
static float8 get_float8_infinity(void)
Definition: float.h:93
#define FPzero(A)
Definition: geo_decls.h:44
float8 B
Definition: geo_decls.h:130
float8 A
Definition: geo_decls.h:130
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:237

◆ line_out()

Datum line_out ( PG_FUNCTION_ARGS  )

Definition at line 996 of file geo_ops.c.

References LINE::A, LINE::B, LINE::C,