LCOV - code coverage report
Current view: top level - src/backend/access/spgist - spgproc.c (source / functions) Coverage Total Hit
Test: Code coverage Lines: 100.0 % 33 33
Test Date: 2026-01-26 10:56:24 Functions: 100.0 % 3 3
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 77.8 % 36 28

             Branch data     Line data    Source code
       1                 :             : /*-------------------------------------------------------------------------
       2                 :             :  *
       3                 :             :  * spgproc.c
       4                 :             :  *        Common supporting procedures for SP-GiST opclasses.
       5                 :             :  *
       6                 :             :  *
       7                 :             :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
       8                 :             :  * Portions Copyright (c) 1994, Regents of the University of California
       9                 :             :  *
      10                 :             :  * IDENTIFICATION
      11                 :             :  *                      src/backend/access/spgist/spgproc.c
      12                 :             :  *
      13                 :             :  *-------------------------------------------------------------------------
      14                 :             :  */
      15                 :             : 
      16                 :             : #include "postgres.h"
      17                 :             : 
      18                 :             : #include <math.h>
      19                 :             : 
      20                 :             : #include "access/spgist_private.h"
      21                 :             : #include "utils/float.h"
      22                 :             : #include "utils/fmgrprotos.h"
      23                 :             : #include "utils/geo_decls.h"
      24                 :             : 
      25                 :             : #define point_point_distance(p1,p2) \
      26                 :             :         DatumGetFloat8(DirectFunctionCall2(point_distance, \
      27                 :             :                                                                            PointPGetDatum(p1), PointPGetDatum(p2)))
      28                 :             : 
      29                 :             : /* Point-box distance in the assumption that box is aligned by axis */
      30                 :             : static double
      31                 :       15708 : point_box_distance(Point *point, BOX *box)
      32                 :             : {
      33                 :       15708 :         double          dx,
      34                 :             :                                 dy;
      35                 :             : 
      36   [ -  +  +  +  :       15708 :         if (isnan(point->x) || isnan(box->low.x) ||
          +  -  -  +  +  
                +  +  - ]
      37   [ -  +  +  +  :       15708 :                 isnan(point->y) || isnan(box->low.y))
          +  -  -  +  +  
                +  +  - ]
      38                 :      125664 :                 return get_float8_nan();
      39                 :             : 
      40         [ +  + ]:       15708 :         if (point->x < box->low.x)
      41                 :       14294 :                 dx = box->low.x - point->x;
      42         [ +  + ]:        1414 :         else if (point->x > box->high.x)
      43                 :        1110 :                 dx = point->x - box->high.x;
      44                 :             :         else
      45                 :         304 :                 dx = 0.0;
      46                 :             : 
      47         [ +  + ]:       15708 :         if (point->y < box->low.y)
      48                 :        7560 :                 dy = box->low.y - point->y;
      49         [ +  + ]:        8148 :         else if (point->y > box->high.y)
      50                 :        7954 :                 dy = point->y - box->high.y;
      51                 :             :         else
      52                 :         194 :                 dy = 0.0;
      53                 :             : 
      54                 :       15708 :         return hypot(dx, dy);
      55                 :      141372 : }
      56                 :             : 
      57                 :             : /*
      58                 :             :  * Returns distances from given key to array of ordering scan keys.  Leaf key
      59                 :             :  * is expected to be point, non-leaf key is expected to be box.  Scan key
      60                 :             :  * arguments are expected to be points.
      61                 :             :  */
      62                 :             : double *
      63                 :       62235 : spg_key_orderbys_distances(Datum key, bool isLeaf,
      64                 :             :                                                    ScanKey orderbys, int norderbys)
      65                 :             : {
      66                 :       62235 :         int                     sk_num;
      67                 :       62235 :         double     *distances = palloc_array(double, norderbys),
      68                 :       62235 :                            *distance = distances;
      69                 :             : 
      70         [ +  + ]:      124788 :         for (sk_num = 0; sk_num < norderbys; ++sk_num, ++orderbys, ++distance)
      71                 :             :         {
      72                 :       62553 :                 Point      *point = DatumGetPointP(orderbys->sk_argument);
      73                 :             : 
      74         [ +  + ]:       62553 :                 *distance = isLeaf ? point_point_distance(point, DatumGetPointP(key))
      75                 :       15708 :                         : point_box_distance(point, DatumGetBoxP(key));
      76                 :       62553 :         }
      77                 :             : 
      78                 :      124470 :         return distances;
      79                 :       62235 : }
      80                 :             : 
      81                 :             : BOX *
      82                 :         691 : box_copy(BOX *orig)
      83                 :             : {
      84                 :         691 :         BOX                *result = palloc_object(BOX);
      85                 :             : 
      86                 :         691 :         *result = *orig;
      87                 :        1382 :         return result;
      88                 :         691 : }
        

Generated by: LCOV version 2.3.2-1