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 /////////////////////////////////////////////////////////////////////////////
40 void SkRect::toQuad(SkPoint quad[4]) const {
43 quad[0].set(fLeft, fTop);
44 quad[1].set(fRight, fTop);
45 quad[2].set(fRight, fBottom);
46 quad[3].set(fLeft, fBottom);
49 bool SkRect::setBoundsCheck(const SkPoint pts[], int count) {
50 SkASSERT((pts && count > 0) || count == 0);
55 sk_bzero(this, sizeof(SkRect));
62 // If all of the points are finite, accum should stay 0. If we encounter
63 // a NaN or infinity, then accum should become NaN.
65 accum *= l; accum *= t;
67 for (int i = 1; i < count; i++) {
68 SkScalar x = pts[i].fX;
69 SkScalar y = pts[i].fY;
71 accum *= x; accum *= y;
73 // we use if instead of if/else, so we can generate min/max
74 // float instructions (at least on SSE)
82 SkASSERT(!accum || !SkScalarIsFinite(accum));
87 this->set(l, t, r, b);
93 #define CHECK_INTERSECT(al, at, ar, ab, bl, bt, br, bb) \
94 SkScalar L = SkMaxScalar(al, bl); \
95 SkScalar R = SkMinScalar(ar, br); \
96 SkScalar T = SkMaxScalar(at, bt); \
97 SkScalar B = SkMinScalar(ab, bb); \
98 do { if (L >= R || T >= B) return false; } while (0)
100 bool SkRect::intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) {
101 CHECK_INTERSECT(left, top, right, bottom, fLeft, fTop, fRight, fBottom);
102 this->setLTRB(L, T, R, B);
106 bool SkRect::intersect(const SkRect& r) {
107 return this->intersect(r.fLeft, r.fTop, r.fRight, r.fBottom);
110 bool SkRect::intersect(const SkRect& a, const SkRect& b) {
111 CHECK_INTERSECT(a.fLeft, a.fTop, a.fRight, a.fBottom, b.fLeft, b.fTop, b.fRight, b.fBottom);
112 this->setLTRB(L, T, R, B);
116 void SkRect::join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) {
117 // do nothing if the params are empty
118 if (left >= right || top >= bottom) {
122 // if we are empty, just assign
123 if (fLeft >= fRight || fTop >= fBottom) {
124 this->set(left, top, right, bottom);
126 fLeft = SkMinScalar(fLeft, left);
127 fTop = SkMinScalar(fTop, top);
128 fRight = SkMaxScalar(fRight, right);
129 fBottom = SkMaxScalar(fBottom, bottom);