Implemented a line-crossing detection algorithm