Skip to content

Commit

Permalink
performance tweak for clip
Browse files Browse the repository at this point in the history
  • Loading branch information
kallaballa committed Dec 1, 2014
1 parent 5d4a233 commit f8b535a
Showing 1 changed file with 47 additions and 45 deletions.
92 changes: 47 additions & 45 deletions src/ctrl-cut/cut/operations/Clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
void clip(Route& src, Route& sink, const Box& bounds) {
LOG_DEBUG(src.size());

for(const SegmentPtr segPtr : segments(src)) {
for (const SegmentPtr segPtr : segments(src)) {
Segment& seg = *segPtr.get();
double width = bounds.width();
double height = bounds.height();
Expand All @@ -29,65 +29,67 @@ void clip(Route& src, Route& sink, const Box& bounds) {
Point intersection;
Segment clipped = seg;

if (clipped.first.x < 0 || clipped.second.x < 0) {
// out of bounds;
if (clipped.first.x < 0 && clipped.second.x < 0) {
continue;
if (clipped.first.x < 0 || clipped.second.x < 0
|| clipped.first.y < 0 || clipped.second.y < 0
|| clipped.first.x > width - 1 || clipped.second.x > width - 1
|| clipped.first.y > height - 1 || clipped.second.y > height - 1) {
if (clipped.first.x < 0 || clipped.second.x < 0) {
// out of bounds;
if (clipped.first.x < 0 && clipped.second.x < 0) {
continue;
}

if (intersects(clipped, leftBedBorder, intersection) == ALIGN_INTERSECT) {
if (clipped.first.x >= clipped.second.x)
clipped.second = clipped.first;

clipped.first = intersection;
intersection = Point();
}
}

if (intersects(clipped, leftBedBorder, intersection) == ALIGN_INTERSECT) {
if (clipped.first.x >= clipped.second.x)
clipped.second = clipped.first;
if (clipped.first.y < 0 || clipped.second.y < 0) {
if (clipped.first.y < 0 && clipped.second.y < 0) {
continue;
}

clipped.first = intersection;
intersection = Point();
}
}

if (clipped.first.y < 0 || clipped.second.y < 0) {
if (clipped.first.y < 0 && clipped.second.y < 0) {
continue;
}

if (intersects(clipped, topBedBorder, intersection) == ALIGN_INTERSECT) {
if (clipped.first.y >= clipped.second.y)
clipped.second = clipped.first;
if (intersects(clipped, topBedBorder, intersection) == ALIGN_INTERSECT) {
if (clipped.first.y >= clipped.second.y)
clipped.second = clipped.first;

clipped.first = intersection;
clipped.first = intersection;

intersection = Point();
intersection = Point();
}
}
}

if (greater_than(clipped.first.x, width - 1)
|| greater_than(clipped.second.x, width - 1)) {
if (greater_than(clipped.first.x, width - 1)
&& greater_than(clipped.second.x, width - 1)) {
continue;
}
if (greater_than(clipped.first.x, width - 1) || greater_than(clipped.second.x, width - 1)) {
if (greater_than(clipped.first.x, width - 1) && greater_than(clipped.second.x, width - 1)) {
continue;
}

if (intersects(clipped, rightBedBorder, intersection) == ALIGN_INTERSECT) {
if (clipped.first.x <= clipped.second.x)
clipped.second = clipped.first;
if (intersects(clipped, rightBedBorder, intersection) == ALIGN_INTERSECT) {
if (clipped.first.x <= clipped.second.x)
clipped.second = clipped.first;

clipped.first = intersection;
clipped.first = intersection;

intersection = Point();
intersection = Point();
}
}
}

if (clipped.first.y > height - 1 || clipped.second.y > height - 1) {
if (clipped.first.y > height - 1 && clipped.second.y > height - 1) {
continue;
}
if (intersects(clipped, bottomBedBorder, intersection) == ALIGN_INTERSECT) {
if (clipped.first.y <= clipped.second.y)
if (clipped.first.y > height - 1 || clipped.second.y > height - 1) {
if (clipped.first.y > height - 1 && clipped.second.y > height - 1) {
continue;
}
if (intersects(clipped, bottomBedBorder, intersection) == ALIGN_INTERSECT) {
if (clipped.first.y <= clipped.second.y)

clipped.second = clipped.first;
clipped.first = intersection;
clipped.second = clipped.first;
clipped.first = intersection;
}
}
}

add(sink, clipped);
}
LOG_DEBUG(sink.size());
Expand Down

0 comments on commit f8b535a

Please sign in to comment.