         ), center AS (
             -- get centroid of polygon defined by N,E,S,W extreme points
             SELECT
-            ST_Centroid(ST_ConvexHull(ST_Collect(p))) AS c
+            ST_Centroid(ST_ExteriorRing(ST_Envelope(ST_Collect(p)))) AS c
             FROM unpacked
         ), sorted_cw AS (
             -- sort extreme points clock-wise
             SELECT
             a.p AS way
             FROM unpacked a, center b
-            ORDER BY -ST_Azimuth(b.c, a.p)
+            ORDER BY ST_Azimuth(b.c, a.p)
         )
         SELECT array_agg(way)
         FROM sorted_cw

        FROM close_pair a, other_extreme b
    );


    INSERT INTO support(way) SELECT ST_MakeLine(rc2[1], rc2[3]);
    INSERT INTO support(way) SELECT ST_MakeLine(rc2[2], rc2[3]);

    IF  rc2[2] = nesw[2] THEN
        RAISE NOTICE 'north cut';
    END IF;

    -- INSERT INTO support(way)
    -- SELECT ST_MakeLine(a.on_road, a.on_parcel)
    -- FROM close_pair a
    -- UNION
    -- SELECT ST_MakeLine(a.on_road, b.on_parcel)
    -- FROM close_pair a, other_extreme b;


    -- TODO: need to take the decision here on which
    -- direction to sweep in

    RETURN retval;
END;
$$ LANGUAGE plpgsql;


-- TODO: implement and use this function in pseudo_parcel
-- label boundary points with indicators based on which edge of the bounding
-- box they're on
CREATE OR REPLACE FUNCTION get_nesw(ps geometry[]) RETURNS void AS $$
DECLARE
BEGIN
    -- the way we're going to label points is as follows
    -- we're going to check whether they have YMax or YMin
    -- and add an 'N' or 'S' and then we're going to check if they have
    -- an XMin or XMax and add an 'W' or 'E'
END;
$$ LANGUAGE plpgsql;

-- this function will implement the corner-cut algorithm
CREATE OR REPLACE FUNCTION pseudo_parcel(p_uid integer, area integer) RETURNS void AS $$
DECLARE
bbox    geometry;
