コード例 #1
0
  void runTest()
  {
    BufferedLineSegmentIntersector uut;

    {
      LineSegment ls1(0, 0, 1, 1);
      LineSegment ls2(0, 0, 1, 1);
      LineSegment result;
      HOOT_STR_EQUALS(true, uut.intersect(ls1, 1, ls2, result));
      HOOT_STR_EQUALS("LINESEGMENT(0 0,1 1)",
                      result);
    }

    {
      LineSegment ls1(0, 1, 1, 0);
      LineSegment ls2(0, 0, 1, 1);
      LineSegment result;
      HOOT_STR_EQUALS(true, uut.intersect(ls1, .14142135623730950488016887242097, ls2, result));
      HOOT_STR_EQUALS("LINESEGMENT(0.4 0.4,0.6 0.6)",
                      result);
    }

    {
      LineSegment ls1(2, 0, 3, 2);
      LineSegment ls2(2, 0, 4, 4);
      LineSegment result;
      HOOT_STR_EQUALS(true, uut.intersect(ls1, .1, ls2, result));
      HOOT_STR_EQUALS("LINESEGMENT(2 0,3.04472 2.08944)", result);
    }
  }
コード例 #2
0
ファイル: MaximalSubline.cpp プロジェクト: giserh/hootenanny
void MaximalSubline::ThresholdMatchCriteria::matchingSubline(LineSegment &a, LineSegment &b) const
{
    BufferedLineSegmentIntersector bi;

    LineSegment sublineA, sublineB;
    bi.intersect(a, _maxDistance, b, sublineB);
    bi.intersect(b, _maxDistance, a, sublineA);

    a = sublineA;
    b = sublineB;
}
コード例 #3
0
  void runRandomTest()
  {
    BufferedLineSegmentIntersector uut;

    double scale = 5;

    double uutTime = 0.0;
    double geosTime = 0.0;
    // the geos intersection is an approximation so we need a fairly large epsilon
    double epsilon = 1e-2;
    size_t count = 1000;
    for (size_t i = 0; i < count; i++)
    {
      double r = Tgs::Random::instance()->generateUniform() * 3.0;
      LineSegment ls1(Tgs::Random::instance()->generateUniform() * scale,
                      Tgs::Random::instance()->generateUniform() * scale,
                      Tgs::Random::instance()->generateUniform() * scale,
                      Tgs::Random::instance()->generateUniform() * scale);
      LineSegment ls2(Tgs::Random::instance()->generateUniform() * scale,
                      Tgs::Random::instance()->generateUniform() * scale,
                      Tgs::Random::instance()->generateUniform() * scale,
                      Tgs::Random::instance()->generateUniform() * scale);

      LineSegment lsGeos;
      double start = Tgs::Time::getTime();
      bool resultGeos = geosIntersect(ls1, r, ls2, lsGeos);
      double end = Tgs::Time::getTime();
      geosTime += end - start;

      LineSegment lsUut;
      start = Tgs::Time::getTime();
      bool resultUut = uut.intersect(ls1, r, ls2, lsUut);
      end = Tgs::Time::getTime();
      uutTime += end - start;

      // if the line is very close to the buffer then we can't expect consistent results.
      bool touchy = fabs(ls1.distance(ls2) - r) <= epsilon;
      CPPUNIT_ASSERT_EQUAL(resultGeos || touchy, resultUut || touchy);
      if (resultGeos && !touchy)
      {
        CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, lsGeos.p0.distance(lsUut.p0), epsilon);
        CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, lsGeos.p1.distance(lsUut.p1), epsilon);
      }
    }

    LOG_INFO("GEOS Mean Time: " << (1000.0 * geosTime) / (double)count << "ms");
    LOG_INFO("UUT Mean Time: " << (1000.0 * uutTime) / (double)count << "ms");
    LOG_INFO("Ratio: " << geosTime / uutTime);
  }