LibreOffice Module canvas (master)  1
surfacerect.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #pragma once
21 
24 
25 namespace canvas
26 {
37  struct SurfaceRect
38  {
41 
42  explicit SurfaceRect( const ::basegfx::B2ISize &rSize ) :
43  maPos(),
44  maSize(rSize)
45  {
46  }
47 
48  bool pointInside( sal_Int32 px, sal_Int32 py ) const
49  {
50  const sal_Int32 x1(maPos.getX());
51  const sal_Int32 y1(maPos.getY());
52  const sal_Int32 x2(x1 + maSize.getX());
53  const sal_Int32 y2(y1 + maSize.getY());
54  if(px < x1) return false;
55  if(px >= x2) return false;
56  if(py < y1) return false;
57  if(py >= y2) return false;
58  return true;
59  }
60 
62  bool intersection( const SurfaceRect& r ) const
63  {
64  const sal_Int32 x1(maPos.getX());
65  const sal_Int32 y1(maPos.getY());
66  const sal_Int32 x1w(x1 + maSize.getX() - 1);
67  const sal_Int32 y1h(y1 + maSize.getY() - 1);
68 
69  const sal_Int32 x2(r.maPos.getX());
70  const sal_Int32 y2(r.maPos.getY());
71  const sal_Int32 x2w(x2 + r.maSize.getX() - 1);
72  const sal_Int32 y2h(y2 + r.maSize.getY() - 1);
73 
74  return !((x1w < x2) || (x2w < x1) || (y1h < y2) || (y2h < y1));
75  }
76 
77  bool inside( const SurfaceRect& r ) const
78  {
79  const sal_Int32 x1(maPos.getX());
80  const sal_Int32 y1(maPos.getY());
81  const sal_Int32 x2(x1 + maSize.getX() - 1);
82  const sal_Int32 y2(y1 + maSize.getY() - 1);
83  if(!(r.pointInside(x1,y1))) return false;
84  if(!(r.pointInside(x2,y2))) return false;
85  return true;
86  }
87  };
88 }
89 
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool intersection(const SurfaceRect &r) const
returns true if the passed rect intersects this one.
Definition: surfacerect.hxx:62
bool inside(const SurfaceRect &r) const
Definition: surfacerect.hxx:77
bool pointInside(sal_Int32 px, sal_Int32 py) const
Definition: surfacerect.hxx:48
sal_Int32 getX() const
SurfaceRect(const ::basegfx::B2ISize &rSize)
Definition: surfacerect.hxx:42
sal_Int32 getY() const
::basegfx::B2IPoint maPos
Definition: surfacerect.hxx:39
::basegfx::B2ISize maSize
Definition: surfacerect.hxx:40
This implements some equivalent to basegfx::B2IBox, but instead of two BasicBox ranges, it uses a position and a size.
Definition: surfacerect.hxx:37