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 5329 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define FPgt(A, B)
Definition: geo_decls.h:38
Point low
Definition: geo_decls.h:101
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
float8 y
Definition: geo_decls.h:57
Point high
Definition: geo_decls.h:101

◆ 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
Point low
Definition: geo_decls.h:101
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
float8 y
Definition: geo_decls.h:57
Point high
Definition: geo_decls.h:101
#define FPge(A, B)
Definition: geo_decls.h:39

◆ box_add()

Datum box_add ( PG_FUNCTION_ARGS  )

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

4218 {
4219  BOX *box = PG_GETARG_BOX_P(0);
4220  Point *p = PG_GETARG_POINT_P(1);
4221  BOX *result;
4222 
4223  result = (BOX *) palloc(sizeof(BOX));
4224 
4225  point_add_point(&result->high, &box->high, p);
4226  point_add_point(&result->low, &box->low, p);
4227 
4228  PG_RETURN_BOX_P(result);
4229 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
Point low
Definition: geo_decls.h:101
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:159
static void point_add_point(Point *result, Point *pt1, Point *pt2)
Definition: geo_ops.c:4097
Point high
Definition: geo_decls.h:101
void * palloc(Size size)
Definition: mcxt.c:949

◆ 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:232
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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
Point low
Definition: geo_decls.h:101
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define FPlt(A, B)
Definition: geo_decls.h:36
float8 y
Definition: geo_decls.h:57
Point high
Definition: geo_decls.h:101

◆ 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 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
Point low
Definition: geo_decls.h:101
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
float8 y
Definition: geo_decls.h:57
Point high
Definition: geo_decls.h:101
#define FPle(A, B)
Definition: geo_decls.h:37

◆ 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
static void box_cn(Point *center, BOX *box)
Definition: geo_ops.c:860
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:137
void * palloc(Size size)
Definition: mcxt.c:949

◆ box_circle()

Datum box_circle ( PG_FUNCTION_ARGS  )

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

5201 {
5202  BOX *box = PG_GETARG_BOX_P(0);
5203  CIRCLE *circle;
5204 
5205  circle = (CIRCLE *) palloc(sizeof(CIRCLE));
5206 
5207  circle->center.x = float8_div(float8_pl(box->high.x, box->low.x), 2.0);
5208  circle->center.y = float8_div(float8_pl(box->high.y, box->low.y), 2.0);
5209 
5210  circle->radius = point_dt(&circle->center, &box->high);
5211 
5212  PG_RETURN_CIRCLE_P(circle);
5213 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
float8 x
Definition: geo_decls.h:57
float8 radius
Definition: geo_decls.h:124
static float8 point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1959
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:187
Point low
Definition: geo_decls.h:101
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:171
float8 y
Definition: geo_decls.h:57
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:260
Point high
Definition: geo_decls.h:101
Point center
Definition: geo_decls.h:123
void * palloc(Size size)
Definition: mcxt.c:949

◆ box_closept_lseg()

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

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

3047 {
3048  float8 dist,
3049  d;
3050  Point point,
3051  closept;
3052  LSEG bseg;
3053 
3054  if (box_interpt_lseg(result, box, lseg))
3055  return 0.0;
3056 
3057  /* pairwise check lseg distances */
3058  point.x = box->low.x;
3059  point.y = box->high.y;
3060  statlseg_construct(&bseg, &box->low, &point);
3061  dist = lseg_closept_lseg(result, &bseg, lseg);
3062 
3063  statlseg_construct(&bseg, &box->high, &point);
3064  d = lseg_closept_lseg(&closept, &bseg, lseg);
3065  if (float8_lt(d, dist))
3066  {
3067  dist = d;
3068  if (result != NULL)
3069  *result = closept;
3070  }
3071 
3072  point.x = box->high.x;
3073  point.y = box->low.y;
3074  statlseg_construct(&bseg, &box->low, &point);
3075  d = lseg_closept_lseg(&closept, &bseg, lseg);
3076  if (float8_lt(d, dist))
3077  {
3078  dist = d;
3079  if (result != NULL)
3080  *result = closept;
3081  }
3082 
3083  statlseg_construct(&bseg, &box->high, &point);
3084  d = lseg_closept_lseg(&closept, &bseg, lseg);
3085  if (float8_lt(d, dist))
3086  {
3087  dist = d;
3088  if (result != NULL)
3089  *result = closept;
3090  }
3091 
3092  return dist;
3093 }
static float8 lseg_closept_lseg(Point *result, LSEG *on_lseg, LSEG *to_lseg)
Definition: geo_ops.c:2801
float8 x
Definition: geo_decls.h:57
static void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: geo_ops.c:2095
Definition: geo_decls.h:65
double float8
Definition: c.h:491
static bool box_interpt_lseg(Point *result, BOX *box, LSEG *lseg)
Definition: geo_ops.c:3312
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:314
Point low
Definition: geo_decls.h:101
float8 y
Definition: geo_decls.h:57
Point high
Definition: geo_decls.h:101

◆ box_closept_point()

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

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

2870 {
2871  float8 dist,
2872  d;
2873  Point point,
2874  closept;
2875  LSEG lseg;
2876 
2877  if (box_contain_point(box, pt))
2878  {
2879  if (result != NULL)
2880  *result = *pt;
2881 
2882  return 0.0;
2883  }
2884 
2885  /* pairwise check lseg distances */
2886  point.x = box->low.x;
2887  point.y = box->high.y;
2888  statlseg_construct(&lseg, &box->low, &point);
2889  dist = lseg_closept_point(result, &lseg, pt);
2890 
2891  statlseg_construct(&lseg, &box->high, &point);
2892  d = lseg_closept_point(&closept, &lseg, pt);
2893  if (float8_lt(d, dist))
2894  {
2895  dist = d;
2896  if (result != NULL)
2897  *result = closept;
2898  }
2899 
2900  point.x = box->high.x;
2901  point.y = box->low.y;
2902  statlseg_construct(&lseg, &box->low, &point);
2903  d = lseg_closept_point(&closept, &lseg, pt);
2904  if (float8_lt(d, dist))
2905  {
2906  dist = d;
2907  if (result != NULL)
2908  *result = closept;
2909  }
2910 
2911  statlseg_construct(&lseg, &box->high, &point);
2912  d = lseg_closept_point(&closept, &lseg, pt);
2913  if (float8_lt(d, dist))
2914  {
2915  dist = d;
2916  if (result != NULL)
2917  *result = closept;
2918  }
2919 
2920  return dist;
2921 }
static bool box_contain_point(BOX *box, Point *point)
Definition: geo_ops.c:3179
float8 x
Definition: geo_decls.h:57
static void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: geo_ops.c:2095
Definition: geo_decls.h:65
double float8
Definition: c.h:491
static float8 lseg_closept_point(Point *result, LSEG *lseg, Point *pt)
Definition: geo_ops.c:2763
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:314
Point low
Definition: geo_decls.h:101
float8 y
Definition: geo_decls.h:57
Point high
Definition: geo_decls.h:101

◆ 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:57
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:187
Point low
Definition: geo_decls.h:101
float8 y
Definition: geo_decls.h:57
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:260
Point high
Definition: geo_decls.h:101

◆ 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:57
Point low
Definition: geo_decls.h:101
static bool float8_gt(const float8 val1, const float8 val2)
Definition: float.h:338
float8 y
Definition: geo_decls.h:57
Point high
Definition: geo_decls.h:101

◆ 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
static bool box_contain_box(BOX *contains_box, BOX *contained_box)
Definition: geo_ops.c:692
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ 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 }
float8 x
Definition: geo_decls.h:57
Point low
Definition: geo_decls.h:101
float8 y
Definition: geo_decls.h:57
Point high
Definition: geo_decls.h:101
#define FPge(A, B)
Definition: geo_decls.h:39
#define FPle(A, B)
Definition: geo_decls.h:37

◆ box_contain_lseg()

static bool box_contain_lseg ( BOX box,
LSEG lseg 
)
static

Definition at line 3266 of file geo_ops.c.

References box_contain_point(), and LSEG::p.

Referenced by on_sb().

3267 {
3268  return box_contain_point(box, &lseg->p[0]) &&
3269  box_contain_point(box, &lseg->p[1]);
3270 }
static bool box_contain_point(BOX *box, Point *point)
Definition: geo_ops.c:3179
Point p[2]
Definition: geo_decls.h:67

◆ box_contain_point()

static bool box_contain_point ( BOX box,
Point point 
)
static

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

3180 {
3181  return box->high.x >= point->x && box->low.x <= point->x &&
3182  box->high.y >= point->y && box->low.y <= point->y;
3183 }
float8 x
Definition: geo_decls.h:57
Point low
Definition: geo_decls.h:101
float8 y
Definition: geo_decls.h:57
Point high
Definition: geo_decls.h:101

◆ box_contain_pt()

Datum box_contain_pt ( PG_FUNCTION_ARGS  )

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

3196 {
3197  BOX *box = PG_GETARG_BOX_P(0);
3198  Point *pt = PG_GETARG_POINT_P(1);
3199 
3201 }
Definition: geo_decls.h:99
static bool box_contain_point(BOX *box, Point *point)
Definition: geo_ops.c:3179
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
static bool box_contain_box(BOX *contains_box, BOX *contained_box)
Definition: geo_ops.c:692
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
static void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: geo_ops.c:2095
Definition: geo_decls.h:65
#define PG_RETURN_LSEG_P(x)
Definition: geo_decls.h:142
Point low
Definition: geo_decls.h:101
Point high
Definition: geo_decls.h:101
void * palloc(Size size)
Definition: mcxt.c:949

◆ 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
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:1959

◆ box_div()

Datum box_div ( PG_FUNCTION_ARGS  )

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

4267 {
4268  BOX *box = PG_GETARG_BOX_P(0);
4269  Point *p = PG_GETARG_POINT_P(1);
4270  BOX *result;
4271  Point high,
4272  low;
4273 
4274  result = (BOX *) palloc(sizeof(BOX));
4275 
4276  point_div_point(&high, &box->high, p);
4277  point_div_point(&low, &box->low, p);
4278 
4279  box_construct(result, &high, &low);
4280 
4281  PG_RETURN_BOX_P(result);
4282 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
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:136
static void point_div_point(Point *result, Point *pt1, Point *pt2)
Definition: geo_ops.c:4168
Point low
Definition: geo_decls.h:101
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:159
Point high
Definition: geo_decls.h:101
void * palloc(Size size)
Definition: mcxt.c:949

◆ 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define FPeq(A, B)
Definition: geo_decls.h:34
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
static float8 box_ar(BOX *box)
Definition: geo_ops.c:851

◆ 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define FPge(A, B)
Definition: geo_decls.h:39
static float8 box_ar(BOX *box)
Definition: geo_ops.c:851

◆ 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define FPgt(A, B)
Definition: geo_decls.h:38
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
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:209
Point low
Definition: geo_decls.h:101
float8 y
Definition: geo_decls.h:57
Point high
Definition: geo_decls.h:101

◆ 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:99
float8 x
Definition: geo_decls.h:57
double float8
Definition: c.h:491
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:314
Point low
Definition: geo_decls.h:101
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:159
float8 y
Definition: geo_decls.h:57
Point high
Definition: geo_decls.h:101
void * palloc(Size size)
Definition: mcxt.c:949
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:272
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 3312 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().

3313 {
3314  BOX lbox;
3315  LSEG bseg;
3316  Point point;
3317 
3318  lbox.low.x = float8_min(lseg->p[0].x, lseg->p[1].x);
3319  lbox.low.y = float8_min(lseg->p[0].y, lseg->p[1].y);
3320  lbox.high.x = float8_max(lseg->p[0].x, lseg->p[1].x);
3321  lbox.high.y = float8_max(lseg->p[0].y, lseg->p[1].y);
3322 
3323  /* nothing close to overlap? then not going to intersect */
3324  if (!box_ov(&lbox, box))
3325  return false;
3326 
3327  if (result != NULL)
3328  {
3329  box_cn(&point, box);
3330  lseg_closept_point(result, lseg, &point);
3331  }
3332 
3333  /* an endpoint of segment is inside box? then clearly intersects */
3334  if (box_contain_point(box, &lseg->p[0]) ||
3335  box_contain_point(box, &lseg->p[1]))
3336  return true;
3337 
3338  /* pairwise check lseg intersections */
3339  point.x = box->low.x;
3340  point.y = box->high.y;
3341  statlseg_construct(&bseg, &box->low, &point);
3342  if (lseg_interpt_lseg(NULL, &bseg, lseg))
3343  return true;
3344 
3345  statlseg_construct(&bseg, &box->high, &point);
3346  if (lseg_interpt_lseg(NULL, &bseg, lseg))
3347  return true;
3348 
3349  point.x = box->high.x;
3350  point.y = box->low.y;
3351  statlseg_construct(&bseg, &box->low, &point);
3352  if (lseg_interpt_lseg(NULL, &bseg, lseg))
3353  return true;
3354 
3355  statlseg_construct(&bseg, &box->high, &point);
3356  if (lseg_interpt_lseg(NULL, &bseg, lseg))
3357  return true;
3358 
3359  /* if we dropped through, no two segs intersected */
3360  return false;
3361 }
Definition: geo_decls.h:99
static bool box_contain_point(BOX *box, Point *point)
Definition: geo_ops.c:3179
float8 x
Definition: geo_decls.h:57
static void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: geo_ops.c:2095
static float8 float8_min(const float8 val1, const float8 val2)
Definition: float.h:362
Definition: geo_decls.h:65
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:2763
Point low
Definition: geo_decls.h:101
static bool lseg_interpt_lseg(Point *result, LSEG *l1, LSEG *l2)
Definition: geo_ops.c:2291
float8 y
Definition: geo_decls.h:57
Point p[2]
Definition: geo_decls.h:67
Point high
Definition: geo_decls.h:101
static float8 float8_max(const float8 val1, const float8 val2)
Definition: float.h:374

◆ 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
float8 x
Definition: geo_decls.h:57
static float8 float8_min(const float8 val1, const float8 val2)
Definition: float.h:362
static bool box_ov(BOX *box1, BOX *box2)
Definition: geo_ops.c:560
Point low
Definition: geo_decls.h:101
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:159
float8 y
Definition: geo_decls.h:57
Point high
Definition: geo_decls.h:101
void * palloc(Size size)
Definition: mcxt.c:949
static float8 float8_max(const float8 val1, const float8 val2)
Definition: float.h:374
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ 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 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
static float8 box_ar(BOX *box)
Definition: geo_ops.c:851
#define FPle(A, B)
Definition: geo_decls.h:37

◆ 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
float8 x
Definition: geo_decls.h:57
Point low
Definition: geo_decls.h:101
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define FPlt(A, B)
Definition: geo_decls.h:36
Point high
Definition: geo_decls.h:101

◆ 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define FPlt(A, B)
Definition: geo_decls.h:36
static float8 box_ar(BOX *box)
Definition: geo_ops.c:851

◆ box_mul()

Datum box_mul ( PG_FUNCTION_ARGS  )

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

4248 {
4249  BOX *box = PG_GETARG_BOX_P(0);
4250  Point *p = PG_GETARG_POINT_P(1);
4251  BOX *result;
4252  Point high,
4253  low;
4254 
4255  result = (BOX *) palloc(sizeof(BOX));
4256 
4257  point_mul_point(&high, &box->high, p);
4258  point_mul_point(&low, &box->low, p);
4259 
4260  box_construct(result, &high, &low);
4261 
4262  PG_RETURN_BOX_P(result);
4263 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
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:4143
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
Point low
Definition: geo_decls.h:101
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:159
Point high
Definition: geo_decls.h:101
void * palloc(Size size)
Definition: mcxt.c:949

◆ 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:352
Point high
Definition: geo_decls.h:101
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 }
float8 x
Definition: geo_decls.h:57
Point low
Definition: geo_decls.h:101
float8 y
Definition: geo_decls.h:57
Point high
Definition: geo_decls.h:101
#define FPle(A, B)
Definition: geo_decls.h:37

◆ 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
Point low
Definition: geo_decls.h:101
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
float8 y
Definition: geo_decls.h:57
#define FPge(A, B)
Definition: geo_decls.h:39

◆ 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 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
float8 y
Definition: geo_decls.h:57
Point high
Definition: geo_decls.h:101
#define FPle(A, B)
Definition: geo_decls.h:37

◆ 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
static bool box_ov(BOX *box1, BOX *box2)
Definition: geo_ops.c:560
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ 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 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
float8 x
Definition: geo_decls.h:57
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
Point high
Definition: geo_decls.h:101
#define FPle(A, B)
Definition: geo_decls.h:37

◆ 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
float8 x
Definition: geo_decls.h:57
Point low
Definition: geo_decls.h:101
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define FPge(A, B)
Definition: geo_decls.h:39

◆ box_poly()

Datum box_poly ( PG_FUNCTION_ARGS  )

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

4536 {
4537  BOX *box = PG_GETARG_BOX_P(0);
4538  POLYGON *poly;
4539  int size;
4540 
4541  /* map four corners of the box to a polygon */
4542  size = offsetof(POLYGON, p) + sizeof(poly->p[0]) * 4;
4543  poly = (POLYGON *) palloc(size);
4544 
4545  SET_VARSIZE(poly, size);
4546  poly->npts = 4;
4547 
4548  poly->p[0].x = box->low.x;
4549  poly->p[0].y = box->low.y;
4550  poly->p[1].x = box->low.x;
4551  poly->p[1].y = box->high.y;
4552  poly->p[2].x = box->high.x;
4553  poly->p[2].y = box->high.y;
4554  poly->p[3].x = box->high.x;
4555  poly->p[3].y = box->low.y;
4556 
4557  box_construct(&poly->boundbox, &box->high, &box->low);
4558 
4559  PG_RETURN_POLYGON_P(poly);
4560 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
float8 x
Definition: geo_decls.h:57
static void box_construct(BOX *result, Point *pt1, Point *pt2)
Definition: geo_ops.c:506
int32 npts
Definition: geo_decls.h:113
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:115
Point low
Definition: geo_decls.h:101
BOX boundbox
Definition: geo_decls.h:114
float8 y
Definition: geo_decls.h:57
#define PG_RETURN_POLYGON_P(x)
Definition: geo_decls.h:166
Point high
Definition: geo_decls.h:101
void * palloc(Size size)
Definition: mcxt.c:949
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
#define offsetof(type, field)
Definition: c.h:655

◆ 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:99
float8 x
Definition: geo_decls.h:57
StringInfoData * StringInfo
Definition: stringinfo.h:43
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
double float8
Definition: c.h:491
static char * buf
Definition: pg_test_fsync.c:68
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:314
Point low
Definition: geo_decls.h:101
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:159
float8 pq_getmsgfloat8(StringInfo msg)
Definition: pqformat.c:490
float8 y
Definition: geo_decls.h:57
Point high
Definition: geo_decls.h:101
void * palloc(Size size)
Definition: mcxt.c:949

◆ 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
float8 x
Definition: geo_decls.h:57
#define FPgt(A, B)
Definition: geo_decls.h:38
Point low
Definition: geo_decls.h:101
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
Point high
Definition: geo_decls.h:101

◆ 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
static bool point_eq_point(Point *pt1, Point *pt2)
Definition: geo_ops.c:1938
Point low
Definition: geo_decls.h:101
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
Point high
Definition: geo_decls.h:101

◆ 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
float8 x
Definition: geo_decls.h:57
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:360
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static char * buf
Definition: pg_test_fsync.c:68
Point low
Definition: geo_decls.h:101
float8 y
Definition: geo_decls.h:57
Point high
Definition: geo_decls.h:101

◆ box_sub()

Datum box_sub ( PG_FUNCTION_ARGS  )

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

4233 {
4234  BOX *box = PG_GETARG_BOX_P(0);
4235  Point *p = PG_GETARG_POINT_P(1);
4236  BOX *result;
4237 
4238  result = (BOX *) palloc(sizeof(BOX));
4239 
4240  point_sub_point(&result->high, &box->high, p);
4241  point_sub_point(&result->low, &box->low, p);
4242 
4243  PG_RETURN_BOX_P(result);
4244 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
static void point_sub_point(Point *result, Point *pt1, Point *pt2)
Definition: geo_ops.c:4120
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
Point low
Definition: geo_decls.h:101
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:159
Point high
Definition: geo_decls.h:101
void * palloc(Size size)
Definition: mcxt.c:949

◆ 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:57
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:209
Point low
Definition: geo_decls.h:101
Point high
Definition: geo_decls.h:101

◆ 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:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
static float8 box_wd(BOX *box)
Definition: geo_ops.c:871

◆ boxes_bound_box()

Datum boxes_bound_box ( PG_FUNCTION_ARGS  )

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

4308 {
4309  BOX *box1 = PG_GETARG_BOX_P(0),
4310  *box2 = PG_GETARG_BOX_P(1),
4311  *container;
4312 
4313  container = (BOX *) palloc(sizeof(BOX));
4314 
4315  container->high.x = float8_max(box1->high.x, box2->high.x);
4316  container->low.x = float8_min(box1->low.x, box2->low.x);
4317  container->high.y = float8_max(box1->high.y, box2->high.y);
4318  container->low.y = float8_min(box1->low.y, box2->low.y);
4319 
4320  PG_RETURN_BOX_P(container);
4321 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
float8 x
Definition: geo_decls.h:57
static float8 float8_min(const float8 val1, const float8 val2)
Definition: float.h:362
Point low
Definition: geo_decls.h:101
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:159
float8 y
Definition: geo_decls.h:57
Point high
Definition: geo_decls.h:101
void * palloc(Size size)
Definition: mcxt.c:949
static float8 float8_max(const float8 val1, const float8 val2)
Definition: float.h:374

◆ circle_above()

Datum circle_above ( PG_FUNCTION_ARGS  )

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

4856 {
4857  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4858  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4859 
4860  PG_RETURN_BOOL(FPgt(float8_mi(circle1->center.y, circle1->radius),
4861  float8_pl(circle2->center.y, circle2->radius)));
4862 }
float8 radius
Definition: geo_decls.h:124
#define FPgt(A, B)
Definition: geo_decls.h:38
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:187
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:209
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
float8 y
Definition: geo_decls.h:57
Point center
Definition: geo_decls.h:123

◆ circle_add_pt()

Datum circle_add_pt ( PG_FUNCTION_ARGS  )

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

4958 {
4959  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4960  Point *point = PG_GETARG_POINT_P(1);
4961  CIRCLE *result;
4962 
4963  result = (CIRCLE *) palloc(sizeof(CIRCLE));
4964 
4965  point_add_point(&result->center, &circle->center, point);
4966  result->radius = circle->radius;
4967 
4968  PG_RETURN_CIRCLE_P(result);
4969 }
float8 radius
Definition: geo_decls.h:124
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:171
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
static void point_add_point(Point *result, Point *pt1, Point *pt2)
Definition: geo_ops.c:4097
Point center
Definition: geo_decls.h:123
void * palloc(Size size)
Definition: mcxt.c:949

◆ circle_ar()

static float8 circle_ar ( CIRCLE circle)
static

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

5152 {
5153  return float8_mul(float8_mul(circle->radius, circle->radius), M_PI);
5154 }
float8 radius
Definition: geo_decls.h:124
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:232
#define M_PI
Definition: earthdistance.c:10

◆ circle_area()

Datum circle_area ( PG_FUNCTION_ARGS  )

Definition at line 5024 of file geo_ops.c.

References circle_ar(), PG_GETARG_CIRCLE_P, and PG_RETURN_FLOAT8.

5025 {
5026  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5027 
5028  PG_RETURN_FLOAT8(circle_ar(circle));
5029 }
static float8 circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5151
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170

◆ circle_below()

Datum circle_below ( PG_FUNCTION_ARGS  )

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

4844 {
4845  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4846  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4847 
4848  PG_RETURN_BOOL(FPlt(float8_pl(circle1->center.y, circle1->radius),
4849  float8_mi(circle2->center.y, circle2->radius)));
4850 }
float8 radius
Definition: geo_decls.h:124
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:187
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:209
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
#define FPlt(A, B)
Definition: geo_decls.h:36
float8 y
Definition: geo_decls.h:57
Point center
Definition: geo_decls.h:123

◆ circle_box()

Datum circle_box ( PG_FUNCTION_ARGS  )

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

5179 {
5180  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5181  BOX *box;
5182  float8 delta;
5183 
5184  box = (BOX *) palloc(sizeof(BOX));
5185 
5186  delta = float8_div(circle->radius, sqrt(2.0));
5187 
5188  box->high.x = float8_pl(circle->center.x, delta);
5189  box->low.x = float8_mi(circle->center.x, delta);
5190  box->high.y = float8_pl(circle->center.y, delta);
5191  box->low.y = float8_mi(circle->center.y, delta);
5192 
5193  PG_RETURN_BOX_P(box);
5194 }
Definition: geo_decls.h:99
float8 x
Definition: geo_decls.h:57
float8 radius
Definition: geo_decls.h:124
double float8
Definition: c.h:491
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:187
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:209
Point low
Definition: geo_decls.h:101
#define PG_RETURN_BOX_P(x)
Definition: geo_decls.h:159
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
float8 y
Definition: geo_decls.h:57
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:260
Point high
Definition: geo_decls.h:101
Point center
Definition: geo_decls.h:123
void * palloc(Size size)
Definition: mcxt.c:949

◆ circle_center()

Datum circle_center ( PG_FUNCTION_ARGS  )

Definition at line 5135 of file geo_ops.c.

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

5136 {
5137  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5138  Point *result;
5139 
5140  result = (Point *) palloc(sizeof(Point));
5141  result->x = circle->center.x;
5142  result->y = circle->center.y;
5143 
5144  PG_RETURN_POINT_P(result);
5145 }
float8 x
Definition: geo_decls.h:57
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:137
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
float8 y
Definition: geo_decls.h:57
Point center
Definition: geo_decls.h:123
void * palloc(Size size)
Definition: mcxt.c:949

◆ circle_contain()

Datum circle_contain ( PG_FUNCTION_ARGS  )

Definition at line 4830 of file geo_ops.c.

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

4831 {
4832  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4833  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4834 
4835  PG_RETURN_BOOL(FPle(point_dt(&circle1->center, &circle2->center),
4836  float8_mi(circle1->radius, circle2->radius)));
4837 }
float8 radius
Definition: geo_decls.h:124
static float8 point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1959
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:209
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
Point center
Definition: geo_decls.h:123
#define FPle(A, B)
Definition: geo_decls.h:37

◆ circle_contain_pt()

Datum circle_contain_pt ( PG_FUNCTION_ARGS  )

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

5075 {
5076  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5077  Point *point = PG_GETARG_POINT_P(1);
5078  float8 d;
5079 
5080  d = point_dt(&circle->center, point);
5081  PG_RETURN_BOOL(d <= circle->radius);
5082 }
static float8 point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1959
double float8
Definition: c.h:491
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
Point center
Definition: geo_decls.h:123

◆ circle_contained()

Datum circle_contained ( PG_FUNCTION_ARGS  )

Definition at line 4818 of file geo_ops.c.

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

4819 {
4820  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4821  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4822 
4823  PG_RETURN_BOOL(FPle(point_dt(&circle1->center, &circle2->center),
4824  float8_mi(circle2->radius, circle1->radius)));
4825 }
float8 radius
Definition: geo_decls.h:124
static float8 point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1959
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:209
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
Point center
Definition: geo_decls.h:123
#define FPle(A, B)
Definition: geo_decls.h:37

◆ circle_diameter()

Datum circle_diameter ( PG_FUNCTION_ARGS  )

Definition at line 5035 of file geo_ops.c.

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

5036 {
5037  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5038 
5039  PG_RETURN_FLOAT8(float8_mul(circle->radius, 2.0));
5040 }
float8 radius
Definition: geo_decls.h:124
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:232
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170

◆ circle_distance()

Datum circle_distance ( PG_FUNCTION_ARGS  )

Definition at line 5058 of file geo_ops.c.

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

5059 {
5060  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
5061  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
5062  float8 result;
5063 
5064  result = float8_mi(point_dt(&circle1->center, &circle2->center),
5065  float8_pl(circle1->radius, circle2->radius));
5066  if (result < 0.0)
5067  result = 0.0;
5068 
5069  PG_RETURN_FLOAT8(result);
5070 }
float8 radius
Definition: geo_decls.h:124
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
static float8 point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1959
double float8
Definition: c.h:491
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:187
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:209
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
Point center
Definition: geo_decls.h:123

◆ circle_div_pt()

Datum circle_div_pt ( PG_FUNCTION_ARGS  )

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

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_div_point(&result->center, &circle->center, point);
5015  result->radius = float8_div(circle->radius, HYPOT(point->x, point->y));
5016 
5017  PG_RETURN_CIRCLE_P(result);
5018 }
float8 x
Definition: geo_decls.h:57
float8 radius
Definition: geo_decls.h:124
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
static void point_div_point(Point *result, Point *pt1, Point *pt2)
Definition: geo_ops.c:4168
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:171
#define HYPOT(A, B)
Definition: geo_decls.h:50
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
float8 y
Definition: geo_decls.h:57
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:260
Point center
Definition: geo_decls.h:123
void * palloc(Size size)
Definition: mcxt.c:949

◆ circle_eq()

Datum circle_eq ( PG_FUNCTION_ARGS  )

Definition at line 4895 of file geo_ops.c.

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

4896 {
4897  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4898  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4899 
4900  PG_RETURN_BOOL(FPeq(circle_ar(circle1), circle_ar(circle2)));
4901 }
static float8 circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5151
#define FPeq(A, B)
Definition: geo_decls.h:34
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170

◆ circle_ge()

Datum circle_ge ( PG_FUNCTION_ARGS  )

Definition at line 4940 of file geo_ops.c.

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

4941 {
4942  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4943  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4944 
4945  PG_RETURN_BOOL(FPge(circle_ar(circle1), circle_ar(circle2)));
4946 }
static float8 circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5151
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
#define FPge(A, B)
Definition: geo_decls.h:39

◆ circle_gt()

Datum circle_gt ( PG_FUNCTION_ARGS  )

Definition at line 4922 of file geo_ops.c.

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

4923 {
4924  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4925  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4926 
4927  PG_RETURN_BOOL(FPgt(circle_ar(circle1), circle_ar(circle2)));
4928 }
static float8 circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5151
#define FPgt(A, B)
Definition: geo_decls.h:38
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170

◆ circle_in()

Datum circle_in ( PG_FUNCTION_ARGS  )

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

4612 {
4613  char *str = PG_GETARG_CSTRING(0);
4614  CIRCLE *circle = (CIRCLE *) palloc(sizeof(CIRCLE));
4615  char *s,
4616  *cp;
4617  int depth = 0;
4618 
4619  s = str;
4620  while (isspace((unsigned char) *s))
4621  s++;
4622  if ((*s == LDELIM_C) || (*s == LDELIM))
4623  {
4624  depth++;
4625  cp = (s + 1);
4626  while (isspace((unsigned char) *cp))
4627  cp++;
4628  if (*cp == LDELIM)
4629  s = cp;
4630  }
4631 
4632  pair_decode(s, &circle->center.x, &circle->center.y, &s, "circle", str);
4633 
4634  if (*s == DELIM)
4635  s++;
4636 
4637  circle->radius = single_decode(s, &s, "circle", str);
4638  /* We have to accept NaN. */
4639  if (circle->radius < 0.0)
4640  ereport(ERROR,
4641  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
4642  errmsg("invalid input syntax for type %s: \"%s\"",
4643  "circle", str)));
4644 
4645  while (depth > 0)
4646  {
4647  if ((*s == RDELIM) || ((*s == RDELIM_C) && (depth == 1)))
4648  {
4649  depth--;
4650  s++;
4651  while (isspace((unsigned char) *s))
4652  s++;
4653  }
4654  else
4655  ereport(ERROR,
4656  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
4657  errmsg("invalid input syntax for type %s: \"%s\"",
4658  "circle", str)));
4659  }
4660 
4661  if (*s != '\0')
4662  ereport(ERROR,
4663  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
4664  errmsg("invalid input syntax for type %s: \"%s\"",
4665  "circle", str)));
4666 
4667  PG_RETURN_CIRCLE_P(circle);
4668 }
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:57
float8 radius
Definition: geo_decls.h:124
int errcode(int sqlerrcode)
Definition: elog.c:570
#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 ereport(elevel, rest)
Definition: elog.h:141
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:171
float8 y
Definition: geo_decls.h:57
#define LDELIM_C
Definition: geo_ops.c:157
Point center
Definition: geo_decls.h:123
#define RDELIM_C
Definition: geo_ops.c:158
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:272
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 4931 of file geo_ops.c.

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

4932 {
4933  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4934  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4935 
4936  PG_RETURN_BOOL(FPle(circle_ar(circle1), circle_ar(circle2)));
4937 }
static float8 circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5151
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
#define FPle(A, B)
Definition: geo_decls.h:37

◆ circle_left()

Datum circle_left ( PG_FUNCTION_ARGS  )

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

4782 {
4783  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4784  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4785 
4786  PG_RETURN_BOOL(FPlt(float8_pl(circle1->center.x, circle1->radius),
4787  float8_mi(circle2->center.x, circle2->radius)));
4788 }
float8 x
Definition: geo_decls.h:57
float8 radius
Definition: geo_decls.h:124
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:187
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:209
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
#define FPlt(A, B)
Definition: geo_decls.h:36
Point center
Definition: geo_decls.h:123

◆ circle_lt()

Datum circle_lt ( PG_FUNCTION_ARGS  )

Definition at line 4913 of file geo_ops.c.

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

4914 {
4915  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4916  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4917 
4918  PG_RETURN_BOOL(FPlt(circle_ar(circle1), circle_ar(circle2)));
4919 }
static float8 circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5151
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
#define FPlt(A, B)
Definition: geo_decls.h:36

◆ circle_mul_pt()

Datum circle_mul_pt ( PG_FUNCTION_ARGS  )

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

4992 {
4993  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4994  Point *point = PG_GETARG_POINT_P(1);
4995  CIRCLE *result;
4996 
4997  result = (CIRCLE *) palloc(sizeof(CIRCLE));
4998 
4999  point_mul_point(&result->center, &circle->center, point);
5000  result->radius = float8_mul(circle->radius, HYPOT(point->x, point->y));
5001 
5002  PG_RETURN_CIRCLE_P(result);
5003 }
float8 x
Definition: geo_decls.h:57
float8 radius
Definition: geo_decls.h:124
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:232
static void point_mul_point(Point *result, Point *pt1, Point *pt2)
Definition: geo_ops.c:4143
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:171
#define HYPOT(A, B)
Definition: geo_decls.h:50
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
float8 y
Definition: geo_decls.h:57
Point center
Definition: geo_decls.h:123
void * palloc(Size size)
Definition: mcxt.c:949

◆ circle_ne()

Datum circle_ne ( PG_FUNCTION_ARGS  )

Definition at line 4904 of file geo_ops.c.

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

4905 {
4906  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4907  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4908 
4909  PG_RETURN_BOOL(FPne(circle_ar(circle1), circle_ar(circle2)));
4910 }
static float8 circle_ar(CIRCLE *circle)
Definition: geo_ops.c:5151
#define FPne(A, B)
Definition: geo_decls.h:35
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170

◆ circle_out()

Datum circle_out ( PG_FUNCTION_ARGS  )

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

4674 {
4675  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4677 
4678  initStringInfo(&str);
4679 
4682  pair_encode(circle->center.x, circle->center.y, &str);
4684  appendStringInfoChar(&str, DELIM);
4685  single_encode(circle->radius, &str);
4687 
4688  PG_RETURN_CSTRING(str.data);
4689 }
float8 x
Definition: geo_decls.h:57
float8 radius
Definition: geo_decls.h:124
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:175
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
float8 y
Definition: geo_decls.h:57
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:352
#define LDELIM_C
Definition: geo_ops.c:157
Point center
Definition: geo_decls.h:123
#define RDELIM_C
Definition: geo_ops.c:158

◆ circle_overabove()

Datum circle_overabove ( PG_FUNCTION_ARGS  )

Definition at line 4881 of file geo_ops.c.

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

4882 {
4883  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4884  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4885 
4886  PG_RETURN_BOOL(FPge(float8_mi(circle1->center.y, circle1->radius),
4887  float8_mi(circle2->center.y, circle2->radius)));
4888 }
float8 radius
Definition: geo_decls.h:124
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:209
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
float8 y
Definition: geo_decls.h:57
Point center
Definition: geo_decls.h:123
#define FPge(A, B)
Definition: geo_decls.h:39

◆ circle_overbelow()

Datum circle_overbelow ( PG_FUNCTION_ARGS  )

Definition at line 4868 of file geo_ops.c.

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

4869 {
4870  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4871  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4872 
4873  PG_RETURN_BOOL(FPle(float8_pl(circle1->center.y, circle1->radius),
4874  float8_pl(circle2->center.y, circle2->radius)));
4875 }
float8 radius
Definition: geo_decls.h:124
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:187
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
float8 y
Definition: geo_decls.h:57
Point center
Definition: geo_decls.h:123
#define FPle(A, B)
Definition: geo_decls.h:37

◆ circle_overlap()

Datum circle_overlap ( PG_FUNCTION_ARGS  )

Definition at line 4756 of file geo_ops.c.

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

4757 {
4758  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4759  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4760 
4761  PG_RETURN_BOOL(FPle(point_dt(&circle1->center, &circle2->center),
4762  float8_pl(circle1->radius, circle2->radius)));
4763 }
float8 radius
Definition: geo_decls.h:124
static float8 point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1959
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:187
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
Point center
Definition: geo_decls.h:123
#define FPle(A, B)
Definition: geo_decls.h:37

◆ circle_overleft()

Datum circle_overleft ( PG_FUNCTION_ARGS  )

Definition at line 4769 of file geo_ops.c.

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

4770 {
4771  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4772  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4773 
4774  PG_RETURN_BOOL(FPle(float8_pl(circle1->center.x, circle1->radius),
4775  float8_pl(circle2->center.x, circle2->radius)));
4776 }
float8 x
Definition: geo_decls.h:57
float8 radius
Definition: geo_decls.h:124
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:187
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
Point center
Definition: geo_decls.h:123
#define FPle(A, B)
Definition: geo_decls.h:37

◆ circle_overright()

Datum circle_overright ( PG_FUNCTION_ARGS  )

Definition at line 4806 of file geo_ops.c.

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

4807 {
4808  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4809  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4810 
4811  PG_RETURN_BOOL(FPge(float8_mi(circle1->center.x, circle1->radius),
4812  float8_mi(circle2->center.x, circle2->radius)));
4813 }
float8 x
Definition: geo_decls.h:57
float8 radius
Definition: geo_decls.h:124
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:209
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
Point center
Definition: geo_decls.h:123
#define FPge(A, B)
Definition: geo_decls.h:39

◆ circle_poly()

Datum circle_poly ( PG_FUNCTION_ARGS  )

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

5218 {
5219  int32 npts = PG_GETARG_INT32(0);
5220  CIRCLE *circle = PG_GETARG_CIRCLE_P(1);
5221  POLYGON *poly;
5222  int base_size,
5223  size;
5224  int i;
5225  float8 angle;
5226  float8 anglestep;
5227 
5228  if (FPzero(circle->radius))
5229  ereport(ERROR,
5230  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5231  errmsg("cannot convert circle with radius zero to polygon")));
5232 
5233  if (npts < 2)
5234  ereport(ERROR,
5235  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
5236  errmsg("must request at least 2 points")));
5237 
5238  base_size = sizeof(poly->p[0]) * npts;
5239  size = offsetof(POLYGON, p) + base_size;
5240 
5241  /* Check for integer overflow */
5242  if (base_size / npts != sizeof(poly->p[0]) || size <= base_size)
5243  ereport(ERROR,
5244  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
5245  errmsg("too many points requested")));
5246 
5247  poly = (POLYGON *) palloc0(size); /* zero any holes */
5248  SET_VARSIZE(poly, size);
5249  poly->npts = npts;
5250 
5251  anglestep = float8_div(2.0 * M_PI, npts);
5252 
5253  for (i = 0; i < npts; i++)
5254  {
5255  angle = float8_mul(anglestep, i);
5256 
5257  poly->p[i].x = float8_mi(circle->center.x,
5258  float8_mul(circle->radius, cos(angle)));
5259  poly->p[i].y = float8_pl(circle->center.y,
5260  float8_mul(circle->radius, sin(angle)));
5261  }
5262 
5263  make_bound_box(poly);
5264 
5265  PG_RETURN_POLYGON_P(poly);
5266 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define FPzero(A)
Definition: geo_decls.h:33
float8 x
Definition: geo_decls.h:57
float8 radius
Definition: geo_decls.h:124
int errcode(int sqlerrcode)
Definition: elog.c:570
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:232
int32 npts
Definition: geo_decls.h:113
signed int int32
Definition: c.h:346
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:491
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:187
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:115
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:209
#define ereport(elevel, rest)
Definition: elog.h:141
void * palloc0(Size size)
Definition: mcxt.c:980
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
static void make_bound_box(POLYGON *poly)
Definition: geo_ops.c:3425
float8 y
Definition: geo_decls.h:57
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:260
#define PG_RETURN_POLYGON_P(x)
Definition: geo_decls.h:166
Point center
Definition: geo_decls.h:123
int errmsg(const char *fmt,...)
Definition: elog.c:784
int i
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
#define offsetof(type, field)
Definition: c.h:655
#define M_PI
Definition: earthdistance.c:10

◆ circle_radius()

Datum circle_radius ( PG_FUNCTION_ARGS  )

Definition at line 5046 of file geo_ops.c.

References PG_GETARG_CIRCLE_P, PG_RETURN_FLOAT8, and CIRCLE::radius.

5047 {
5048  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5049 
5050  PG_RETURN_FLOAT8(circle->radius);
5051 }
float8 radius
Definition: geo_decls.h:124
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170

◆ circle_recv()

Datum circle_recv ( PG_FUNCTION_ARGS  )

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

4696 {
4698  CIRCLE *circle;
4699 
4700  circle = (CIRCLE *) palloc(sizeof(CIRCLE));
4701 
4702  circle->center.x = pq_getmsgfloat8(buf);
4703  circle->center.y = pq_getmsgfloat8(buf);
4704  circle->radius = pq_getmsgfloat8(buf);
4705 
4706  /* We have to accept NaN. */
4707  if (circle->radius < 0.0)
4708  ereport(ERROR,
4709  (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
4710  errmsg("invalid radius in external \"circle\" value")));
4711 
4712  PG_RETURN_CIRCLE_P(circle);
4713 }
float8 x
Definition: geo_decls.h:57
float8 radius
Definition: geo_decls.h:124
StringInfoData * StringInfo
Definition: stringinfo.h:43
int errcode(int sqlerrcode)
Definition: elog.c:570
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
#define ERROR
Definition: elog.h:43
static char * buf
Definition: pg_test_fsync.c:68
#define ereport(elevel, rest)
Definition: elog.h:141
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:171
float8 pq_getmsgfloat8(StringInfo msg)
Definition: pqformat.c:490
float8 y
Definition: geo_decls.h:57
Point center
Definition: geo_decls.h:123
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ circle_right()

Datum circle_right ( PG_FUNCTION_ARGS  )

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

4794 {
4795  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4796  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4797 
4798  PG_RETURN_BOOL(FPgt(float8_mi(circle1->center.x, circle1->radius),
4799  float8_pl(circle2->center.x, circle2->radius)));
4800 }
float8 x
Definition: geo_decls.h:57
float8 radius
Definition: geo_decls.h:124
#define FPgt(A, B)
Definition: geo_decls.h:38
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:187
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:209
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
Point center
Definition: geo_decls.h:123

◆ circle_same()

Datum circle_same ( PG_FUNCTION_ARGS  )

Definition at line 4743 of file geo_ops.c.

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

4744 {
4745  CIRCLE *circle1 = PG_GETARG_CIRCLE_P(0);
4746  CIRCLE *circle2 = PG_GETARG_CIRCLE_P(1);
4747 
4748  PG_RETURN_BOOL(((isnan(circle1->radius) && isnan(circle1->radius)) ||
4749  FPeq(circle1->radius, circle2->radius)) &&
4750  point_eq_point(&circle1->center, &circle2->center));
4751 }
float8 radius
Definition: geo_decls.h:124
static bool point_eq_point(Point *pt1, Point *pt2)
Definition: geo_ops.c:1938
#define FPeq(A, B)
Definition: geo_decls.h:34
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
Point center
Definition: geo_decls.h:123

◆ circle_send()

Datum circle_send ( PG_FUNCTION_ARGS  )

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

4720 {
4721  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
4723 
4724  pq_begintypsend(&buf);
4725  pq_sendfloat8(&buf, circle->center.x);
4726  pq_sendfloat8(&buf, circle->center.y);
4727  pq_sendfloat8(&buf, circle->radius);
4729 }
float8 x
Definition: geo_decls.h:57
float8 radius
Definition: geo_decls.h:124
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:360
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:170
float8 y
Definition: geo_decls.h:57
Point center
Definition: geo_decls.h:123

◆ circle_sub_pt()

Datum circle_sub_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_sub_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_sub_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:124
static void point_sub_point(Point *result, Point *pt1, Point *pt2)
Definition: geo_ops.c:4120
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:171
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
Point center
Definition: geo_decls.h:123
void * palloc(Size size)
Definition: mcxt.c:949

◆ close_lb()

Datum close_lb ( PG_FUNCTION_ARGS  )

Definition at line 3112 of file geo_ops.c.

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

3113 {
3114 #ifdef NOT_USED
3115  LINE *line = PG_GETARG_LINE_P(0);
3116  BOX *box = PG_GETARG_BOX_P(1);
3117 #endif
3118 
3119  /* think about this one for a while */
3120  ereport(ERROR,
3121  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3122  errmsg("function \"close_lb\" not implemented")));
3123 
3124  PG_RETURN_NULL();
3125 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
int errcode(int sqlerrcode)
Definition: elog.c:570
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:153
#define ERROR
Definition: elog.h:43
Definition: geo_decls.h:87
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ close_ls()

Datum close_ls ( PG_FUNCTION_ARGS  )

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

3022 {
3023  LINE *line = PG_GETARG_LINE_P(0);
3024  LSEG *lseg = PG_GETARG_LSEG_P(1);
3025  Point *result;
3026 
3027  if (lseg_sl(lseg) == line_sl(line))
3028  PG_RETURN_NULL();
3029 
3030  result = (Point *) palloc(sizeof(Point));
3031 
3032  if (isnan(lseg_closept_line(result, lseg, line)))
3033  PG_RETURN_NULL();
3034 
3035  PG_RETURN_POINT_P(result);
3036 }
static float8 lseg_closept_line(Point *result, LSEG *lseg, LINE *line)
Definition: geo_ops.c:2993
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:141
static float8 lseg_sl(LSEG *lseg)
Definition: geo_ops.c:2108
Definition: geo_decls.h:65
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:153
Definition: geo_decls.h:87
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:137
void * palloc(Size size)
Definition: mcxt.c:949
static float8 line_sl(LINE *line)
Definition: geo_ops.c:1195
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ close_lseg()

Datum close_lseg ( PG_FUNCTION_ARGS  )

Definition at line 2844 of file geo_ops.c.

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

2845 {
2846  LSEG *l1 = PG_GETARG_LSEG_P(0);
2847  LSEG *l2 = PG_GETARG_LSEG_P(1);
2848  Point *result;
2849 
2850  if (lseg_sl(l1) == lseg_sl(l2))
2851  PG_RETURN_NULL();
2852 
2853  result = (Point *) palloc(sizeof(Point));
2854 
2855  if (isnan(lseg_closept_lseg(result, l2, l1)))
2856  PG_RETURN_NULL();
2857 
2858  PG_RETURN_POINT_P(result);
2859 }
static float8 lseg_closept_lseg(Point *result, LSEG *on_lseg, LSEG *to_lseg)
Definition: geo_ops.c:2801
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:141
static float8 lseg_sl(LSEG *lseg)
Definition: geo_ops.c:2108
Definition: geo_decls.h:65
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:137
void * palloc(Size size)
Definition: mcxt.c:949
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ close_pb()

Datum close_pb ( PG_FUNCTION_ARGS  )

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

2925 {
2926  Point *pt = PG_GETARG_POINT_P(0);
2927  BOX *box = PG_GETARG_BOX_P(1);
2928  Point *result;
2929 
2930  result = (Point *) palloc(sizeof(Point));
2931 
2932  if (isnan(box_closept_point(result, box, pt)))
2933  PG_RETURN_NULL();
2934 
2935  PG_RETURN_POINT_P(result);
2936 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:137
static float8 box_closept_point(Point *result, BOX *box, Point *point)
Definition: geo_ops.c:2869
void * palloc(Size size)
Definition: mcxt.c:949
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ close_pl()

Datum close_pl ( PG_FUNCTION_ARGS  )

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

2742 {
2743  Point *pt = PG_GETARG_POINT_P(0);
2744  LINE *line = PG_GETARG_LINE_P(1);
2745  Point *result;
2746 
2747  result = (Point *) palloc(sizeof(Point));
2748 
2749  if (isnan(line_closept_point(result, line, pt)))
2750  PG_RETURN_NULL();
2751 
2752  PG_RETURN_POINT_P(result);
2753 }
static float8 line_closept_point(Point *result, LINE *line, Point *pt)
Definition: geo_ops.c:2715
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:153
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
Definition: geo_decls.h:87
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:137
void * palloc(Size size)
Definition: mcxt.c:949
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ close_ps()

Datum close_ps ( PG_FUNCTION_ARGS  )

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

2783 {
2784  Point *pt = PG_GETARG_POINT_P(0);
2785  LSEG *lseg = PG_GETARG_LSEG_P(1);
2786  Point *result;
2787 
2788  result = (Point *) palloc(sizeof(Point));
2789 
2790  if (isnan(lseg_closept_point(result, lseg, pt)))
2791  PG_RETURN_NULL();
2792 
2793  PG_RETURN_POINT_P(result);
2794 }
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:141
Definition: geo_decls.h:65
static float8 lseg_closept_point(Point *result, LSEG *lseg, Point *pt)
Definition: geo_ops.c:2763
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:137
void * palloc(Size size)
Definition: mcxt.c:949
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ close_sb()

Datum close_sb ( PG_FUNCTION_ARGS  )

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

3097 {
3098  LSEG *lseg = PG_GETARG_LSEG_P(0);
3099  BOX *box = PG_GETARG_BOX_P(1);
3100  Point *result;
3101 
3102  result = (Point *) palloc(sizeof(Point));
3103 
3104  if (isnan(box_closept_lseg(result, box, lseg)))
3105  PG_RETURN_NULL();
3106 
3107  PG_RETURN_POINT_P(result);
3108 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:141
Definition: geo_decls.h:65
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:137
void * palloc(Size size)
Definition: mcxt.c:949
static float8 box_closept_lseg(Point *result, BOX *box, LSEG *lseg)
Definition: geo_ops.c:3046
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ close_sl()

Datum close_sl ( PG_FUNCTION_ARGS  )

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

2950 {
2951 #ifdef NOT_USED
2952  LSEG *lseg = PG_GETARG_LSEG_P(0);
2953  LINE *line = PG_GETARG_LINE_P(1);
2954  Point *result;
2955  float8 d1,
2956  d2;
2957 
2958  result = (Point *) palloc(sizeof(Point));
2959 
2960  if (lseg_interpt_line(result, lseg, line))
2961  PG_RETURN_POINT_P(result);
2962 
2963  d1 = line_closept_point(NULL, line, &lseg->p[0]);
2964  d2 = line_closept_point(NULL, line, &lseg->p[1]);
2965  if (float8_lt(d1, d2))
2966  *result = lseg->p[0];
2967  else
2968  *result = lseg->p[1];
2969 
2970  PG_RETURN_POINT_P(result);
2971 #endif
2972 
2973  ereport(ERROR,
2974  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2975  errmsg("function \"close_sl\" not implemented")));
2976 
2977  PG_RETURN_NULL();
2978 }
static bool lseg_interpt_line(Point *result, LSEG *lseg, LINE *line)
Definition: geo_ops.c:2666
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:141
Definition: geo_decls.h:65
int errcode(int sqlerrcode)
Definition: elog.c:570
static float8 line_closept_point(Point *result, LINE *line, Point *pt)
Definition: geo_ops.c:2715
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:153
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:491
Definition: geo_decls.h:87
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:137
#define ereport(elevel, rest)
Definition: elog.h:141
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:314
Point p[2]
Definition: geo_decls.h:67
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ construct_point()

Datum construct_point ( PG_FUNCTION_ARGS  )

Definition at line 4082 of file geo_ops.c.

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

4083 {
4084  float8 x = PG_GETARG_FLOAT8(0);
4085  float8 y = PG_GETARG_FLOAT8(1);
4086  Point *result;
4087 
4088  result = (Point *) palloc(sizeof(Point));
4089 
4090  point_construct(result, x, y);
4091 
4092  PG_RETURN_POINT_P(result);
4093 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:276
static void point_construct(Point *result, float8 x, float8 y)
Definition: geo_ops.c:1842
double float8
Definition: c.h:491
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:137
void * palloc(Size size)
Definition: mcxt.c:949

◆ cr_circle()

Datum cr_circle ( PG_FUNCTION_ARGS  )

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

5163 {
5164  Point *center = PG_GETARG_POINT_P(0);
5165  float8 radius = PG_GETARG_FLOAT8(1);
5166  CIRCLE *result;
5167 
5168  result = (CIRCLE *) palloc(sizeof(CIRCLE));
5169 
5170  result->center.x = center->x;
5171  result->center.y = center->y;
5172  result->radius = radius;
5173 
5174  PG_RETURN_CIRCLE_P(result);
5175 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:276
float8 x
Definition: geo_decls.h:57
float8 radius
Definition: geo_decls.h:124
double float8
Definition: c.h:491
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
#define PG_RETURN_CIRCLE_P(x)
Definition: geo_decls.h:171
float8 y
Definition: geo_decls.h:57
Point center
Definition: geo_decls.h:123
void * palloc(Size size)
Definition: mcxt.c:949

◆ dist_bl()

Datum dist_bl ( PG_FUNCTION_ARGS  )

Definition at line 2546 of file geo_ops.c.

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

2547 {
2548 #ifdef NOT_USED
2549  BOX *box = PG_GETARG_BOX_P(0);
2550  LINE *line = PG_GETARG_LINE_P(1);
2551 #endif
2552 
2553  /* need to think about this one for a while */
2554  ereport(ERROR,
2555  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2556  errmsg("function \"dist_bl\" not implemented")));
2557 
2558  PG_RETURN_NULL();
2559 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
int errcode(int sqlerrcode)
Definition: elog.c:570
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:153
#define ERROR
Definition: elog.h:43
Definition: geo_decls.h:87
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ dist_bp()

Datum dist_bp ( 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  BOX *box = PG_GETARG_BOX_P(0);
2470  Point *pt = PG_GETARG_POINT_P(1);
2471 
2472  PG_RETURN_FLOAT8(box_closept_point(NULL, box, pt));
2473 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
static float8 box_closept_point(Point *result, BOX *box, Point *point)
Definition: geo_ops.c:2869

◆ dist_bs()

Datum dist_bs ( 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  BOX *box = PG_GETARG_BOX_P(0);
2518  LSEG *lseg = PG_GETARG_LSEG_P(1);
2519 
2520  PG_RETURN_FLOAT8(box_closept_lseg(NULL, box, lseg));
2521 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:141
Definition: geo_decls.h:65
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
static float8 box_closept_lseg(Point *result, BOX *box, LSEG *lseg)
Definition: geo_ops.c:3046

◆ dist_cpoint()

Datum dist_cpoint ( PG_FUNCTION_ARGS  )

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

5120 {
5121  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
5122  Point *point = PG_GETARG_POINT_P(1);
5123  float8 result;
5124 
5125  result = float8_mi(point_dt(point, &circle->center), circle->radius);
5126  if (result < 0.0)
5127  result = 0.0;
5128 
5129  PG_RETURN_FLOAT8(result);
5130 }
float8 radius
Definition: geo_decls.h:124
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
static float8 point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1959
double float8
Definition: c.h:491
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:209
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
Point center
Definition: geo_decls.h:123

◆ dist_cpoly()

Datum dist_cpoly ( PG_FUNCTION_ARGS  )

Definition at line 2579 of file geo_ops.c.

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

2580 {
2581  CIRCLE *circle = PG_GETARG_CIRCLE_P(0);
2582  POLYGON *poly = PG_GETARG_POLYGON_P(1);
2583 
2584  PG_RETURN_FLOAT8(dist_cpoly_internal(circle, poly));
2585 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
#define PG_GETARG_POLYGON_P(n)
Definition: geo_decls.h:164
static float8 dist_cpoly_internal(CIRCLE *circle, POLYGON *poly)
Definition: geo_ops.c:2562
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170

◆ dist_cpoly_internal()

static float8 dist_cpoly_internal ( CIRCLE circle,
POLYGON poly 
)
static

Definition at line 2562 of file geo_ops.c.

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

Referenced by dist_cpoly(), and dist_polyc().

2563 {
2564  float8 result;
2565 
2566  /* calculate distance to center, and subtract radius */
2567  result = float8_mi(dist_ppoly_internal(&circle->center, poly),
2568  circle->radius);
2569  if (result < 0.0)
2570  result = 0.0;
2571 
2572  return result;
2573 }
static float8 dist_ppoly_internal(Point *pt, POLYGON *poly)
Definition: geo_ops.c:2621
float8 radius
Definition: geo_decls.h:124
double float8
Definition: c.h:491
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:209
Point center
Definition: geo_decls.h:123

◆ dist_lb()

Datum dist_lb ( PG_FUNCTION_ARGS  )

Definition at line 2527 of file geo_ops.c.

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

2528 {
2529 #ifdef NOT_USED
2530  LINE *line = PG_GETARG_LINE_P(0);
2531  BOX *box = PG_GETARG_BOX_P(1);
2532 #endif
2533 
2534  /* need to think about this one for a while */
2535  ereport(ERROR,
2536  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2537  errmsg("function \"dist_lb\" not implemented")));
2538 
2539  PG_RETURN_NULL();
2540 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
int errcode(int sqlerrcode)
Definition: elog.c:570
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:153
#define ERROR
Definition: elog.h:43
Definition: geo_decls.h:87
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ dist_lp()

Datum dist_lp ( 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  LINE *line = PG_GETARG_LINE_P(0);
2358  Point *pt = PG_GETARG_POINT_P(1);
2359 
2360  PG_RETURN_FLOAT8(line_closept_point(NULL, line, pt));
2361 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
static float8 line_closept_point(Point *result, LINE *line, Point *pt)
Definition: geo_ops.c:2715
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:153
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
Definition: geo_decls.h:87

◆ dist_ls()

Datum dist_ls ( 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  LINE *line = PG_GETARG_LINE_P(0);
2494  LSEG *lseg = PG_GETARG_LSEG_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:2993
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:141
Definition: geo_decls.h:65
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:153
Definition: geo_decls.h:87

◆ dist_pathp()

Datum dist_pathp ( 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  PATH *path = PG_GETARG_PATH_P(0);
2446  Point *pt = PG_GETARG_POINT_P(1);
2447 
2449 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
static float8 dist_ppath_internal(Point *pt, PATH *path)
Definition: geo_ops.c:2388
#define PG_GETARG_PATH_P(n)
Definition: geo_decls.h:147
Definition: geo_decls.h:74

◆ dist_pb()

Datum dist_pb ( PG_FUNCTION_ARGS  )

Definition at line 2455 of file geo_ops.c.

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

2456 {
2457  Point *pt = PG_GETARG_POINT_P(0);
2458  BOX *box = PG_GETARG_BOX_P(1);
2459 
2460  PG_RETURN_FLOAT8(box_closept_point(NULL, box, pt));
2461 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
static float8 box_closept_point(Point *result, BOX *box, Point *point)
Definition: geo_ops.c:2869

◆ dist_pc()

Datum dist_pc ( PG_FUNCTION_ARGS  )

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

5102 {
5103  Point *point = PG_GETARG_POINT_P(0);
5104  CIRCLE *circle = PG_GETARG_CIRCLE_P(1);
5105  float8 result;
5106 
5107  result = float8_mi(point_dt(point, &circle->center),
5108  circle->radius);
5109  if (result < 0.0)
5110  result = 0.0;
5111 
5112  PG_RETURN_FLOAT8(result);
5113 }
float8 radius
Definition: geo_decls.h:124
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
static float8 point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1959
double float8
Definition: c.h:491
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:209
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170
Point center
Definition: geo_decls.h:123

◆ dist_pl()

Datum dist_pl ( PG_FUNCTION_ARGS  )

Definition at line 2343 of file geo_ops.c.

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

2344 {
2345  Point *pt = PG_GETARG_POINT_P(0);
2346  LINE *line = PG_GETARG_LINE_P(1);
2347 
2348  PG_RETURN_FLOAT8(line_closept_point(NULL, line, pt));
2349 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
static float8 line_closept_point(Point *result, LINE *line, Point *pt)
Definition: geo_ops.c:2715
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:153
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
Definition: geo_decls.h:87

◆ dist_polyc()

Datum dist_polyc ( 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  POLYGON *poly = PG_GETARG_POLYGON_P(0);
2594  CIRCLE *circle = PG_GETARG_CIRCLE_P(1);
2595 
2596  PG_RETURN_FLOAT8(dist_cpoly_internal(circle, poly));
2597 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
#define PG_GETARG_POLYGON_P(n)
Definition: geo_decls.h:164
static float8 dist_cpoly_internal(CIRCLE *circle, POLYGON *poly)
Definition: geo_ops.c:2562
#define PG_GETARG_CIRCLE_P(n)
Definition: geo_decls.h:170

◆ dist_polyp()

Datum dist_polyp ( PG_FUNCTION_ARGS  )

Definition at line 2612 of file geo_ops.c.

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

2613 {
2614  POLYGON *poly = PG_GETARG_POLYGON_P(0);
2615  Point *point = PG_GETARG_POINT_P(1);
2616 
2617  PG_RETURN_FLOAT8(dist_ppoly_internal(point, poly));
2618 }
static float8 dist_ppoly_internal(Point *pt, POLYGON *poly)
Definition: geo_ops.c:2621
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
#define PG_GETARG_POLYGON_P(n)
Definition: geo_decls.h:164
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136

◆ dist_ppath()

Datum dist_ppath ( PG_FUNCTION_ARGS  )

Definition at line 2431 of file geo_ops.c.

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

2432 {
2433  Point *pt = PG_GETARG_POINT_P(0);
2434  PATH *path = PG_GETARG_PATH_P(1);
2435 
2437 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
static float8 dist_ppath_internal(Point *pt, PATH *path)
Definition: geo_ops.c:2388
#define PG_GETARG_PATH_P(n)
Definition: geo_decls.h:147
Definition: geo_decls.h:74

◆ dist_ppath_internal()

static float8 dist_ppath_internal ( Point pt,
PATH path 
)
static

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

2389 {
2390  float8 result = 0.0; /* keep compiler quiet */
2391  bool have_min = false;
2392  float8 tmp;
2393  int i;
2394  LSEG lseg;
2395 
2396  Assert(path->npts > 0);
2397 
2398  /*
2399  * The distance from a point to a path is the smallest distance from the
2400  * point to any of its constituent segments.
2401  */
2402  for (i = 0; i < path->npts; i++)
2403  {
2404  int iprev;
2405 
2406  if (i > 0)
2407  iprev = i - 1;
2408  else
2409  {
2410  if (!path->closed)
2411  continue;
2412  iprev = path->npts - 1; /* Include the closure segment */
2413  }
2414 
2415  statlseg_construct(&lseg, &path->p[iprev], &path->p[i]);
2416  tmp = lseg_closept_point(NULL, &lseg, pt);
2417  if (!have_min || float8_lt(tmp, result))
2418  {
2419  result = tmp;
2420  have_min = true;
2421  }
2422  }
2423 
2424  return result;
2425 }
int32 closed
Definition: geo_decls.h:78
static void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: geo_ops.c:2095
Definition: geo_decls.h:65
double float8
Definition: c.h:491
static float8 lseg_closept_point(Point *result, LSEG *lseg, Point *pt)
Definition: geo_ops.c:2763
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:80
int32 npts
Definition: geo_decls.h:77
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:314
#define Assert(condition)
Definition: c.h:732
int i

◆ dist_ppoly()

Datum dist_ppoly ( PG_FUNCTION_ARGS  )

Definition at line 2603 of file geo_ops.c.

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

2604 {
2605  Point *point = PG_GETARG_POINT_P(0);
2606  POLYGON *poly = PG_GETARG_POLYGON_P(1);
2607 
2608  PG_RETURN_FLOAT8(dist_ppoly_internal(point, poly));
2609 }
static float8 dist_ppoly_internal(Point *pt, POLYGON *poly)
Definition: geo_ops.c:2621
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
#define PG_GETARG_POLYGON_P(n)
Definition: geo_decls.h:164
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136

◆ dist_ppoly_internal()

static float8 dist_ppoly_internal ( Point pt,
POLYGON poly 
)
static

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

2622 {
2623  float8 result;
2624  float8 d;
2625  int i;
2626  LSEG seg;
2627 
2628  if (point_inside(pt, poly->npts, poly->p) != 0)
2629  return 0.0;
2630 
2631  /* initialize distance with segment between first and last points */
2632  seg.p[0].x = poly->p[0].x;
2633  seg.p[0].y = poly->p[0].y;
2634  seg.p[1].x = poly->p[poly->npts - 1].x;
2635  seg.p[1].y = poly->p[poly->npts - 1].y;
2636  result = lseg_closept_point(NULL, &seg, pt);
2637 
2638  /* check distances for other segments */
2639  for (i = 0; i < poly->npts - 1; i++)
2640  {
2641  seg.p[0].x = poly->p[i].x;
2642  seg.p[0].y = poly->p[i].y;
2643  seg.p[1].x = poly->p[i + 1].x;
2644  seg.p[1].y = poly->p[i + 1].y;
2645  d = lseg_closept_point(NULL, &seg, pt);
2646  if (float8_lt(d, result))
2647  result = d;
2648  }
2649 
2650  return result;
2651 }
float8 x
Definition: geo_decls.h:57
Definition: geo_decls.h:65
static int point_inside(Point *p, int npts, Point *plist)
Definition: geo_ops.c:5332
int32 npts
Definition: geo_decls.h:113
double float8
Definition: c.h:491
static float8 lseg_closept_point(Point *result, LSEG *lseg, Point *pt)
Definition: geo_ops.c:2763
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:115
static bool float8_lt(const float8 val1, const float8 val2)
Definition: float.h:314
float8 y
Definition: geo_decls.h:57
Point p[2]
Definition: geo_decls.h:67
int i

◆ dist_ps()

Datum dist_ps ( PG_FUNCTION_ARGS  )

Definition at line 2367 of file geo_ops.c.

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

2368 {
2369  Point *pt = PG_GETARG_POINT_P(0);
2370  LSEG *lseg = PG_GETARG_LSEG_P(1);
2371 
2372  PG_RETURN_FLOAT8(lseg_closept_point(NULL, lseg, pt));
2373 }
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:141
Definition: geo_decls.h:65
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
static float8 lseg_closept_point(Point *result, LSEG *lseg, Point *pt)
Definition: geo_ops.c:2763
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136

◆ dist_sb()

Datum dist_sb ( PG_FUNCTION_ARGS  )

Definition at line 2503 of file geo_ops.c.

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

2504 {
2505  LSEG *lseg = PG_GETARG_LSEG_P(0);
2506  BOX *box = PG_GETARG_BOX_P(1);
2507 
2508  PG_RETURN_FLOAT8(box_closept_lseg(NULL, box, lseg));
2509 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:141
Definition: geo_decls.h:65
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
static float8 box_closept_lseg(Point *result, BOX *box, LSEG *lseg)
Definition: geo_ops.c:3046

◆ dist_sl()

Datum dist_sl ( PG_FUNCTION_ARGS  )

Definition at line 2479 of file geo_ops.c.

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

2480 {
2481  LSEG *lseg = PG_GETARG_LSEG_P(0);
2482  LINE *line = PG_GETARG_LINE_P(1);
2483 
2484  PG_RETURN_FLOAT8(lseg_closept_line(NULL, lseg, line));
2485 }
static float8 lseg_closept_line(Point *result, LSEG *lseg, LINE *line)
Definition: geo_ops.c:2993
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:141
Definition: geo_decls.h:65
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:153
Definition: geo_decls.h:87

◆ dist_sp()

Datum dist_sp ( 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  LSEG *lseg = PG_GETARG_LSEG_P(0);
2382  Point *pt = PG_GETARG_POINT_P(1);
2383 
2384  PG_RETURN_FLOAT8(lseg_closept_point(NULL, lseg, pt));
2385 }
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:141
Definition: geo_decls.h:65
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
static float8 lseg_closept_point(Point *result, LSEG *lseg, Point *pt)
Definition: geo_ops.c:2763
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136

◆ inter_lb()

Datum inter_lb ( PG_FUNCTION_ARGS  )

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

3378 {
3379  LINE *line = PG_GETARG_LINE_P(0);
3380  BOX *box = PG_GETARG_BOX_P(1);
3381  LSEG bseg;
3382  Point p1,
3383  p2;
3384 
3385  /* pairwise check lseg intersections */
3386  p1.x = box->low.x;
3387  p1.y = box->low.y;
3388  p2.x = box->low.x;
3389  p2.y = box->high.y;
3390  statlseg_construct(&bseg, &p1, &p2);
3391  if (lseg_interpt_line(NULL, &bseg, line))
3392  PG_RETURN_BOOL(true);
3393  p1.x = box->high.x;
3394  p1.y = box->high.y;
3395  statlseg_construct(&bseg, &p1, &p2);
3396  if (lseg_interpt_line(NULL, &bseg, line))
3397  PG_RETURN_BOOL(true);
3398  p2.x = box->high.x;
3399  p2.y = box->low.y;
3400  statlseg_construct(&bseg, &p1, &p2);
3401  if (lseg_interpt_line(NULL, &bseg, line))
3402  PG_RETURN_BOOL(true);
3403  p1.x = box->low.x;
3404  p1.y = box->low.y;
3405  statlseg_construct(&bseg, &p1, &p2);
3406  if (lseg_interpt_line(NULL, &bseg, line))
3407  PG_RETURN_BOOL(true);
3408 
3409  /* if we dropped through, no intersection */
3410  PG_RETURN_BOOL(false);
3411 }
Definition: geo_decls.h:99
static bool lseg_interpt_line(Point *result, LSEG *lseg, LINE *line)
Definition: geo_ops.c:2666
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
float8 x
Definition: geo_decls.h:57
static void statlseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: geo_ops.c:2095
Definition: geo_decls.h:65
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:153
Definition: geo_decls.h:87
Point low
Definition: geo_decls.h:101
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
float8 y
Definition: geo_decls.h:57
Point high
Definition: geo_decls.h:101

◆ inter_sb()

Datum inter_sb ( PG_FUNCTION_ARGS  )

Definition at line 3364 of file geo_ops.c.

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

3365 {
3366  LSEG *lseg = PG_GETARG_LSEG_P(0);
3367  BOX *box = PG_GETARG_BOX_P(1);
3368 
3369  PG_RETURN_BOOL(box_interpt_lseg(NULL, box, lseg));
3370 }
Definition: geo_decls.h:99
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:158
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:141
Definition: geo_decls.h:65
static bool box_interpt_lseg(Point *result, BOX *box, LSEG *lseg)
Definition: geo_ops.c:3312
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ inter_sl()

Datum inter_sl ( PG_FUNCTION_ARGS  )

Definition at line 3287 of file geo_ops.c.

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

3288 {
3289  LSEG *lseg = PG_GETARG_LSEG_P(0);
3290  LINE *line = PG_GETARG_LINE_P(1);
3291 
3292  PG_RETURN_BOOL(lseg_interpt_line(NULL, lseg, line));
3293 }
static bool lseg_interpt_line(Point *result, LSEG *lseg, LINE *line)
Definition: geo_ops.c:2666
#define PG_GETARG_LSEG_P(n)
Definition: geo_decls.h:141
Definition: geo_decls.h:65
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:153
Definition: geo_decls.h:87
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ line_closept_point()

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

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

2716 {
2717  Point closept;
2718  LINE tmp;
2719 
2720  /*
2721  * We drop a perpendicular to find the intersection point. Ordinarily we
2722  * should always find it, but that can fail in the presence of NaN
2723  * coordinates, and perhaps even from simple roundoff issues.
2724  */
2725  line_construct(&tmp, point, line_invsl(line));
2726  if (!line_interpt_line(&closept, &tmp, line))
2727  {
2728  if (result != NULL)
2729  *result = *point;
2730 
2731  return get_float8_nan();
2732  }
2733 
2734  if (result != NULL)
2735  *result = closept;
2736 
2737  return point_dt(&closept, point);
2738 }
static bool line_interpt_line(Point *result, LINE *l1, LINE *l2)
Definition: geo_ops.c:1276
static float8 line_invsl(LINE *line)
Definition: geo_ops.c:1209
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:1959
static float8 get_float8_nan(void)
Definition: float.h:119
Definition: geo_decls.h:87

◆ 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 (m == DBL_MAX)
1059  {
1060  /* vertical - use "x = C" */
1061  result->A = -1.0;
1062  result->B = 0.0;
1063  result->C = pt->x;
1064  }
1065  else
1066  {
1067  /* use "mx - y + yinter = 0" */
1068  result->A = m;
1069  result->B = -1.0;
1070  result->C = float8_mi(pt->y, float8_mul(m, pt->x));
1071  /* on some platforms, the preceding expression tends to produce -0 */
1072  if (result->C == 0.0)
1073  result->C = 0.0;
1074  }
1075 }
float8 C
Definition: geo_decls.h:89
float8 x
Definition: geo_decls.h:57
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:232
float8 B
Definition: geo_decls.h:89
float8 A
Definition: geo_decls.h:89
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:209
float8 y
Definition: geo_decls.h:57

◆ line_construct_pp()

Datum line_construct_pp ( PG_FUNCTION_ARGS  )

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

1082 {
1083  Point *pt1 = PG_GETARG_POINT_P(0);
1084  Point *pt2 = PG_GETARG_POINT_P(1);
1085  LINE *result = (LINE *) palloc(sizeof(LINE));
1086 
1087  if (point_eq_point(pt1, pt2))
1088  ereport(ERROR,
1089  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1090  errmsg("invalid line specification: must be two distinct points")));
1091 
1092  line_construct(result, pt1, point_sl(pt1, pt2));
1093 
1094  PG_RETURN_LINE_P(result);
1095 }
static void line_construct(LINE *result, Point *pt, float8 m)
Definition: geo_ops.c:1056
int errcode(int sqlerrcode)
Definition: elog.c:570
#define ERROR
Definition: elog.h:43
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:136
static bool point_eq_point(Point *pt1, Point *pt2)
Definition: geo_ops.c:1938
Definition: geo_decls.h:87
#define ereport(elevel, rest)
Definition: elog.h:141
static float8 point_sl(Point *pt1, Point *pt2)
Definition: geo_ops.c:1980
#define PG_RETURN_LINE_P(x)
Definition: geo_decls.h:154
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:784

◆ line_contain_point()

static bool line_contain_point ( LINE line,
Point point 
)
static

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

3137 {
3138  return FPzero(float8_pl(float8_pl(float8_mul(line->A, point->x),
3139  float8_mul(line->B, point->y)),
3140  line->C));
3141 }
float8 C
Definition: geo_decls.h:89
#define FPzero(A)
Definition: geo_decls.h:33
float8 x
Definition: geo_decls.h:57
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:232
float8 B
Definition: geo_decls.h:89
float8 A
Definition: geo_decls.h:89
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:187
float8 y
Definition: geo_decls.h:57

◆ 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:89
#define DELIM
Definition: geo_ops.c:154
float8 B
Definition: geo_decls.h:89
float8 A
Definition: geo_decls.h:89
#define RDELIM_L
Definition: geo_ops.c:160

◆ line_distance()

Datum line_distance ( PG_FUNCTION_ARGS  )

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

1224 {
1225  LINE *l1 = PG_GETARG_LINE_P(0);
1226  LINE *l2 = PG_GETARG_LINE_P(1);
1227  float8 ratio;
1228 
1229  if (line_interpt_line(NULL, l1, l2)) /* intersecting? */
1230  PG_RETURN_FLOAT8(0.0);
1231 
1232  if (!FPzero(l1->A) && !isnan(l1->A) && !FPzero(l2->A) && !isnan(l2->A))
1233  ratio = float8_div(l1->A, l2->A);
1234  else if (!FPzero(l1->B) && !isnan(l1->B) && !FPzero(l2->B) && !isnan(l2->B))
1235  ratio = float8_div(l1->B, l2->B);
1236  else
1237  ratio = 1.0;
1238 
1240  float8_mul(ratio, l2->C))),
1241  HYPOT(l1->A, l1->B)));
1242 }
static bool line_interpt_line(Point *result, LINE *l1, LINE *l2)
Definition: geo_ops.c:1276
float8 C
Definition: geo_decls.h:89
#define FPzero(A)
Definition: geo_decls.h:33
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:232
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:153
double float8
Definition: c.h:491
Definition: geo_decls.h:87
float8 B
Definition: geo_decls.h:89
float8 A
Definition: geo_decls.h:89
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:209
#define HYPOT(A, B)
Definition: geo_decls.h:50
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:260

◆ line_eq()

Datum line_eq ( PG_FUNCTION_ARGS  )

Definition at line 1163 of file geo_ops.c.

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

1164 {
1165  LINE *l1 = PG_GETARG_LINE_P(0);
1166  LINE *l2 = PG_GETARG_LINE_P(1);
1167  float8 ratio;
1168 
1169  if (!FPzero(l2->A) && !isnan(l2->A))
1170  ratio = float8_div(l1->A, l2->A);
1171  else if (!FPzero(l2->B) && !isnan(l2->B))
1172  ratio = float8_div(l1->B, l2->B);
1173  else if (!FPzero(l2->C) && !isnan(l2->C))
1174  ratio = float8_div(l1->C, l2->C);
1175  else
1176  ratio = 1.0;
1177 
1178  PG_RETURN_BOOL((FPeq(l1->A, float8_mul(ratio, l2->A)) &&
1179  FPeq(l1->B, float8_mul(ratio, l2->B)) &&
1180  FPeq(l1->C, float8_mul(ratio, l2->C))) ||
1181  (float8_eq(l1->A, l2->A) &&
1182  float8_eq(l1->B, l2->B) &&
1183  float8_eq(l1->C, l2->C)));
1184 }
float8 C
Definition: geo_decls.h:89
#define FPzero(A)
Definition: geo_decls.h:33
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:232
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:153
double float8
Definition: c.h:491
Definition: geo_decls.h:87
float8 B
Definition: geo_decls.h:89
float8 A
Definition: geo_decls.h:89
#define FPeq(A, B)
Definition: geo_decls.h:34
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:260
static bool float8_eq(const float8 val1, const float8 val2)
Definition: float.h:290

◆ line_horizontal()

Datum line_horizontal ( PG_FUNCTION_ARGS  )

Definition at line 1148 of file geo_ops.c.

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

1149 {
1150  LINE *line = PG_GETARG_LINE_P(0);
1151 
1152  PG_RETURN_BOOL(FPzero(line->A));
1153 }
#define FPzero(A)
Definition: geo_decls.h:33
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:153
Definition: geo_decls.h:87
float8 A
Definition: geo_decls.h:89
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ 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:33
static float8 lseg_sl(LSEG *lseg)
Definition: geo_ops.c:2108
Definition: geo_decls.h:65
static void line_construct(LINE *result, Point *pt, float8 m)
Definition: geo_ops.c:1056
int errcode(int sqlerrcode)
Definition: elog.c:570
#define ERROR
Definition: elog.h:43
static bool point_eq_point(Point *pt1, Point *pt2)
Definition: geo_ops.c:1938
Definition: geo_decls.h:87
float8 B
Definition: geo_decls.h:89
#define LDELIM_L
Definition: geo_ops.c:159
float8 A
Definition: geo_decls.h:89
#define ereport(elevel, rest)
Definition: elog.h:141
static bool line_decode(char *s, const char *str, LINE *line)
Definition: geo_ops.c:938
Point p[2]
Definition: geo_decls.h:67
#define PG_RETURN_LINE_P(x)
Definition: geo_decls.h:154
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:272
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 1248 of file geo_ops.c.

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

1249 {
1250  LINE *l1 = PG_GETARG_LINE_P(0);
1251  LINE *l2 = PG_GETARG_LINE_P(1);
1252  Point *result;
1253 
1254  result = (Point *) palloc(sizeof(Point));
1255 
1256  if (!line_interpt_line(result, l1, l2))
1257  PG_RETURN_NULL();
1258  PG_RETURN_POINT_P(result);
1259 }
static bool line_interpt_line(Point *result, LINE *l1, LINE *l2)
Definition: geo_ops.c:1276
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:153
Definition: geo_decls.h:87
#define PG_RETURN_POINT_P(x)
Definition: geo_decls.h:137
void * palloc(Size size)
Definition: mcxt.c:949
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ line_interpt_line()

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

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

1277 {
1278  float8 x,
1279  y;
1280 
1281  if (!FPzero(l1->B))
1282  {
1283  if (FPeq(l2->A, float8_mul(l1->A, float8_div(l2->B, l1->B))))
1284  return false;
1285 
1286  x = float8_div(float8_mi(float8_mul(l1->B, l2->C),
1287  float8_mul(l2->B, l1->C)),
1288  float8_mi(float8_mul(l1->A, l2->B),
1289  float8_mul(l2->A, l1->B)));
1290  y = float8_div(-float8_pl(float8_mul(l1->A, x), l1->C), l1->B);
1291  }
1292  else if (!FPzero(l2->B))
1293  {
1294  if (FPeq(l1->A, float8_mul(l2->A, float8_div(l1->B, l2->B))))
1295  return false;
1296 
1297  x = float8_div(float8_mi(float8_mul(l2->B, l1->C),
1298  float8_mul(l1->B, l2->C)),
1299  float8_mi(float8_mul(l2->A, l1->B),
1300  float8_mul(l1->A, l2->B)));
1301  y = float8_div(-float8_pl(float8_mul(l2->A, x), l2->C), l2->B);
1302  }
1303  else
1304  return false;
1305 
1306  /* On some platforms, the preceding expressions tend to produce -0. */
1307  if (x == 0.0)
1308  x = 0.0;
1309  if (y == 0.0)
1310  y = 0.0;
1311 
1312  if (result != NULL)
1313  point_construct(result, x, y);
1314 
1315  return true;
1316 }
float8 C
Definition: geo_decls.h:89
#define FPzero(A)
Definition: geo_decls.h:33
static float8 float8_mul(const float8 val1, const float8 val2)
Definition: float.h:232
static void point_construct(Point *result, float8 x, float8 y)
Definition: geo_ops.c:1842
double float8
Definition: c.h:491
float8 B
Definition: geo_decls.h:89
float8 A
Definition: geo_decls.h:89
static float8 float8_pl(const float8 val1, const float8 val2)
Definition: float.h:187
static float8 float8_mi(const float8 val1, const float8 val2)
Definition: float.h:209
#define FPeq(A, B)
Definition: geo_decls.h:34
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:260

◆ line_intersect()

Datum line_intersect ( PG_FUNCTION_ARGS  )

Definition at line 1103 of file geo_ops.c.

References line_interpt_line(), PG_GETARG_LINE_P, and PG_RETURN_BOOL.

1104 {
1105  LINE *l1 = PG_GETARG_LINE_P(0);
1106  LINE *l2 = PG_GETARG_LINE_P(1);
1107 
1108  PG_RETURN_BOOL(line_interpt_line(NULL, l1, l2));
1109 }
static bool line_interpt_line(Point *result, LINE *l1, LINE *l2)
Definition: geo_ops.c:1276
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:153
Definition: geo_decls.h:87
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ line_invsl()

static float8 line_invsl ( LINE line)
inlinestatic

Definition at line 1209 of file geo_ops.c.

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

Referenced by line_closept_point().

1210 {
1211  if (FPzero(line->A))
1212  return DBL_MAX;
1213  if (FPzero(line->B))
1214  return 0.0;
1215  return float8_div(line->B, line->A);
1216 }
#define FPzero(A)
Definition: geo_decls.h:33
float8 B
Definition: geo_decls.h:89
float8 A
Definition: geo_decls.h:89
static float8 float8_div(const float8 val1, const float8 val2)
Definition: float.h:260

◆ line_out()

Datum line_out ( PG_FUNCTION_ARGS  )

Definition at line 996 of file geo_ops.c.

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

997 {
998  LINE *line = PG_GETARG_LINE_P(0);
999  char *astr = float8out_internal(line->A);
1000  char *bstr = float8out_internal(line->B);
1001  char *cstr = float8out_internal(line->C);
1002 
1003  PG_RETURN_CSTRING(psprintf("%c%s%c%s%c%s%c", LDELIM_L, astr, DELIM, bstr,
1004  DELIM, cstr, RDELIM_L));
1005 }
float8 C
Definition: geo_decls.h:89
char * float8out_internal(double num)
Definition: float.c:546
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
#define DELIM
Definition: geo_ops.c:154
#define PG_GETARG_LINE_P(n)
Definition: geo_decls.h:153
Definition: geo_decls.h:87