code/include/k-regret/contour/geometry.hpp
/**
 * Given two 2d points, calculates the intersection point of their dual lines. Returns
 * std::nullopt if the lines are parallel (or coincident); i.e., have no unique
 * intersection point.
 */
Given two 2d points, calculates the intersection point of their dual lines. Returns
std::nullopt if the lines are parallel (or coincident); i.e., have no unique
intersection point.
Given two 2d points calculates the intersection point of their dual lines . Returns std :: nullopt if the lines are parallel ( or coincident ) ; i . e . have no unique intersection point .
inline
std::optional< Point< 2 > >
  dual_line_intersection( Point< 2 > const a, Point< 2 > const b )
  {
    auto const shift = a[ 0 ] * b[ 1 ] - b[ 0 ] * a[ 1 ];
    if( shift == 0 )  
    {
      return std::nullopt;
    }
    else if( a[ 1 ] == 0 ) 
    {
      assert( b[ 1 ] != 0.0f );
      return Point< 2 >{ a[ 0 ], ( 1.0f - b[ 0 ] * a[ 0 ] ) / b [ 1 ] };
    }
    else if( b[ 1 ] == 0 ) 
    {
      assert( a[ 1 ] != 0.0f );
      return Point< 2 >{ b[ 0 ], ( 1.0f - a[ 0 ] * b[ 0 ] ) / a [ 1 ] };
    }
    else
    {
      auto const y_diff = b[ 1 ] - a[ 1 ];
      auto const x = y_diff / shift;
      auto const y = ( 1.0f - a[ 0 ] * x ) / a [ 1 ];
      return Point< 2 >{ x, y };
    }
  }
inline std :: optional < Point < 2 > > dual_line_intersection ( Point < 2 > const a , Point < 2 > const b ) { auto const shift = a [ 0 ] * b [ 1 ] - b [ 0 ] * a [ 1 ] ; if ( shift == 0 ) { return std :: nullopt ; } else if ( a [ 1 ] == 0 ) { assert ( b [ 1 ] != 0.0f ) ; return Point < 2 > { a [ 0 ] , ( 1.0f - b [ 0 ] * a [ 0 ] ) / b [ 1 ] } ; } else if ( b [ 1 ] == 0 ) { assert ( a [ 1 ] != 0.0f ) ; return Point < 2 > { b [ 0 ] , ( 1.0f - a [ 0 ] * b [ 0 ] ) / a [ 1 ] } ; } else { auto const y_diff = b [ 1 ] - a [ 1 ] ; auto const x = y_diff / shift ; auto const y = ( 1.0f - a [ 0 ] * x ) / a [ 1 ] ; return Point < 2 > { x , y } ; } }
Given two 2d points, calculates the intersection point of their dual lines.
Given two 2d points calculates the intersection point of their dual lines .
/* parallel or coincident */ /* easy case: dual line of a is vertical */ /* another easy case: dual line of b is vertical */