Example #1
0
void visibility_points(struct Point *points, int num_points,
		       struct Line *lines, int num_lines,
		       struct Map_info *out, int n)
{

    int i, j, k;

    double x1, y1, z1, x2, y2, z2;

    /* loop through the points to add */
    for (i = 0; i < n; i++) {
	/* loop through the other points */
	for (j = 0; j < num_points - n; j++) {

	    /* loop trhough the lines */
	    for (k = 0; k < num_lines; k++) {
		if (segment1(&points[j]) == &lines[k] ||
		    segment2(&points[j]) == &lines[k])
		    continue;
		if (Vect_segment_intersection
		    (points[num_points - i - 1].x,
		     points[num_points - i - 1].y, 0, points[j].x,
		     points[j].y, 0, lines[k].p1->x, lines[k].p1->y, 0,
		     lines[k].p2->x, lines[k].p2->y, 0, &x1, &y1, &z1, &x2,
		     &y2, &z2, 0) != 0)
		    break;
	    }

	    if (k == num_lines)
		report(&points[num_points - i - 1], &points[j], out);
	}
    }
}
//mMutexp should be locked before calling this.
LLBufferArray::segment_iterator_t LLBufferArray::splitAfter(U8* address)
{
	ASSERT_LLBUFFERARRAY_MUTEX_LOCKED

	segment_iterator_t end = mSegments.end();
	segment_iterator_t it = getSegment(address);
	if(it == end)
	{
		return end;
	}

	// We have the location and the segment.
	U8* base = (*it).data();
	S32 size = (*it).size();
	if(address == (base + size - 1))
	{
		// No need to split, since this is the last byte of the
		// segment. We do not want to have zero length segments, since
		// that will only incur processing overhead with no advantage.
		return it;
	}
	S32 channel = (*it).getChannel();
	LLSegment segment1(channel, base, (address - base) + 1);
	*it = segment1;
	segment_iterator_t rv = it;
	++it;
	LLSegment segment2(channel, address + 1, size - (address - base) - 1);
	mSegments.insert(it, segment2);
	return rv;
}
Example #3
0
PSchedule Schedule :: schedulePartialyEarlyParallel
(ActiveList *activeList,
 const vector<Resource *> *resources,
 vector<Job *> :: const_iterator minIterator,
 vector<Job *> :: const_iterator maxIterator,
 const map<Job *, int> *starts,
 function<PVectorJobs(PARAMETERS_OF_SELECTING_FUNCTION)> &functionForSelecting)
{
    PSchedule schedule(new Schedule(activeList, resources));
    schedule->_type = ScheduleTypeEarlyComposite;
    
    vector<Job *> segment1(activeList->jobList()->begin(), minIterator);
    vector<Job *> segment2(minIterator, maxIterator + 1);
    vector<Job *> segment3(maxIterator + 1, activeList->jobList()->end());
    
    // segment1
    
    for (Job *job : segment1) {
        auto iterator = starts->find(job);
        if (iterator != starts->end()) schedule->_starts[job] = iterator->second;
        else return PSchedule(nullptr);
        schedule->reduceResourceRemain(job);
    }
    
    // segment 2
    
    schedule->addJobsOnScheduleViaEarlyParallelDecoder(segment2, functionForSelecting);
    
    // segment 3
    
    schedule->addJobsOnScheduleViaEarlyDecoder(&segment3);
    
    return schedule;
}
Example #4
0
TEST(RangeStrideSegmentTest, strongly_typed)
{
  RAJA::TypedRangeStrideSegment<StrongType> segment1(
      0, 7, 3);  // should produce 0,3,6
  ASSERT_EQ(segment1.size(), 3);

  RAJA::TypedRangeStrideSegment<StrongType> segment2(
      0, 13, 3);  // should produce 0,3,6,9,12
  ASSERT_EQ(segment2.size(), 5);

  RAJA::TypedRangeStrideSegment<StrongType> segment3(
      0, 17, 5);  // should produce 0,5,10,15
  ASSERT_EQ(segment3.size(), 4);

  std::vector<int> values(7, 0);
  RAJA::forall<RAJA::seq_exec>(segment1, [&](StrongType i) { values[*i] = 1; });

  ASSERT_EQ(values[0], 1);
  ASSERT_EQ(values[1], 0);
  ASSERT_EQ(values[2], 0);
  ASSERT_EQ(values[3], 1);
  ASSERT_EQ(values[4], 0);
  ASSERT_EQ(values[5], 0);
  ASSERT_EQ(values[6], 1);
}
Example #5
0
TEST(RangeStrideSegmentTest, sizes_primes)
{
  RAJA::RangeStrideSegment segment1(0, 7, 3);  // should produce 0,3,6
  ASSERT_EQ(segment1.size(), 3);

  RAJA::RangeStrideSegment segment2(0, 13, 3);  // should produce 0,3,6,9,12
  ASSERT_EQ(segment2.size(), 5);

  RAJA::RangeStrideSegment segment3(0, 17, 5);  // should produce 0,5,10,15
  ASSERT_EQ(segment3.size(), 4);
}
Example #6
0
PSchedule Schedule :: schedulePartialyLateParallel
(ActiveList *activeList,
 const vector<Resource *> *resources,
 vector<Job *> :: const_iterator minIterator,
 vector<Job *> :: const_iterator maxIterator,
 const map<Job *, int> *starts,
 function<PVectorJobs(PARAMETERS_OF_SELECTING_FUNCTION)> &functionForSelecting)
{
    PSchedule schedule(new Schedule(activeList, resources));
    schedule->_type = ScheduleTypeLateComposite;
    
    vector<Job *> segment1(activeList->jobList()->begin(), minIterator);
    vector<Job *> segment2(minIterator, maxIterator + 1);
    vector<Job *> segment3(maxIterator + 1, activeList->jobList()->end());
    
    // segment3
    
    for (Job *job : segment3) {
        auto iterator = starts->find(job);
        if (iterator != starts->end()) schedule->_starts[job] = iterator->second;
        else return PSchedule(nullptr);
        schedule->reduceResourceRemain(job);
    }
    
    // Move schedule to ending at far time
    
    int maxEnd = INT_MIN;
    for (auto &jobStart : schedule->_starts) {
        int end = jobStart.second + jobStart.first->duration();
        if (end > maxEnd) maxEnd = end;
    }
    schedule->shift(activeList->duration() - maxEnd);
    
    // segment 2
    
    schedule->addJobsOnScheduleViaLateParallelDecoder(segment2, functionForSelecting);
    
    // segment 1
    
    schedule->addJobsOnScheduleViaLateDecoder(&segment1);
    
    // Move schedule to starting at zero time
    
    int start = INT_MAX;
    for (auto &jobStart : schedule->_starts) {
        if (jobStart.second < start) start = jobStart.second;
    }
    schedule->shift(-start);
    
    return schedule;
}
Example #7
0
TEST(RangeStrideSegmentTest, sizes_roundoff1)
{
  RAJA::RangeStrideSegment segment2(0, 21, 2);
  ASSERT_EQ(segment2.size(), 11);

  RAJA::RangeStrideSegment segment3(0, 21, 4);
  ASSERT_EQ(segment3.size(), 6);

  RAJA::RangeStrideSegment segment4(0, 21, 5);
  ASSERT_EQ(segment4.size(), 5);

  RAJA::RangeStrideSegment segment5(0, 21, 10);
  ASSERT_EQ(segment5.size(), 3);

  RAJA::RangeStrideSegment segment6(0, 21, 20);
  ASSERT_EQ(segment6.size(), 2);
}
Example #8
0
TEST(RangeStrideSegmentTest, sizes_reverse_roundoff1)
{
  RAJA::RangeStrideSegment segment2(20, -1, -2);
  ASSERT_EQ(segment2.size(), 11);

  RAJA::RangeStrideSegment segment3(20, -1, -4);
  ASSERT_EQ(segment3.size(), 6);

  RAJA::RangeStrideSegment segment4(20, -1, -5);
  ASSERT_EQ(segment4.size(), 5);

  RAJA::RangeStrideSegment segment5(20, -1, -10);
  ASSERT_EQ(segment5.size(), 3);

  RAJA::RangeStrideSegment segment6(20, -1, -20);
  ASSERT_EQ(segment6.size(), 2);
}
Example #9
0
TEST(RangeStrideSegmentTest, basic_types)
{
  RAJA::TypedRangeStrideSegment<signed char> segment1(0, 31, 3);
  ASSERT_EQ(segment1.size(), 11);

  RAJA::TypedRangeStrideSegment<short> segment2(0, 31, 3);
  ASSERT_EQ(segment2.size(), 11);

  RAJA::TypedRangeStrideSegment<int> segment3(0, 31, 3);
  ASSERT_EQ(segment3.size(), 11);

  RAJA::TypedRangeStrideSegment<long> segment4(0, 31, 3);
  ASSERT_EQ(segment3.size(), 11);

  RAJA::TypedRangeStrideSegment<long long> segment5(0, 31, 3);
  ASSERT_EQ(segment3.size(), 11);
}
Example #10
0
TEST(RangeStrideSegmentTest, sizes_no_roundoff)
{
  RAJA::RangeStrideSegment segment1(0, 20, 1);
  ASSERT_EQ(segment1.size(), 20);

  RAJA::RangeStrideSegment segment2(0, 20, 2);
  ASSERT_EQ(segment2.size(), 10);

  RAJA::RangeStrideSegment segment3(0, 20, 4);
  ASSERT_EQ(segment3.size(), 5);

  RAJA::RangeStrideSegment segment4(0, 20, 5);
  ASSERT_EQ(segment4.size(), 4);

  RAJA::RangeStrideSegment segment5(0, 20, 10);
  ASSERT_EQ(segment5.size(), 2);

  RAJA::RangeStrideSegment segment6(0, 20, 20);
  ASSERT_EQ(segment6.size(), 1);
}
Example #11
0
TEST(RangeStrideSegmentTest, sizes_reverse_no_roundoff)
{
  RAJA::RangeStrideSegment segment1(19, -1, -1);
  ASSERT_EQ(segment1.size(), 20);

  RAJA::RangeStrideSegment segment2(19, -1, -2);
  ASSERT_EQ(segment2.size(), 10);

  RAJA::RangeStrideSegment segment3(19, -1, -4);
  ASSERT_EQ(segment3.size(), 5);

  RAJA::RangeStrideSegment segment4(19, -1, -5);
  ASSERT_EQ(segment4.size(), 4);

  RAJA::RangeStrideSegment segment5(19, -1, -10);
  ASSERT_EQ(segment5.size(), 2);

  RAJA::RangeStrideSegment segment6(19, -1, -20);
  ASSERT_EQ(segment6.size(), 1);
}
Example #12
0
/** for all points initiate their vis line to the one directly below
*/
void init_vis(struct Point *points, int num_points, struct Line *lines,
	      int num_lines)
{
    int i;
    double d;
    struct avl_table *tree = avl_create(cmp_points, NULL, NULL);
    struct avl_traverser it;
    struct Point *p;

    double y1, y2;

    struct Point *s1, *s2;

    for (i = 0; i < num_points; i++) {

	points[i].vis = NULL;
	d = PORT_DOUBLE_MAX;

	avl_t_init(&it, tree);

	/* loop through the tree */
	while ((p = avl_t_next(&it)) != NULL) {
	    if (segment1(p) == NULL && segment2(p) == NULL)
		continue;

	    /* test for intersection and get the intersecting point */
	    if (segment1(p) != NULL &&
		segment_intersect(segment1(p), &points[i], &y1) > -1) {
		/* find the closest one below */
		if (y1 < points[i].y && (points[i].y - y1) < d) {
		    d = points[i].y - y1;
		    points[i].vis = segment1(p);

		}
	    }


	    if (segment2(p) != NULL &&
		segment_intersect(segment2(p), &points[i], &y2) > -1) {
		if (y2 < points[i].y && (points[i].y - y2) < d) {
		    d = points[i].y - y2;
		    points[i].vis = segment2(p);
		}
	    }

	}			/* end loop */

	s1 = s2 = NULL;

	/* now if the other point is on the right, we can delete it */
	if (segment1(&points[i]) != NULL &&
	    cmp_points(&points[i], other1(&points[i]), NULL) > 0) {
	    p = other1(&points[i]);

	    /* unless the other point of it is on the left */
	    if (segment1(p) != NULL && other1(p) != &points[i] &&
		cmp_points(&points[i], other1(p), NULL) > 0)
		s1 = avl_delete(tree, p);
	    else if (segment2(p) != NULL && other2(p) != &points[i] &&
		     cmp_points(&points[i], other2(p), NULL) > 0)
		s1 = avl_delete(tree, p);
	}

	/* now if the other point is on the right, we can delete it */
	if (segment2(&points[i]) != NULL &&
	    cmp_points(&points[i], other2(&points[i]), NULL) > 0) {
	    p = other2(&points[i]);

	    /* unless the other point of it is on the left */
	    if (segment1(p) != NULL && other1(p) != &points[i] &&
		cmp_points(&points[i], other1(p), NULL) > 0)
		s2 = avl_delete(tree, p);
	    else if (segment2(p) != NULL && other2(p) != &points[i] &&
		     cmp_points(&points[i], other2(p), NULL) > 0)
		s2 = avl_delete(tree, p);
	}

	/* if both weren't deleted, it means there is at least one other
	   point on the left, so add the current */
	/* also there is no point adding the point if there is no segment attached to it */
	if ((s1 == NULL || s2 == NULL)) {
	    avl_insert(tree, &points[i]);
	}
    }


    avl_destroy(tree, NULL);
}
Example #13
0
/** for a pair (p, q) of points, add the edge pq if their are visible to each other
*/
void handle(struct Point *p, struct Point *q, struct Map_info *out)
{

    /* if it's a point without segments, just report the edge */
    if (segment1(q) == NULL && segment2(q) == NULL && before(p, q, p->vis)) {
	report(p, q, out);
    }
    else if (segment1(p) != NULL && q == other1(p)) {
	/* we need to check if there is another segment at q so it can be set to the vis */
	if (segment1(q) == segment1(p) && segment2(q) != NULL &&
	    left_turn(p, q, other2(q))) {
	    p->vis = segment2(q);
	}
	else if (segment2(q) == segment1(p) && segment1(q) != NULL &&
		 left_turn(p, q, other1(q))) {
	    p->vis = segment1(q);
	}
	else
	    p->vis = q->vis;

	report(p, q, out);
    }
    else if (segment2(p) != NULL && q == other2(p)) {
	/* we need to check if there is another segment at q so it can be set to the vis */
	if (segment1(q) == segment2(p) && segment2(q) != NULL &&
	    left_turn(p, q, other2(q))) {
	    p->vis = segment2(q);
	}
	else if (segment2(q) == segment2(p) && segment1(q) != NULL &&
		 left_turn(p, q, other1(q))) {
	    p->vis = segment1(q);
	}
	else
	    p->vis = q->vis;

	report(p, q, out);
    }
    else if (segment1(q) == p->vis && segment1(q) != NULL) {
	/* we need to check if there is another segment at q so it can be set to the vis */
	if (segment2(q) != NULL && left_turn(p, q, other2(q)))
	    p->vis = segment2(q);
	else
	    p->vis = q->vis;

	/* check that p and q are not on the same boundary and that the edge pq is inside the boundary */
	if (p->cat == -1 || p->cat != q->cat ||
	    !point_inside(p, (p->x + q->x) * 0.5, (p->y + q->y) * 0.5))
	    report(p, q, out);
    }
    else if (segment2(q) == p->vis && segment2(q) != NULL) {
	/* we need to check if there is another segment at q so it can be set to the vis */
	if (segment1(q) != NULL && left_turn(p, q, other1(q)))
	    p->vis = segment1(q);
	else
	    p->vis = q->vis;

	/* check that p and q are not on the same boundary and that the edge pq is inside the boundary */
	if (p->cat == -1 || p->cat != q->cat ||
	    !point_inside(p, (p->x + q->x) * 0.5, (p->y + q->y) * 0.5))
	    report(p, q, out);
    }
    else if (before(p, q, p->vis)) {
	/* if q only has one segment, then this is the new vis */
	if (segment2(q) == NULL)
	    p->vis = segment1(q);
	else if (segment1(q) == NULL)
	    p->vis = segment2(q);

	/* otherwise take the one with biggest slope */
	else if (left_turn(p, q, other1(q)) && !left_turn(p, q, other2(q)))
	    p->vis = segment1(q);
	else if (!left_turn(p, q, other1(q)) && left_turn(p, q, other2(q)))
	    p->vis = segment2(q);
	else if (left_turn(q, other2(q), other1(q)))
	    p->vis = segment1(q);
	else
	    p->vis = segment2(q);

	/* check that p and q are not on the same boundary and that the edge pq is inside the boundary */
	if (p->cat == -1 || p->cat != q->cat ||
	    !point_inside(p, (p->x + q->x) * 0.5, (p->y + q->y) * 0.5))
	    report(p, q, out);
    }
}