1 /*****************************************************************************
2 Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7 
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation.  The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License, version 2.0, for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 *****************************************************************************/
24 
25 /** @file gis0geo.h
26  The r-tree define from MyISAM
27  *******************************************************/
28 
29 #ifndef _gis0geo_h
30 #define _gis0geo_h
31 
32 #include "page0types.h"
33 #include "sql/gis/rtree_support.h"
34 
35 #define SPTYPE HA_KEYTYPE_DOUBLE
36 #define SPLEN 8
37 
38 namespace dd {
39 class Spatial_reference_system;
40 }
41 
42 /* Rtree split node structure. */
43 struct rtr_split_node_t {
44   double square;  /* square of the mbr.*/
45   int n_node;     /* which group in.*/
46   uchar *key;     /* key. */
47   double *coords; /* mbr. */
48 };
49 
50 /** Inline function for reserving coords */
reserve_coords(double ** d_buffer,int n_dim)51 inline static double *reserve_coords(double **d_buffer, /*!< in/out: buffer. */
52                                      int n_dim)         /*!< in: dimensions. */
53 {
54   double *coords = *d_buffer;
55   (*d_buffer) += n_dim * 2;
56   return coords;
57 }
58 
59 /** Split rtree nodes.
60  Return which group the first rec is in.  */
61 int split_rtree_node(
62     rtr_split_node_t *node,                   /*!< in: split nodes.*/
63     int n_entries,                            /*!< in: entries number.*/
64     int all_size,                             /*!< in: total key's size.*/
65     int key_size,                             /*!< in: key's size.*/
66     int min_size,                             /*!< in: minimal group size.*/
67     int size1,                                /*!< in: size of group.*/
68     int size2,                                /*!< in: initial group sizes */
69     double **d_buffer,                        /*!< in/out: buffer.*/
70     int n_dim,                                /*!< in: dimensions. */
71     uchar *first_rec,                         /*!< in: the first rec. */
72     const dd::Spatial_reference_system *srs); /*!< in: SRS of R-tree */
73 
74 /** Compares two keys a and b depending on mode
75  mode can contain these flags:
76     PAGE_CUR_INTERSECT   a intersects b
77     PAGE_CUR_CONTAIN     a contains   b
78     PAGE_CUR_DISJOINT    a disjoint   b
79     PAGE_CUR_WITHIN      a within     b
80     PAGE_CUR_MBR_EQUAL   All coordinates of MBRs are equal
81  @param[in]	mode	compare method
82  @param[in]	a	first key
83  @param[in]	a_len	first key len
84  @param[in]	b	second key
85  @param[in]	b_len	second_key_len
86  @param[in]	srs	Spatial reference system of R-tree
87  @retval true if the predicate is true, otherwise false. */
88 bool rtree_key_cmp(page_cur_mode_t mode, const uchar *a, int a_len,
89                    const uchar *b, int b_len,
90                    const dd::Spatial_reference_system *srs);
91 #endif
92