         IF ABS(tarea - area) < 0.001 THEN
             RAISE NOTICE 'found split with reasonably close area';
             RAISE NOTICE 'delta for split: %', ABS(tarea-area);
+            EXIT;
+        END IF;
+        
+        IF titer > 70 THEN
+            RAISE NOTICE 'exceeded search iterations';
             RETURN NULL;
+        END IF;
+
+        titer := titer + 1;
+    END LOOP;
+
+    RETURN tline;
+END;
+$$ LANGUAGE plpgsql;
+
+
+
+-- same as hcut_search except the cut line is vertical here
+CREATE OR REPLACE FUNCTION vcut_search(poly geometry, leftright integer, area float, bxmin float, bxmax float, bymin float, bymax float) RETURNS geometry AS $$
+DECLARE
+-- width of bounding box;
+bwidth    float;
+-- length of bounding box;
+bheight   float;
+-- trial cursor will be between [0,bwidth] or between [0,bheight]
+tlow      float;
+tmid      float;
+thigh     float;
+-- trial cut area
+tarea     float;
+-- trial sweep line
+tline     geometry;
+-- tsplit
+tsplit    geometry[];
+-- iteration number
+titer     integer;
+cutline   geometry; 
+BEGIN
+    bwidth  := bxmax - bxmin;
+    bheight := bymax - bymin;
+
+    -- setting up the sweep line bsearch.
+    -- we're looking for a cut between [0, bwidth]
+    -- (analogous situation for vertical sweep-line).
+
+    -- north-south sweep line (this is a horizontal line that travels in north-south direction)
+    cutline := ST_SetSRID(ST_MakeLine(ST_MakePoint(bxmin,bymin), ST_MakePoint(bxmin,bymax)), 900913);
+    titer := 0;
+    tlow  := 0;
+    thigh := bwidth;
+
+    WHILE tlow < thigh LOOP
+        -- RAISE NOTICE 'loop';
+        tmid    := (tlow + thigh)/2;
+        -- try a new position for the cut
+        tline   := ST_Translate(cutline,tmid,0);
+
+        -- split with horizontal line, we might
+        -- get back more than two pieces (depending on the shape of poly).
+        -- so we need to collect those on the left, and those on the right
+        -- of the cut.
+        tsplit  := (
+            WITH parts AS (
+                SELECT 
+                a.piece
+                FROM (
+                    SELECT ((ST_Dump((ST_Split(poly, tline)))).geom) AS piece
+                ) a
+            ), L AS (
+                SELECT
+                ST_Multi(ST_Collect(piece)) AS shape
+                FROM parts
+                WHERE ST_XMin(piece)  < ST_XMin(poly) + tmid
+            ), R AS (
+                SELECT
+                ST_Multi(ST_Collect(piece)) AS shape
+                FROM parts
+                WHERE ST_XMin(piece) >= ST_XMin(poly) + tmid
+            )
+            SELECT
+            ARRAY[L.shape, R.shape]
+            FROM L,R
+        );
+
+        -- RAISE NOTICE '%', array_dims(tsplit);
+
+        tarea := ST_Area(tsplit[leftright]);
+
+        -- re-adjust the range we're searching for the split
+        -- depending on overshot/undershot relatve to the target area.
+        IF    tarea > area AND leftright = 1 THEN
+            -- overshot  the left target area
+            thigh := tmid;
+        ELSIF tarea < area AND leftright = 1 THEN
+            -- undershot the left target area
+            tlow  := tmid;
+        ELSIF tarea > area AND leftright = 2 THEN
+            -- overshot  the right target area
+            tlow  := tmid;
+        ELSIF tarea < area AND leftright = 2 THEN
+            -- undershot the right target area
+            thigh := tmid;
+        END IF;
+
+        RAISE NOTICE 'area above split: %', tarea;
+        IF ABS(tarea - area) < 0.001 THEN
+            RAISE NOTICE 'found split with reasonably close area';
+            RAISE NOTICE 'delta for split: %', ABS(tarea-area);
+            EXIT;
         END IF;
         
         IF titer > 70 THEN


-- input:
-- receives as parameters the initial polygon, the desired area,
-- the x/y min/max of the bbox for the polygon.
--
-- output:

        RETURN NULL;
    END IF;

    IF p_area < target_area THEN
        -- the input polygon is too small and we won't be able to
        -- to find a parcel with the required area.
        RAISE NOTICE 'the polygon area is too small';
