예제 #1
0
int main()
{
    vec v1(1, 1), v2(0, 2);
    cout << "vec1(1,1) cross vec2(0,2): " << cross(v1, v2) << endl << endl;
    node p0(0, 0), p1(0, 1), p2(1, 2), p3(2, 1), p4(2, 0), p5(1, 0), p6(1, 1);
    node s[7];
    s[0] = p4, s[1] = p3, s[2] = p2, s[3] = p1, s[4] = p0, s[5] = p5, s[6] = p6;
    segment l0(p0, p3), l1(p5, p6), l2(p6, p4), l3(p1, p2);
    test_segment(l0, l1);
    test_segment(l1, l2);
    test_segment(l0, l3);

    segment ll[4];
    ll[0] = l0, ll[1] = l1, ll[2] = l2, ll[3] = l3;
    for(int i = 0; i < 4; ++ i) {
        ll[i].s_lt.n_idx = i;
        ll[i].s_rt.n_idx = i;
        ll[i].s_lt.n_lt = 1;
        ll[i].s_rt.n_lt = 0;
    }
    cout << "sweeping:" << endl;
    for(int i = 0; i < 4; ++ i)
        ll[i].s_print();
    if(sweeping(ll, 4))
        cout << "yes" << endl;
    else
        cout << "no" << endl;

    return(0);
}
void SegmentsTests<dimension>::run()
{
  VecD origin1 = random_vec<VecD>();
  VecD direction1 = random_vec<VecD>();
  geom::Point<dimension> point1( new typename geom::Point<dimension>::EuclideanDriver( random_vec<HomogenousVecD>() ) );
  geom::Point<dimension> point2( new typename geom::Point<dimension>::EuclideanDriver( random_vec<HomogenousVecD>() ) );
  
  // Test based on line
  geom::Line<dimension> line1( new typename geom::Line<dimension>::EuclideanDriver( origin1, direction1));
  
  double firstIndex = random_float();
  double lastIndex = random_float();
  SegmentD seg1( new typename SegmentD::LineDriver( &line1, firstIndex, lastIndex ) );
  test_segment_validity( seg1 );
  GEOM_CHECK_VEC_EQUAL( seg1.firstPoint(), line1.pointAt(firstIndex) );
  GEOM_CHECK_VEC_EQUAL( seg1.lastPoint(), line1.pointAt(lastIndex) );
  GEOM_CHECK_NULL( geom::angle(seg1, line1 ) );
  test_segment( seg1 );
  JFR_CHECK( !seg1.isTransformable() );
  // Test constructor based on two points
  SegmentD seg2( new typename SegmentD::TwoPointsPointerDriver( &point1, &point2 ) );
  test_segment_validity( seg2 );
  GEOM_CHECK_VEC_EQUAL( seg2.firstPoint(), point1.homogenousCoordinates() );
  GEOM_CHECK_VEC_EQUAL( seg2.lastPoint(), point2.homogenousCoordinates() );
  test_segment( seg2 );
  JFR_CHECK( !seg2.isTransformable() );
  // Test constructor based on two points
  SegmentD seg3( new typename SegmentD::TwoPointsDriver( point1.homogenousCoordinates(), point2.homogenousCoordinates() ) );
  test_segment_validity( seg3 );
  GEOM_CHECK_VEC_EQUAL( seg3.firstPoint(), point1.homogenousCoordinates() );
  GEOM_CHECK_VEC_EQUAL( seg3.lastPoint(), point2.homogenousCoordinates() );
  test_segment( seg3 );
  JFR_CHECK( seg3.isTransformable() );
  // Test transformability
  HomogenousMatrixD m = random_inversible_mat<dimension>();
  HomogenousMatrixD mInv;
  jmath::ublasExtra::inv( m, mInv );
  SegmentD seg3bis = seg3;
  seg3bis.applyTransformation( m );
  GEOM_CHECK_VEC_EQUAL( seg3bis.firstPoint(), ublas::prod(m, seg3.firstPoint() ) );
  GEOM_CHECK_VEC_EQUAL( seg3bis.lastPoint(), ublas::prod(m, seg3.lastPoint() ) );
  seg3bis.applyTransformation( mInv );
  GEOM_CHECK_VEC_EQUAL( seg3bis.firstPoint(), seg3.firstPoint() );
  GEOM_CHECK_VEC_EQUAL( seg3bis.lastPoint(), seg3.lastPoint() );
  
  // Test distance
  test_distance(seg1, seg2);
  test_distance(seg2, seg3);
  test_distance(seg1, seg3);
  test_distance(seg1, seg2.support());
  test_distance(seg1, seg3.support());
  test_distance(seg2, seg1.support());
  test_distance(seg2, seg3.support());
  test_distance(seg3, seg2.support());
  test_distance(seg3, seg1.support());
}
예제 #3
0
static int
segmented_read_tester(file_buffer_t *buffer, unsigned char *file_map)
{
	size_t bytes_read = 0;
	int reading_small = 0;

	debug_assert(LARGE_SIZE > LARGE_SEGMENT);
	while (bytes_read < LARGE_SIZE) {
		size_t segment_bytes_read = test_segment(buffer,
							 file_map,
							 reading_small,
							 bytes_read);

		if (segment_bytes_read == 0) {
			printlg(ERROR_LEVEL,
				"Failed reading segment at "
				"%u bytes into the file.\n",
				(unsigned) bytes_read);
			return 0;
		}
		bytes_read += segment_bytes_read;
		reading_small = !reading_small;
	}

	return 1;
}