gfx/skia/trunk/src/core/SkRect.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2006 The Android Open Source Project
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #include "SkRect.h"
michael@0 11
michael@0 12 void SkIRect::join(int32_t left, int32_t top, int32_t right, int32_t bottom) {
michael@0 13 // do nothing if the params are empty
michael@0 14 if (left >= right || top >= bottom) {
michael@0 15 return;
michael@0 16 }
michael@0 17
michael@0 18 // if we are empty, just assign
michael@0 19 if (fLeft >= fRight || fTop >= fBottom) {
michael@0 20 this->set(left, top, right, bottom);
michael@0 21 } else {
michael@0 22 if (left < fLeft) fLeft = left;
michael@0 23 if (top < fTop) fTop = top;
michael@0 24 if (right > fRight) fRight = right;
michael@0 25 if (bottom > fBottom) fBottom = bottom;
michael@0 26 }
michael@0 27 }
michael@0 28
michael@0 29 void SkIRect::sort() {
michael@0 30 if (fLeft > fRight) {
michael@0 31 SkTSwap<int32_t>(fLeft, fRight);
michael@0 32 }
michael@0 33 if (fTop > fBottom) {
michael@0 34 SkTSwap<int32_t>(fTop, fBottom);
michael@0 35 }
michael@0 36 }
michael@0 37
michael@0 38 /////////////////////////////////////////////////////////////////////////////
michael@0 39
michael@0 40 void SkRect::sort() {
michael@0 41 if (fLeft > fRight) {
michael@0 42 SkTSwap<SkScalar>(fLeft, fRight);
michael@0 43 }
michael@0 44 if (fTop > fBottom) {
michael@0 45 SkTSwap<SkScalar>(fTop, fBottom);
michael@0 46 }
michael@0 47 }
michael@0 48
michael@0 49 void SkRect::toQuad(SkPoint quad[4]) const {
michael@0 50 SkASSERT(quad);
michael@0 51
michael@0 52 quad[0].set(fLeft, fTop);
michael@0 53 quad[1].set(fRight, fTop);
michael@0 54 quad[2].set(fRight, fBottom);
michael@0 55 quad[3].set(fLeft, fBottom);
michael@0 56 }
michael@0 57
michael@0 58 bool SkRect::setBoundsCheck(const SkPoint pts[], int count) {
michael@0 59 SkASSERT((pts && count > 0) || count == 0);
michael@0 60
michael@0 61 bool isFinite = true;
michael@0 62
michael@0 63 if (count <= 0) {
michael@0 64 sk_bzero(this, sizeof(SkRect));
michael@0 65 } else {
michael@0 66 SkScalar l, t, r, b;
michael@0 67
michael@0 68 l = r = pts[0].fX;
michael@0 69 t = b = pts[0].fY;
michael@0 70
michael@0 71 // If all of the points are finite, accum should stay 0. If we encounter
michael@0 72 // a NaN or infinity, then accum should become NaN.
michael@0 73 float accum = 0;
michael@0 74 accum *= l; accum *= t;
michael@0 75
michael@0 76 for (int i = 1; i < count; i++) {
michael@0 77 SkScalar x = pts[i].fX;
michael@0 78 SkScalar y = pts[i].fY;
michael@0 79
michael@0 80 accum *= x; accum *= y;
michael@0 81
michael@0 82 // we use if instead of if/else, so we can generate min/max
michael@0 83 // float instructions (at least on SSE)
michael@0 84 if (x < l) l = x;
michael@0 85 if (x > r) r = x;
michael@0 86
michael@0 87 if (y < t) t = y;
michael@0 88 if (y > b) b = y;
michael@0 89 }
michael@0 90
michael@0 91 SkASSERT(!accum || !SkScalarIsFinite(accum));
michael@0 92 if (accum) {
michael@0 93 l = t = r = b = 0;
michael@0 94 isFinite = false;
michael@0 95 }
michael@0 96 this->set(l, t, r, b);
michael@0 97 }
michael@0 98
michael@0 99 return isFinite;
michael@0 100 }
michael@0 101
michael@0 102 bool SkRect::intersect(SkScalar left, SkScalar top, SkScalar right,
michael@0 103 SkScalar bottom) {
michael@0 104 if (left < right && top < bottom && !this->isEmpty() && // check for empties
michael@0 105 fLeft < right && left < fRight && fTop < bottom && top < fBottom)
michael@0 106 {
michael@0 107 if (fLeft < left) fLeft = left;
michael@0 108 if (fTop < top) fTop = top;
michael@0 109 if (fRight > right) fRight = right;
michael@0 110 if (fBottom > bottom) fBottom = bottom;
michael@0 111 return true;
michael@0 112 }
michael@0 113 return false;
michael@0 114 }
michael@0 115
michael@0 116 bool SkRect::intersect(const SkRect& r) {
michael@0 117 SkASSERT(&r);
michael@0 118 return this->intersect(r.fLeft, r.fTop, r.fRight, r.fBottom);
michael@0 119 }
michael@0 120
michael@0 121 bool SkRect::intersect2(const SkRect& r) {
michael@0 122 SkASSERT(&r);
michael@0 123 SkScalar L = SkMaxScalar(fLeft, r.fLeft);
michael@0 124 SkScalar R = SkMinScalar(fRight, r.fRight);
michael@0 125 if (L >= R) {
michael@0 126 return false;
michael@0 127 }
michael@0 128 SkScalar T = SkMaxScalar(fTop, r.fTop);
michael@0 129 SkScalar B = SkMinScalar(fBottom, r.fBottom);
michael@0 130 if (T >= B) {
michael@0 131 return false;
michael@0 132 }
michael@0 133 this->set(L, T, R, B);
michael@0 134 return true;
michael@0 135 }
michael@0 136
michael@0 137 bool SkRect::intersect(const SkRect& a, const SkRect& b) {
michael@0 138 SkASSERT(&a && &b);
michael@0 139
michael@0 140 if (!a.isEmpty() && !b.isEmpty() &&
michael@0 141 a.fLeft < b.fRight && b.fLeft < a.fRight &&
michael@0 142 a.fTop < b.fBottom && b.fTop < a.fBottom) {
michael@0 143 fLeft = SkMaxScalar(a.fLeft, b.fLeft);
michael@0 144 fTop = SkMaxScalar(a.fTop, b.fTop);
michael@0 145 fRight = SkMinScalar(a.fRight, b.fRight);
michael@0 146 fBottom = SkMinScalar(a.fBottom, b.fBottom);
michael@0 147 return true;
michael@0 148 }
michael@0 149 return false;
michael@0 150 }
michael@0 151
michael@0 152 void SkRect::join(SkScalar left, SkScalar top, SkScalar right,
michael@0 153 SkScalar bottom) {
michael@0 154 // do nothing if the params are empty
michael@0 155 if (left >= right || top >= bottom) {
michael@0 156 return;
michael@0 157 }
michael@0 158
michael@0 159 // if we are empty, just assign
michael@0 160 if (fLeft >= fRight || fTop >= fBottom) {
michael@0 161 this->set(left, top, right, bottom);
michael@0 162 } else {
michael@0 163 if (left < fLeft) fLeft = left;
michael@0 164 if (top < fTop) fTop = top;
michael@0 165 if (right > fRight) fRight = right;
michael@0 166 if (bottom > fBottom) fBottom = bottom;
michael@0 167 }
michael@0 168 }

mercurial