1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
|
set client_min_messages = 'WARNING';
create table pl_box (
data box, barea float, boverlaps bool, boverleft bool, boverright bool,
bleft bool, bright bool
);
create or replace function box_val(box[]) returns setof pl_box as '
b1 = Box.new(2.5,2.5,1.0,1.0)
b2 = Box.new(2.0,2.0,2.5,2.5)
b3 = Box.new(3.0,3.0,5.0,5.0)
args[0].each do |b|
yield [b, b.area, b.overlap?(b1), b.overleft?(b2),
b.overright?(b2), b.left?(b3), b3.right?(b)]
end
' language 'plruby';
select * from
box_val('{(2.0,2.0,0.0,0.0);(1.0,1.0,3.0,3.0);(2.5,2.5,2.5,3.5);(3.0,3.0,3.0,3.0)}'::box[]);
data | barea | boverlaps | boverleft | boverright | bleft | bright
---------------------+-------+-----------+-----------+------------+-------+--------
(2,2),(0,0) | 4 | t | t | f | t | t
(3,3),(1,1) | 4 | t | f | f | f | f
(2.5,3.5),(2.5,2.5) | 0 | t | t | t | t | t
(3,3),(3,3) | 0 | f | f | t | f | f
(4 rows)
drop table pl_box cascade;
create table pl_box (
b box, bcmp1 int, bcmp2 int, bin bool, bcontain bool, bcenter point
);
create or replace function box_val(box[]) returns setof pl_box as '
b1 = Box.new(3.0,3.0,5.0,5.0)
b2 = Box.new(3.5,3.0,4.5,3.0)
b3 = Box.new(0,0,3,3)
args[0].each do |b|
yield [b, b <=> b1, b <=> b2, b.in?(b3), b.contain?(b3), b.center]
end
' language 'plruby';
select * from
box_val('{(2.0,2.0,0.0,0.0);(1.0,1.0,3.0,3.0);(2.5,2.5,2.5,3.5);(3.0,3.0,3.0,3.0)}'::box[]);
b | bcmp1 | bcmp2 | bin | bcontain | bcenter
---------------------+-------+-------+-----+----------+---------
(2,2),(0,0) | 0 | 1 | t | f | (1,1)
(3,3),(1,1) | 0 | 1 | t | f | (2,2)
(2.5,3.5),(2.5,2.5) | -1 | 0 | f | f | (2.5,3)
(3,3),(3,3) | -1 | 0 | t | f | (3,3)
(4 rows)
drop table pl_box cascade;
create table pl_box (
b0 box, b1 box, b2 box, b3 box
);
create or replace function box_val(box[]) returns setof pl_box as '
p0 = [Point.new(-10.0,0.0), Point.new(-3.0,4.0),
Point.new(5.1, 34.5), Point.new(-5.0,-12.0)]
args[0].each do |b|
p0.each do |p|
yield [b + p, b - p, b * p, b / p]
end
p0.each do |p|
yield [p + b, p - b, p * b, p / b]
end
end
' language 'plruby';
select * from
box_val('{(2.0,2.0,0.0,0.0);(1.0,1.0,3.0,3.0);(2.5,2.5,2.5,3.5);(3.0,3.0,3.0,3.0)}'::box[]);
b0 | b1 | b2 | b3
-------------------------+---------------------------+-----------------------------+-----------------------------------------------------------------------------------
(-8,2),(-10,0) | (12,2),(10,0) | (-0,0),(-20,-20) | (0,-0),(-0.2,-0.2)
(-1,6),(-3,4) | (5,-2),(3,-4) | (-0,2),(-14,0) | (0.08,-0),(0,-0.56)
(7.1,36.5),(5.1,34.5) | (-3.1,-32.5),(-5.1,-34.5) | (0,79.2),(-58.8,0) | (0.0651176557643925,0),(0,-0.0483449262493217)
(-3,-10),(-5,-12) | (7,14),(5,12) | (14,-0),(0,-34) | (-0,0.0828402366863905),(-0.201183431952663,0)
(-8,2),(-10,0) | (12,2),(10,0) | (-0,0),(-20,-20) | (0,-0),(-0.2,-0.2)
(-1,6),(-3,4) | (5,-2),(3,-4) | (-0,2),(-14,0) | (0.08,-0),(0,-0.56)
(7.1,36.5),(5.1,34.5) | (-3.1,-32.5),(-5.1,-34.5) | (0,79.2),(-58.8,0) | (0.0651176557643925,0),(0,-0.0483449262493217)
(-3,-10),(-5,-12) | (7,14),(5,12) | (14,-0),(0,-34) | (-0,0.0828402366863905),(-0.201183431952663,0)
(-7,3),(-9,1) | (13,3),(11,1) | (-10,-10),(-30,-30) | (-0.1,-0.1),(-0.3,-0.3)
(0,7),(-2,5) | (6,-1),(4,-3) | (-7,3),(-21,1) | (0.12,-0.28),(0.04,-0.84)
(8.1,37.5),(6.1,35.5) | (-2.1,-31.5),(-4.1,-33.5) | (-29.4,118.8),(-88.2,39.6) | (0.0976764836465887,-0.0241724631246608),(0.0325588278821962,-0.0725173893739825)
(-2,-9),(-4,-11) | (8,15),(6,13) | (21,-17),(7,-51) | (-0.100591715976331,0.124260355029586),(-0.301775147928994,0.0414201183431953)
(-7,3),(-9,1) | (13,3),(11,1) | (-10,-10),(-30,-30) | (-0.1,-0.1),(-0.3,-0.3)
(0,7),(-2,5) | (6,-1),(4,-3) | (-7,3),(-21,1) | (0.12,-0.28),(0.04,-0.84)
(8.1,37.5),(6.1,35.5) | (-2.1,-31.5),(-4.1,-33.5) | (-29.4,118.8),(-88.2,39.6) | (0.0976764836465887,-0.0241724631246608),(0.0325588278821962,-0.0725173893739825)
(-2,-9),(-4,-11) | (8,15),(6,13) | (21,-17),(7,-51) | (-0.100591715976331,0.124260355029586),(-0.301775147928994,0.0414201183431953)
(-7.5,3.5),(-7.5,2.5) | (12.5,3.5),(12.5,2.5) | (-25,-25),(-25,-35) | (-0.25,-0.25),(-0.25,-0.35)
(-0.5,7.5),(-0.5,6.5) | (5.5,-0.5),(5.5,-1.5) | (-17.5,2.5),(-21.5,-0.5) | (0.26,-0.7),(0.1,-0.82)
(7.6,38),(7.6,37) | (-2.6,-31),(-2.6,-32) | (-73.5,104.1),(-108,99) | (0.109762715208919,-0.0562379754328844),(0.0813970697054906,-0.0604311578116521)
(-2.5,-8.5),(-2.5,-9.5) | (7.5,15.5),(7.5,14.5) | (29.5,-42.5),(17.5,-47.5) | (-0.251479289940828,0.103550295857988),(-0.322485207100592,0.0739644970414201)
(-7.5,3.5),(-7.5,2.5) | (12.5,3.5),(12.5,2.5) | (-25,-25),(-25,-35) | (-0.25,-0.25),(-0.25,-0.35)
(-0.5,7.5),(-0.5,6.5) | (5.5,-0.5),(5.5,-1.5) | (-17.5,2.5),(-21.5,-0.5) | (0.26,-0.7),(0.1,-0.82)
(7.6,38),(7.6,37) | (-2.6,-31),(-2.6,-32) | (-73.5,104.1),(-108,99) | (0.109762715208919,-0.0562379754328844),(0.0813970697054906,-0.0604311578116521)
(-2.5,-8.5),(-2.5,-9.5) | (7.5,15.5),(7.5,14.5) | (29.5,-42.5),(17.5,-47.5) | (-0.251479289940828,0.103550295857988),(-0.322485207100592,0.0739644970414201)
(-7,3),(-7,3) | (13,3),(13,3) | (-30,-30),(-30,-30) | (-0.3,-0.3),(-0.3,-0.3)
(0,7),(0,7) | (6,-1),(6,-1) | (-21,3),(-21,3) | (0.12,-0.84),(0.12,-0.84)
(8.1,37.5),(8.1,37.5) | (-2.1,-31.5),(-2.1,-31.5) | (-88.2,118.8),(-88.2,118.8) | (0.0976764836465887,-0.0725173893739825),(0.0976764836465887,-0.0725173893739825)
(-2,-9),(-2,-9) | (8,15),(8,15) | (21,-51),(21,-51) | (-0.301775147928994,0.124260355029586),(-0.301775147928994,0.124260355029586)
(-7,3),(-7,3) | (13,3),(13,3) | (-30,-30),(-30,-30) | (-0.3,-0.3),(-0.3,-0.3)
(0,7),(0,7) | (6,-1),(6,-1) | (-21,3),(-21,3) | (0.12,-0.84),(0.12,-0.84)
(8.1,37.5),(8.1,37.5) | (-2.1,-31.5),(-2.1,-31.5) | (-88.2,118.8),(-88.2,118.8) | (0.0976764836465887,-0.0725173893739825),(0.0976764836465887,-0.0725173893739825)
(-2,-9),(-2,-9) | (8,15),(8,15) | (21,-51),(21,-51) | (-0.301775147928994,0.124260355029586),(-0.301775147928994,0.124260355029586)
(32 rows)
drop table pl_box cascade;
create table pl_box (
p point, dp float, d0 float, c circle, w float, h float
);
create or replace function box_val(box[]) returns setof pl_box as '
p = Point.new(6,4)
args[0].each do |b|
p0 = b.center
yield [p0, Geometry::distance(p, b),Geometry::distance(p, p0),
b.to_circle, b.height, b.width]
end
' language 'plruby';
select * from
box_val('{(2.0,2.0,0.0,0.0);(1.0,1.0,3.0,3.0);(2.5,2.5,2.5,3.5);(3.0,3.0,3.0,3.0)}'::box[]);
p | dp | d0 | c | w | h
---------+------------------+------------------+-------------------------+---+---
(1,1) | 4.47213595499958 | 5.8309518948453 | <(1,1),1.4142135623731> | 2 | 2
(2,2) | 3.16227766016838 | 4.47213595499958 | <(2,2),1.4142135623731> | 2 | 2
(2.5,3) | 3.53553390593274 | 3.64005494464026 | <(2.5,3),0.5> | 1 | 0
(3,3) | 3.16227766016838 | 3.16227766016838 | <(3,3),0> | 0 | 0
(4 rows)
drop table pl_box cascade;
create table pl_box (
nb int, ll float, pc bool
);
create or replace function path_val(path[]) returns setof pl_box as '
args[0].each do |b|
yield [b.npoints, b.length, b.closed?]
end
' language 'plruby';
select * from
path_val('{"[1,2,3,4]","(0,0),(3,0),(4,5),(1,6)","11,12,13,14,25,12"}'::path[]);
nb | ll | pc
----+------------------+----
2 | 2.82842712474619 | f
4 | 17.3440597040594 | t
3 | 28.9939521853426 | t
(3 rows)
drop table pl_box cascade;
create table pl_box (
p path, p0 path, p1 path
);
create or replace function path_val(path[]) returns setof pl_box as '
p0 = Point.new(6,7)
args[0].each do |b|
yield [b, b + p0, b - p0]
end
' language 'plruby';
select * from
path_val('{"[1,2,3,4]","(0,0),(3,0),(4,5),(1,6)","11,12,13,14,25,12"}'::path[]);
p | p0 | p1
---------------------------+------------------------------+-----------------------------------
[(1,2),(3,4)] | [(7,9),(9,11)] | [(-5,-5),(-3,-3)]
((0,0),(3,0),(4,5),(1,6)) | ((6,7),(9,7),(10,12),(7,13)) | ((-6,-7),(-3,-7),(-2,-2),(-5,-1))
((11,12),(13,14),(25,12)) | ((17,19),(19,21),(31,19)) | ((5,5),(7,7),(19,5))
(3 rows)
drop table pl_box cascade;
create table pl_box (
p path, p0 path, p1 path
);
create or replace function path_val(path[]) returns setof pl_box as '
p0 = Point.new(6,7)
args[0].each do |b|
yield [b, b * p0, b / p0]
end
' language 'plruby';
select * from
path_val('{"[1,2,3,4]","(0,0),(3,0),(4,5),(1,6)","11,12,13,14,25,12"}'::path[]);
p | p0 | p1
---------------------------+-----------------------------------+-----------------------------------------------------------------------------------------------------------------------------
[(1,2),(3,4)] | [(-8,19),(-10,45)] | [(0.235294117647059,0.0588235294117647),(0.541176470588235,0.0352941176470588)]
((0,0),(3,0),(4,5),(1,6)) | ((0,0),(18,21),(-11,58),(-36,43)) | ((0,0),(0.211764705882353,-0.247058823529412),(0.694117647058824,0.0235294117647059),(0.564705882352941,0.341176470588235))
((11,12),(13,14),(25,12)) | ((-18,149),(-20,175),(66,247)) | ((1.76470588235294,-0.0588235294117647),(2.07058823529412,-0.0823529411764706),(2.75294117647059,-1.21176470588235))
(3 rows)
drop table pl_box cascade;
create table pl_box (
center point, area float, radius float, diameter float
);
create or replace function circle_val(circle[]) returns setof pl_box as '
args[0].each do |b|
yield b.center, b.area, b.radius, b.diameter
end
' language 'plruby';
select * from
circle_val('{"<(5,1),3>","<(1,2),100>","<(100,200),10>","<(100,1),115>","1,3,5"}'::circle[]);
center | area | radius | diameter
-----------+----------------+--------+----------
(5,1) | 28.2743338824 | 3 | 6
(1,2) | 31415.926536 | 100 | 200
(100,200) | 314.15926536 | 10 | 20
(100,1) | 41547.56284386 | 115 | 230
(1,3) | 78.53981634 | 5 | 10
(5 rows)
drop table pl_box cascade;
create table pl_box (
p circle, p0 circle, p1 circle
);
create or replace function circle_val(circle[]) returns setof pl_box as '
p0 = Point.new(6,7)
args[0].each do |b|
yield [b, b + p0, b - p0]
end
' language 'plruby';
select * from
circle_val('{"<(5,1),3>","<(1,2),100>","<(100,200),10>","<(100,1),115>","1,3,5"}'::circle[]);
p | p0 | p1
----------------+----------------+---------------
<(5,1),3> | <(11,8),3> | <(-1,-6),3>
<(1,2),100> | <(7,9),100> | <(-5,-5),100>
<(100,200),10> | <(106,207),10> | <(94,193),10>
<(100,1),115> | <(106,8),115> | <(94,-6),115>
<(1,3),5> | <(7,10),5> | <(-5,-4),5>
(5 rows)
drop table pl_box cascade;
create table pl_box (
p circle, p0 circle, p1 circle
);
create or replace function circle_val(circle[]) returns setof pl_box as '
p0 = Point.new(6,7)
args[0].each do |b|
yield [b, p0 * b, p0 / b ]
end
' language 'plruby';
select * from
circle_val('{"<(5,1),3>","<(1,2),100>","<(100,200),10>","<(100,1),115>","1,3,5"}'::circle[]);
p | p0 | p1
----------------+--------------------------------+------------------------------------------------------------
<(5,1),3> | <(23,41),27.6586333718787> | <(0.435294117647059,-0.341176470588235),0.325395686727984>
<(1,2),100> | <(-8,19),921.954445729289> | <(0.235294117647059,0.0588235294117647),10.8465228909328>
<(100,200),10> | <(-800,1900),92.1954445729289> | <(23.5294117647059,5.88235294117647),1.08465228909328>
<(100,1),115> | <(593,706),1060.24761258868> | <(7.14117647058824,-8.16470588235294),12.4735013245727>
<(1,3),5> | <(-15,25),46.0977222864644> | <(0.317647058823529,0.129411764705882),0.54232614454664>
(5 rows)
drop table pl_box cascade;
create table pl_box (
overlap bool, overleft bool, overright bool,
bleft bool, bright bool, below bool, above bool
);
create or replace function circle_val(circle, circle) returns setof pl_box as '
b0 = args[0]
b1 = args[1]
yield b0.overlap?(b1), b0.overleft?(b1), b0.overright?(b1),
b0.left?(b1), b0.right?(b1), b0.below?(b1), b0.above?(b1)
' language 'plruby';
select * from
circle_val('<(5,1),3>'::circle, '<(1,2),100>'::circle);
overlap | overleft | overright | bleft | bright | below | above
---------+----------+-----------+-------+--------+-------+-------
t | t | t | f | f | f | f
(1 row)
select * from
circle_val('<(100,200),10>'::circle, '<(100,1),115>'::circle);
overlap | overleft | overright | bleft | bright | below | above
---------+----------+-----------+-------+--------+-------+-------
f | t | t | f | f | f | t
(1 row)
|