Skip to content

Instantly share code, notes, and snippets.

@pgp44
Created April 14, 2019 05:15
Show Gist options
  • Save pgp44/f6f8fd1243b12a66b55deeef3282c145 to your computer and use it in GitHub Desktop.
Save pgp44/f6f8fd1243b12a66b55deeef3282c145 to your computer and use it in GitHub Desktop.
largesttriangle(grp,p) as (
select
wga.grp,
((0,0),(wga.x,wga.y),(0,0),0.0)::triangle_t
from withgrpavg wga
where grp = 1
union all
select distinct
wga.grp,
(largest_triangle(
(ltt.p).p2, -- the selected point of the previous bucket
(wga.x,wga.y), -- current bucket
(wga.xavg3,wga.yavg3)::triangle_t -- average of next bucket
) over (partition by wga.grp)
from withgrpavg wga join largesttriangle ltt on wga.grp=ltt.grp+1
where wga.grp > 1
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment