OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 int aY = aSpan->y; | 124 int aY = aSpan->y; |
125 int aMaxY = (aSpan + 1)->y; | 125 int aMaxY = (aSpan + 1)->y; |
126 int bY = bSpan->y; | 126 int bY = bSpan->y; |
127 int bMaxY = (bSpan + 1)->y; | 127 int bMaxY = (bSpan + 1)->y; |
128 | 128 |
129 Shape::SegmentIterator aSegment = aShape.segmentsBegin(aSpan); | 129 Shape::SegmentIterator aSegment = aShape.segmentsBegin(aSpan); |
130 Shape::SegmentIterator aSegmentEnd = aShape.segmentsEnd(aSpan); | 130 Shape::SegmentIterator aSegmentEnd = aShape.segmentsEnd(aSpan); |
131 Shape::SegmentIterator bSegment = bShape.segmentsBegin(bSpan); | 131 Shape::SegmentIterator bSegment = bShape.segmentsBegin(bSpan); |
132 Shape::SegmentIterator bSegmentEnd = bShape.segmentsEnd(bSpan); | 132 Shape::SegmentIterator bSegmentEnd = bShape.segmentsEnd(bSpan); |
133 | 133 |
134 // Look for a non-overlapping part of the spans. If B had a segment in its p
revious span, then we already tested A against B within that span. | 134 // Look for a non-overlapping part of the spans. If B had a segment in its |
| 135 // previous span, then we already tested A against B within that span. |
135 bool aHasSegmentInSpan = aSegment != aSegmentEnd; | 136 bool aHasSegmentInSpan = aSegment != aSegmentEnd; |
136 bool bHasSegmentInSpan = bSegment != bSegmentEnd; | 137 bool bHasSegmentInSpan = bSegment != bSegmentEnd; |
137 if (aY < bY && !bHadSegmentInPreviousSpan && aHasSegmentInSpan && | 138 if (aY < bY && !bHadSegmentInPreviousSpan && aHasSegmentInSpan && |
138 CompareOperation::aOutsideB(result)) | 139 CompareOperation::aOutsideB(result)) |
139 return result; | 140 return result; |
140 if (bY < aY && !aHadSegmentInPreviousSpan && bHasSegmentInSpan && | 141 if (bY < aY && !aHadSegmentInPreviousSpan && bHasSegmentInSpan && |
141 CompareOperation::bOutsideA(result)) | 142 CompareOperation::bOutsideA(result)) |
142 return result; | 143 return result; |
143 | 144 |
144 aHadSegmentInPreviousSpan = aHasSegmentInSpan; | 145 aHadSegmentInPreviousSpan = aHasSegmentInSpan; |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 int flag = 0; | 444 int flag = 0; |
444 int oldFlag = 0; | 445 int oldFlag = 0; |
445 | 446 |
446 SegmentIterator s1 = segments1; | 447 SegmentIterator s1 = segments1; |
447 SegmentIterator s2 = segments2; | 448 SegmentIterator s2 = segments2; |
448 | 449 |
449 // Clear vector without dropping capacity. | 450 // Clear vector without dropping capacity. |
450 segments.resize(0); | 451 segments.resize(0); |
451 ASSERT(segments.capacity()); | 452 ASSERT(segments.capacity()); |
452 | 453 |
453 // Now iterate over the segments in each span and construct a new vector of
segments. | 454 // Now iterate over the segments in each span and construct a new vector of |
| 455 // segments. |
454 while (s1 != segments1End && s2 != segments2End) { | 456 while (s1 != segments1End && s2 != segments2End) { |
455 int test = *s1 - *s2; | 457 int test = *s1 - *s2; |
456 int x; | 458 int x; |
457 | 459 |
458 if (test <= 0) { | 460 if (test <= 0) { |
459 x = *s1; | 461 x = *s1; |
460 flag = flag ^ 1; | 462 flag = flag ^ 1; |
461 ++s1; | 463 ++s1; |
462 } | 464 } |
463 if (test >= 0) { | 465 if (test >= 0) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 void Region::unite(const Region& region) { | 587 void Region::unite(const Region& region) { |
586 if (region.isEmpty()) | 588 if (region.isEmpty()) |
587 return; | 589 return; |
588 if (isRect() && m_bounds.contains(region.m_bounds)) | 590 if (isRect() && m_bounds.contains(region.m_bounds)) |
589 return; | 591 return; |
590 if (region.isRect() && region.m_bounds.contains(m_bounds)) { | 592 if (region.isRect() && region.m_bounds.contains(m_bounds)) { |
591 m_shape = region.m_shape; | 593 m_shape = region.m_shape; |
592 m_bounds = region.m_bounds; | 594 m_bounds = region.m_bounds; |
593 return; | 595 return; |
594 } | 596 } |
595 // FIXME: We may want another way to construct a Region without doing this tes
t when we expect it to be false. | 597 // FIXME: We may want another way to construct a Region without doing this |
| 598 // test when we expect it to be false. |
596 if (!isRect() && contains(region)) | 599 if (!isRect() && contains(region)) |
597 return; | 600 return; |
598 | 601 |
599 Shape unitedShape = Shape::unionShapes(m_shape, region.m_shape); | 602 Shape unitedShape = Shape::unionShapes(m_shape, region.m_shape); |
600 | 603 |
601 m_shape.swap(unitedShape); | 604 m_shape.swap(unitedShape); |
602 m_bounds.unite(region.m_bounds); | 605 m_bounds.unite(region.m_bounds); |
603 } | 606 } |
604 | 607 |
605 void Region::subtract(const Region& region) { | 608 void Region::subtract(const Region& region) { |
606 if (m_bounds.isEmpty()) | 609 if (m_bounds.isEmpty()) |
607 return; | 610 return; |
608 if (region.isEmpty()) | 611 if (region.isEmpty()) |
609 return; | 612 return; |
610 if (!m_bounds.intersects(region.m_bounds)) | 613 if (!m_bounds.intersects(region.m_bounds)) |
611 return; | 614 return; |
612 | 615 |
613 Shape subtractedShape = Shape::subtractShapes(m_shape, region.m_shape); | 616 Shape subtractedShape = Shape::subtractShapes(m_shape, region.m_shape); |
614 | 617 |
615 m_shape.swap(subtractedShape); | 618 m_shape.swap(subtractedShape); |
616 m_bounds = m_shape.bounds(); | 619 m_bounds = m_shape.bounds(); |
617 } | 620 } |
618 | 621 |
619 void Region::translate(const IntSize& offset) { | 622 void Region::translate(const IntSize& offset) { |
620 m_bounds.move(offset); | 623 m_bounds.move(offset); |
621 m_shape.translate(offset); | 624 m_shape.translate(offset); |
622 } | 625 } |
623 | 626 |
624 } // namespace blink | 627 } // namespace blink |
OLD | NEW |