bool intersects(const LineSegment<type>& l1, const LineSegment<type>& l2) {
  if(l1.isDegenerate() || l2.isDegenerate()) {
    return false;
  }
  type t = -(dot(l2.getNormal(), l1.getPoint1())+l2.getOffset())/dot(l2.getNormal(), l1.getDirection());
  if(t < 0 || t > 1) {
    return false;
  }
  t = -(dot(l1.getNormal(), l2.getPoint1())+l1.getOffset())/dot(l1.getNormal(), l2.getDirection());
  if(t < 0 || t > 1) {
    return false;
  }
  return true;
}
bool intersects(typename LineSegment<type>::Point& i, const LineSegment<type>& l1, const LineSegment<type>& l2) {
  if(l1.m_degenerate || l2.m_degenerate) {
    return false;
  }
  type t = -(dot(l2.getNormal(), l1.getPoint1)+l2.getOffset())/dot(l2.getNormal(), l1.getDirection());
  if(t < 0 || t > 1) {
    return false;
  }
  t = -(dot(l1.getNormal(), l2.getPoint1())+l1.getOffset())/dot(l1.getNormal(), l2.getDirection());
  if(t < 0 || t > 1) {
    return false;
  }
  i = lerp(l2.getPoint1(), l2.getPoint2(), t);      
  return true;
}