         var x:Number;
         var y:Number;
         
-        if (d1 != 0)
+        if (d1 != 0 && preferredX > 0)
         {
             const invD1:Number = 1 / d1;
+            preferredX = Math.max(minX, Math.min(maxX, preferredX));
             x = preferredX;
             
             // Case1:

            return null; // No solution
        
        // Handle special cases first
        if (b == 0)
            return new Point( preferredX, h / Math.abs(d) );               
        else if (d == 0)

            }
        }
        
        if (b != 0 && preferredY > 0)
        {
            const invB:Number = 1 / b;
            preferredY = Math.max(minY, Math.min(maxY, preferredY));
            y = preferredY;
            
            // Case3:
