added sweep line algorithm