Back to Mnn

MNN: include/Rect.h 源文件

doc/API/html/_rect_8h_source.html

3.5.025.0 KB
Original Source

| MNN 1.0 |

Rect.h

浏览该文件的文档.

1 //

2 // Rect.h

3 // MNN

4 //

5 // Modified by jiangxiaotang on 2018/09/19.

6 // Copyright © 2018, Alibaba Group Holding Limited

7 //

8

9 /*

10 * Copyright 2006 The Android Open Source Project

11 *

12 * Use of this source code is governed by a BSD-style license that can be

13 * found in the LICENSE file.

14 */

15

16 /* Generated by tools/bookmaker from include/core/Rect.h and docs/SkRect_Reference.bmh

17 on 2018-07-13 08:15:11. Additional documentation and examples can be found at:

18 https://skia.org/user/api/SkRect\_Reference

19

20 You may edit either file directly. Structural changes to public interfaces require

21 editing both files. After editing docs/SkRect_Reference.bmh, run:

22 bookmaker -b docs -i include/core/Rect.h -p

23 to create an updated version of this file.

24 */

25

26 #ifndef SkRect_DEFINED

27 #define SkRect_DEFINED

28

29 #include <math.h>

30 #include <algorithm>

31 #include <utility>

32 #include "MNNDefine.h"

33

34 namespace MNN {

35 namespace CV {

36

37 struct Point {

38float fX;

39float fY;

40

41void set(float x, float y) {

42fX = x;

43fY = y;

44 }

45 };

46

54 struct MNN_PUBLIC Rect {

55float fLeft;

56float fTop;

57float fRight;

58float fBottom;

59

67static constexpr Rect MakeEmpty() {

68return Rect{0, 0, 0, 0};

69 }

70

71 #ifdef SK_SUPPORT_LEGACY_RECTMAKELARGEST

72

74static Rect MakeLargest() {

75return {SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax};

76 }

77 #endif

78

89static constexpr Rect MakeWH(float w, float h) {

90return Rect{0, 0, w, h};

91 }

92

103static Rect MakeIWH(int w, int h) {

104Rect r;

105 r.set(0, 0, (float)(w), (float)(h));

106return r;

107 }

108

118static constexpr Rect MakeLTRB(float l, float t, float r, float b) {

119return Rect{l, t, r, b};

120 }

121

131static constexpr Rect MakeXYWH(float x, float y, float w, float h) {

132return Rect{x, y, x + w, y + h};

133 }

134

141bool isEmpty() const {

142// We write it as the NOT of a non-empty rect, so we will return true if any values

143// are NaN.

144return !(fLeft < fRight && fTop < fBottom);

145 }

146

153bool isSorted() const {

154return fLeft <= fRight && fTop <= fBottom;

155 }

156

162float x() const {

163return fLeft;

164 }

165

171float y() const {

172return fTop;

173 }

174

180float left() const {

181return fLeft;

182 }

183

189float top() const {

190return fTop;

191 }

192

198float right() const {

199return fRight;

200 }

201

207float bottom() const {

208return fBottom;

209 }

210

216float width() const {

217return fRight - fLeft;

218 }

219

225float height() const {

226return fBottom - fTop;

227 }

228

234float centerX() const {

235// don't use floatHalf(fLeft + fBottom) as that might overflow before the 0.5

236return 0.5f * (fLeft) + 0.5f * (fRight);

237 }

238

244float centerY() const {

245// don't use floatHalf(fTop + fBottom) as that might overflow before the 0.5

246return 0.5f * (fTop) + 0.5f * (fBottom);

247 }

248

255void setEmpty() {

256 *this = MakeEmpty();

257 }

258

268void set(float left, float top, float right, float bottom) {

269 fLeft = left;

270 fTop = top;

271 fRight = right;

272 fBottom = bottom;

273 }

274

284void setLTRB(float left, float top, float right, float bottom) {

285 this->set(left, top, right, bottom);

286 }

287

298void iset(int left, int top, int right, int bottom) {

299 fLeft = (float)(left);

300 fTop = (float)(top);

301 fRight = (float)(right);

302 fBottom = (float)(bottom);

303 }

304

312void isetWH(int width, int height) {

313 fLeft = fTop = 0;

314 fRight = (float)(width);

315 fBottom = (float)(height);

316 }

317

326void setXYWH(float x, float y, float width, float height) {

327 fLeft = x;

328 fTop = y;

329 fRight = x + width;

330 fBottom = y + height;

331 }

332

339void setWH(float width, float height) {

340 fLeft = 0;

341 fTop = 0;

342 fRight = width;

343 fBottom = height;

344 }

345

357Rect makeOffset(float dx, float dy) const {

358return MakeLTRB(fLeft + dx, fTop + dy, fRight + dx, fBottom + dy);

359 }

360

372Rect makeInset(float dx, float dy) const {

373return MakeLTRB(fLeft + dx, fTop + dy, fRight - dx, fBottom - dy);

374 }

375

387Rect makeOutset(float dx, float dy) const {

388return MakeLTRB(fLeft - dx, fTop - dy, fRight + dx, fBottom + dy);

389 }

390

401void offset(float dx, float dy) {

402 fLeft += dx;

403 fTop += dy;

404 fRight += dx;

405 fBottom += dy;

406 }

407

414void offsetTo(float newX, float newY) {

415 fRight += newX - fLeft;

416 fBottom += newY - fTop;

417 fLeft = newX;

418 fTop = newY;

419 }

420

431void inset(float dx, float dy) {

432 fLeft += dx;

433 fTop += dy;

434 fRight -= dx;

435 fBottom -= dy;

436 }

437

448void outset(float dx, float dy) {

449 this->inset(-dx, -dy);

450 }

451

460bool intersect(const Rect& r);

461

476bool intersect(float left, float top, float right, float bottom);

477

487bool intersect(const Rect& a, const Rect& b);

488

489 private:

490static bool Intersects(float al, float at, float ar, float ab, float bl, float bt, float br, float bb) {

491float L = std::max(al, bl);

492float R = std::min(ar, br);

493float T = std::max(at, bt);

494float B = std::min(ab, bb);

495return L < R && T < B;

496 }

497

498 public:

511bool intersects(float left, float top, float right, float bottom) const {

512return Intersects(fLeft, fTop, fRight, fBottom, left, top, right, bottom);

513 }

514

521bool intersects(const Rect& r) const {

522return Intersects(fLeft, fTop, fRight, fBottom, r.fLeft, r.fTop, r.fRight, r.fBottom);

523 }

524

532static bool Intersects(const Rect& a, const Rect& b) {

533return Intersects(a.fLeft, a.fTop, a.fRight, a.fBottom, b.fLeft, b.fTop, b.fRight, b.fBottom);

534 }

535

549void join(float left, float top, float right, float bottom);

550

558void join(const Rect& r) {

559 this->join(r.fLeft, r.fTop, r.fRight, r.fBottom);

560 }

561

571void joinNonEmptyArg(const Rect& r) {

572MNN_ASSERT(!r.isEmpty());

573// if we are empty, just assign

574if (fLeft >= fRight || fTop >= fBottom) {

575 *this = r;

576 } else {

577 this->joinPossiblyEmptyRect(r);

578 }

579 }

580

587void joinPossiblyEmptyRect(const Rect& r) {

588 fLeft = std::min(fLeft, r.left());

589 fTop = std::min(fTop, r.top());

590 fRight = std::max(fRight, r.right());

591 fBottom = std::max(fBottom, r.bottom());

592 }

593

601bool contains(float x, float y) const {

602return x >= fLeft && x < fRight && y >= fTop && y < fBottom;

603 }

604

609void sort() {

610using std::swap;

611if (fLeft > fRight) {

612 swap(fLeft, fRight);

613 }

614

615if (fTop > fBottom) {

616 swap(fTop, fBottom);

617 }

618 }

619

626Rect makeSorted() const {

627return MakeLTRB(std::min(fLeft, fRight), std::min(fTop, fBottom), std::max(fLeft, fRight),

628 std::max(fTop, fBottom));

629 }

630

636const float* asScalars() const {

637return &fLeft;

638 }

639 };

640

641 } // namespace CV

642 } // namespace MNN

643 #endif

MNN::CV::Rect::makeOutset

Rect makeOutset(float dx, float dy) const

Definition: Rect.h:387

MNN::CV::Rect::MakeXYWH

static constexpr Rect MakeXYWH(float x, float y, float w, float h)

Definition: Rect.h:131

MNN::CV::Rect::contains

bool contains(float x, float y) const

Definition: Rect.h:601

MNN::CV::Rect::join

void join(const Rect &r)

Definition: Rect.h:558

MNN::CV::Rect::width

float width() const

Definition: Rect.h:216

MNN::CV::Rect::MakeWH

static constexpr Rect MakeWH(float w, float h)

Definition: Rect.h:89

MNN::CV::Rect::fTop

float fTop

smaller y-axis bounds

Definition: Rect.h:56

MNN::CV::Rect::fBottom

float fBottom

larger y-axis bounds

Definition: Rect.h:58

MNN_ASSERT

#define MNN_ASSERT(x)

Definition: MNNDefine.h:41

MNN::CV::Rect

Definition: Rect.h:54

MNN::CV::Rect::Intersects

static bool Intersects(const Rect &a, const Rect &b)

Definition: Rect.h:532

MNN::CV::Rect::isetWH

void isetWH(int width, int height)

Definition: Rect.h:312

MNN::CV::Rect::fRight

float fRight

larger x-axis bounds

Definition: Rect.h:57

MNN::CV::Rect::offset

void offset(float dx, float dy)

Definition: Rect.h:401

MNN::CV::Rect::fLeft

float fLeft

smaller x-axis bounds

Definition: Rect.h:55

MNN::CV::Rect::isSorted

bool isSorted() const

Definition: Rect.h:153

MNN::CV::Rect::iset

void iset(int left, int top, int right, int bottom)

Definition: Rect.h:298

MNN::CV::Point::set

void set(float x, float y)

Definition: Rect.h:41

MNN::CV::Rect::joinNonEmptyArg

void joinNonEmptyArg(const Rect &r)

Definition: Rect.h:571

MNN::CV::Rect::MakeIWH

static Rect MakeIWH(int w, int h)

Definition: Rect.h:103

MNN::CV::Rect::isEmpty

bool isEmpty() const

Definition: Rect.h:141

MNN::CV::Rect::y

float y() const

Definition: Rect.h:171

MNN::CV::Point::fY

float fY

Definition: Rect.h:39

MNN::CV::Rect::sort

void sort()

Definition: Rect.h:609

MNN::CV::Rect::inset

void inset(float dx, float dy)

Definition: Rect.h:431

MNN::CV::Rect::set

void set(float left, float top, float right, float bottom)

Definition: Rect.h:268

MNN::CV::Rect::offsetTo

void offsetTo(float newX, float newY)

Definition: Rect.h:414

MNN::CV::Point::fX

float fX

Definition: Rect.h:38

MNN::CV::Rect::makeOffset

Rect makeOffset(float dx, float dy) const

Definition: Rect.h:357

MNN::CV::Rect::joinPossiblyEmptyRect

void joinPossiblyEmptyRect(const Rect &r)

Definition: Rect.h:587

MNN::CV::Rect::setWH

void setWH(float width, float height)

Definition: Rect.h:339

MNN::CV::Rect::top

float top() const

Definition: Rect.h:189

MNN_PUBLIC

#define MNN_PUBLIC

Definition: MNNDefine.h:53

MNN::CV::Rect::asScalars

const float * asScalars() const

Definition: Rect.h:636

MNN::CV::Rect::outset

void outset(float dx, float dy)

Definition: Rect.h:448

MNN::CV::Rect::MakeEmpty

static constexpr Rect MakeEmpty()

Definition: Rect.h:67

MNN::CV::Rect::MakeLTRB

static constexpr Rect MakeLTRB(float l, float t, float r, float b)

Definition: Rect.h:118

MNN

Definition: AutoTime.hpp:16

MNN::CV::Rect::setEmpty

void setEmpty()

Definition: Rect.h:255

MNN::CV::Rect::height

float height() const

Definition: Rect.h:225

MNN::CV::Rect::bottom

float bottom() const

Definition: Rect.h:207

MNN::CV::Rect::x

float x() const

Definition: Rect.h:162

MNN::CV::Point

Definition: Rect.h:37

MNN::CV::Rect::setXYWH

void setXYWH(float x, float y, float width, float height)

Definition: Rect.h:326

MNN::CV::Rect::setLTRB

void setLTRB(float left, float top, float right, float bottom)

Definition: Rect.h:284

MNN::CV::Rect::makeSorted

Rect makeSorted() const

Definition: Rect.h:626

MNN::CV::Rect::intersects

bool intersects(const Rect &r) const

Definition: Rect.h:521

MNN::CV::Rect::right

float right() const

Definition: Rect.h:198

MNN::CV::Rect::intersects

bool intersects(float left, float top, float right, float bottom) const

Definition: Rect.h:511

MNN::CV::Rect::centerX

float centerX() const

Definition: Rect.h:234

MNN::CV::Rect::centerY

float centerY() const

Definition: Rect.h:244

MNN::CV::Rect::makeInset

Rect makeInset(float dx, float dy) const

Definition: Rect.h:372

MNNDefine.h

MNN::CV::Rect::left

float left() const

Definition: Rect.h:180


制作者 1.8.15