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 #ifndef INCLUDED_CANVAS_SOURCE_TOOLS_SURFACERECT_HXX
21 #define INCLUDED_CANVAS_SOURCE_TOOLS_SURFACERECT_HXX
22 
25 
26 namespace canvas
27 {
38  struct SurfaceRect
39  {
42 
43  explicit SurfaceRect( const ::basegfx::B2ISize &rSize ) :
44  maPos(),
45  maSize(rSize)
46  {
47  }
48 
49  bool pointInside( sal_Int32 px, sal_Int32 py ) const
50  {
51  const sal_Int32 x1(maPos.getX());
52  const sal_Int32 y1(maPos.getY());
53  const sal_Int32 x2(x1 + maSize.getX());
54  const sal_Int32 y2(y1 + maSize.getY());
55  if(px < x1) return false;
56  if(px >= x2) return false;
57  if(py < y1) return false;
58  if(py >= y2) return false;
59  return true;
60  }
61 
63  bool intersection( const SurfaceRect& r ) const
64  {
65  const sal_Int32 x1(maPos.getX());
66  const sal_Int32 y1(maPos.getY());
67  const sal_Int32 x1w(x1 + maSize.getX() - 1);
68  const sal_Int32 y1h(y1 + maSize.getY() - 1);
69 
70  const sal_Int32 x2(r.maPos.getX());
71  const sal_Int32 y2(r.maPos.getY());
72  const sal_Int32 x2w(x2 + r.maSize.getX() - 1);
73  const sal_Int32 y2h(y2 + r.maSize.getY() - 1);
74 
75  return !((x1w < x2) || (x2w < x1) || (y1h < y2) || (y2h < y1));
76  }
77 
78  bool inside( const SurfaceRect& r ) const
79  {
80  const sal_Int32 x1(maPos.getX());
81  const sal_Int32 y1(maPos.getY());
82  const sal_Int32 x2(x1 + maSize.getX() - 1);
83  const sal_Int32 y2(y1 + maSize.getY() - 1);
84  if(!(r.pointInside(x1,y1))) return false;
85  if(!(r.pointInside(x2,y2))) return false;
86  return true;
87  }
88  };
89 }
90 
91 #endif
92 
93 /* 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:63
bool inside(const SurfaceRect &r) const
Definition: surfacerect.hxx:78
bool pointInside(sal_Int32 px, sal_Int32 py) const
Definition: surfacerect.hxx:49
sal_Int32 getX() const
SurfaceRect(const ::basegfx::B2ISize &rSize)
Definition: surfacerect.hxx:43
sal_Int32 getY() const
::basegfx::B2IPoint maPos
Definition: surfacerect.hxx:40
::basegfx::B2ISize maSize
Definition: surfacerect.hxx:41
This implements some equivalent to basegfx::B2IBox, but instead of two BasicBox ranges, it uses a position and a size.
Definition: surfacerect.hxx:38