cube takes text input and returns a cube. This is useful for making cubes
from computed strings.
+cube(float8) returns cube
+ This makes a one dimensional cube with both coordinates the same.
+ If the type of the argument is a numeric type other than float8 an
+ explicit cast to float8 may be needed.
+ cube(1) == '(1)'
+
+cube(float8, float8) returns cube
+ This makes a one dimensional cube.
+ cube(1,2) == '(1),(2)'
+
+cube(cube, float8) returns cube
+ This builds a new cube by adding a dimension on to an existing cube with
+ the same values for both parts of the new coordinate. This is useful for
+ building cubes piece by piece from calculated values.
+ cube('(1)',2) == '(1,2),(1,2)'
+
+cube(cube, float8, float8) returns cube
+ This builds a new cube by adding a dimension on to an existing cube.
+ This is useful for building cubes piece by piece from calculated values.
+ cube('(1,2)',3,4) == '(1,3),(2,4)'
+
cube_dim(cube) returns int
cube_dim returns the number of dimensions stored in the the data structure
for a cube. This is useful for constraints on the dimensions of a cube.
NDBOX *cube_in(char *str);
NDBOX *cube(text *str);
char *cube_out(NDBOX * cube);
+NDBOX *cube_f8(double *);
+NDBOX *cube_f8_f8(double *, double *);
+NDBOX *cube_c_f8(NDBOX *, double *);
+NDBOX *cube_c_f8_f8(NDBOX *, double *, double *);
+int4 cube_dim(NDBOX * a);
+double *cube_ll_coord(NDBOX * a, int4 n);
+double *cube_ur_coord(NDBOX * a, int4 n);
/*
bool cube_lt(NDBOX * a, NDBOX * b);
bool cube_gt(NDBOX * a, NDBOX * b);
double *cube_distance(NDBOX * a, NDBOX * b);
-int4 cube_dim(NDBOX * a);
-double *cube_ll_coord(NDBOX * a, int4 n);
-double *cube_ur_coord(NDBOX * a, int4 n);
bool cube_is_point(NDBOX * a);
NDBOX *cube_enlarge(NDBOX * a, double *r, int4 n);
}
return result;
}
+
+/* Create a one dimensional box with identical upper and lower coordinates */
+NDBOX *
+cube_f8(double *x1)
+{
+ NDBOX *result;
+ int size;
+ size = offsetof(NDBOX, x[0]) + sizeof(double) * 2;
+ result = (NDBOX *) palloc(size);
+ memset(result, 0, size);
+ result->size = size;
+ result->dim = 1;
+ result->x[0] = *x1;
+ result->x[1] = *x1;
+ return result;
+}
+
+/* Create a one dimensional box */
+NDBOX *
+cube_f8_f8(double *x1, double *x2)
+{
+ NDBOX *result;
+ int size;
+ size = offsetof(NDBOX, x[0]) + sizeof(double) * 2;
+ result = (NDBOX *) palloc(size);
+ memset(result, 0, size);
+ result->size = size;
+ result->dim = 1;
+ result->x[0] = *x1;
+ result->x[1] = *x2;
+ return result;
+}
+
+/* Add a dimension to an existing cube with the same values for the new
+ coordinate */
+NDBOX *
+cube_c_f8(NDBOX *c, double *x1)
+{
+ NDBOX *result;
+ int size;
+ int i;
+ size = offsetof(NDBOX, x[0]) + sizeof(double) * (c->dim + 1) * 2;
+ result = (NDBOX *) palloc(size);
+ memset(result, 0, size);
+ result->size = size;
+ result->dim = c->dim + 1;
+ for (i = 0; i < c->dim; i++) {
+ result->x[i] = c->x[i];
+ result->x[result->dim + i] = c->x[c->dim + i];
+ }
+ result->x[result->dim - 1] = *x1;
+ result->x[2 * result->dim - 1] = *x1;
+ return result;
+}
+
+/* Add a dimension to an existing cube */
+NDBOX *
+cube_c_f8_f8(NDBOX *c, double *x1, double *x2)
+{
+ NDBOX *result;
+ int size;
+ int i;
+ size = offsetof(NDBOX, x[0]) + sizeof(double) * (c->dim + 1) * 2;
+ result = (NDBOX *) palloc(size);
+ memset(result, 0, size);
+ result->size = size;
+ result->dim = c->dim + 1;
+ for (i = 0; i < c->dim; i++) {
+ result->x[i] = c->x[i];
+ result->x[result->dim + i] = c->x[c->dim + i];
+ }
+ result->x[result->dim - 1] = *x1;
+ result->x[2 * result->dim - 1] = *x2;
+ return result;
+}
SELECT ''::cube AS cube;
ERROR: cube_in: can't parse an empty string
SELECT 'ABC'::cube AS cube;
-ERROR: parse error at or before position 1, character ('A', \101), input: 'ABC'
+ERROR: syntax error at or before position 1, character ('A', \101), input: 'ABC'
SELECT '()'::cube AS cube;
-ERROR: parse error at or before position 2, character (')', \051), input: '()'
+ERROR: syntax error at or before position 2, character (')', \051), input: '()'
SELECT '[]'::cube AS cube;
-ERROR: parse error at or before position 2, character (']', \135), input: '[]'
+ERROR: syntax error at or before position 2, character (']', \135), input: '[]'
SELECT '[()]'::cube AS cube;
-ERROR: parse error at or before position 3, character (')', \051), input: '[()]'
+ERROR: syntax error at or before position 3, character (')', \051), input: '[()]'
SELECT '[(1)]'::cube AS cube;
-ERROR: parse error at or before position 5, character (']', \135), input: '[(1)]'
+ERROR: syntax error at or before position 5, character (']', \135), input: '[(1)]'
SELECT '[(1),]'::cube AS cube;
-ERROR: parse error at or before position 6, character (']', \135), input: '[(1),]'
+ERROR: syntax error at or before position 6, character (']', \135), input: '[(1),]'
SELECT '[(1),2]'::cube AS cube;
-ERROR: parse error at or before position 7, character (']', \135), input: '[(1),2]'
+ERROR: syntax error at or before position 7, character (']', \135), input: '[(1),2]'
SELECT '[(1),(2),(3)]'::cube AS cube;
-ERROR: parse error at or before position 9, character (',', \054), input: '[(1),(2),(3)]'
+ERROR: syntax error at or before position 9, character (',', \054), input: '[(1),(2),(3)]'
SELECT '1,'::cube AS cube;
-ERROR: parse error at or before position 2, character (',', \054), input: '1,'
+ERROR: syntax error at or before position 2, character (',', \054), input: '1,'
SELECT '1,2,'::cube AS cube;
-ERROR: parse error at or before position 4, character (',', \054), input: '1,2,'
+ERROR: syntax error at or before position 4, character (',', \054), input: '1,2,'
SELECT '1,,2'::cube AS cube;
-ERROR: parse error at or before position 3, character (',', \054), input: '1,,2'
+ERROR: syntax error at or before position 3, character (',', \054), input: '1,,2'
SELECT '(1,)'::cube AS cube;
-ERROR: parse error at or before position 4, character (')', \051), input: '(1,)'
+ERROR: syntax error at or before position 4, character (')', \051), input: '(1,)'
SELECT '(1,2,)'::cube AS cube;
-ERROR: parse error at or before position 6, character (')', \051), input: '(1,2,)'
+ERROR: syntax error at or before position 6, character (')', \051), input: '(1,2,)'
SELECT '(1,,2)'::cube AS cube;
-ERROR: parse error at or before position 4, character (',', \054), input: '(1,,2)'
+ERROR: syntax error at or before position 4, character (',', \054), input: '(1,,2)'
-- invalid input: semantic errors and trailing garbage
SELECT '[(1),(2)],'::cube AS cube; -- 0
SELECT '1..2'::cube AS cube; -- 7
ERROR: (7) bad cube representation; garbage at or before char 4, ('end of input', \000)
+--
+-- Testing building cubes from float8 values
+--
+SELECT cube(0::float8);
+ cube
+------
+ (0)
+(1 row)
+
+SELECT cube(1::float8);
+ cube
+------
+ (1)
+(1 row)
+
+SELECT cube(1,2);
+ cube
+---------
+ (1),(2)
+(1 row)
+
+SELECT cube(cube(1,2),3);
+ cube
+---------------
+ (1, 3),(2, 3)
+(1 row)
+
+SELECT cube(cube(1,2),3,4);
+ cube
+---------------
+ (1, 3),(2, 4)
+(1 row)
+
+SELECT cube(cube(cube(1,2),3,4),5);
+ cube
+---------------------
+ (1, 3, 5),(2, 4, 5)
+(1 row)
+
+SELECT cube(cube(cube(1,2),3,4),5,6);
+ cube
+---------------------
+ (1, 3, 5),(2, 4, 6)
+(1 row)
+
+--
+-- Test that the text -> cube cast was installed.
+--
+SELECT '(0)'::text::cube;
+ cube
+------
+ (0)
+(1 row)
+
--
-- Testing limit of CUBE_MAX_DIM dimensions check in cube_in.
--