3 * Copyright 2006 The Android Open Source Project
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
12 void SkIRect::join(int32_t left, int32_t top, int32_t right, int32_t bottom) {
13 // do nothing if the params are empty
14 if (left >= right || top >= bottom) {
18 // if we are empty, just assign
19 if (fLeft >= fRight || fTop >= fBottom) {
20 this->set(left, top, right, bottom);
22 if (left < fLeft) fLeft = left;
23 if (top < fTop) fTop = top;
24 if (right > fRight) fRight = right;
25 if (bottom > fBottom) fBottom = bottom;
29 void SkIRect::sort() {
31 SkTSwap<int32_t>(fLeft, fRight);
34 SkTSwap<int32_t>(fTop, fBottom);
38 /////////////////////////////////////////////////////////////////////////////
42 SkTSwap<SkScalar>(fLeft, fRight);
45 SkTSwap<SkScalar>(fTop, fBottom);
49 void SkRect::toQuad(SkPoint quad[4]) const {
52 quad[0].set(fLeft, fTop);
53 quad[1].set(fRight, fTop);
54 quad[2].set(fRight, fBottom);
55 quad[3].set(fLeft, fBottom);
58 bool SkRect::setBoundsCheck(const SkPoint pts[], int count) {
59 SkASSERT((pts && count > 0) || count == 0);
64 sk_bzero(this, sizeof(SkRect));
71 // If all of the points are finite, accum should stay 0. If we encounter
72 // a NaN or infinity, then accum should become NaN.
74 accum *= l; accum *= t;
76 for (int i = 1; i < count; i++) {
77 SkScalar x = pts[i].fX;
78 SkScalar y = pts[i].fY;
80 accum *= x; accum *= y;
82 // we use if instead of if/else, so we can generate min/max
83 // float instructions (at least on SSE)
91 SkASSERT(!accum || !SkScalarIsFinite(accum));
96 this->set(l, t, r, b);
102 bool SkRect::intersect(SkScalar left, SkScalar top, SkScalar right,
104 if (left < right && top < bottom && !this->isEmpty() && // check for empties
105 fLeft < right && left < fRight && fTop < bottom && top < fBottom)
107 if (fLeft < left) fLeft = left;
108 if (fTop < top) fTop = top;
109 if (fRight > right) fRight = right;
110 if (fBottom > bottom) fBottom = bottom;
116 bool SkRect::intersect(const SkRect& r) {
118 return this->intersect(r.fLeft, r.fTop, r.fRight, r.fBottom);
121 bool SkRect::intersect2(const SkRect& r) {
123 SkScalar L = SkMaxScalar(fLeft, r.fLeft);
124 SkScalar R = SkMinScalar(fRight, r.fRight);
128 SkScalar T = SkMaxScalar(fTop, r.fTop);
129 SkScalar B = SkMinScalar(fBottom, r.fBottom);
133 this->set(L, T, R, B);
137 bool SkRect::intersect(const SkRect& a, const SkRect& b) {
140 if (!a.isEmpty() && !b.isEmpty() &&
141 a.fLeft < b.fRight && b.fLeft < a.fRight &&
142 a.fTop < b.fBottom && b.fTop < a.fBottom) {
143 fLeft = SkMaxScalar(a.fLeft, b.fLeft);
144 fTop = SkMaxScalar(a.fTop, b.fTop);
145 fRight = SkMinScalar(a.fRight, b.fRight);
146 fBottom = SkMinScalar(a.fBottom, b.fBottom);
152 void SkRect::join(SkScalar left, SkScalar top, SkScalar right,
154 // do nothing if the params are empty
155 if (left >= right || top >= bottom) {
159 // if we are empty, just assign
160 if (fLeft >= fRight || fTop >= fBottom) {
161 this->set(left, top, right, bottom);
163 if (left < fLeft) fLeft = left;
164 if (top < fTop) fTop = top;
165 if (right > fRight) fRight = right;
166 if (bottom > fBottom) fBottom = bottom;