1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_CANVAS_SOURCE_TOOLS_SURFACERECT_HXX
21 #define INCLUDED_CANVAS_SOURCE_TOOLS_SURFACERECT_HXX
23 #include <basegfx/point/b2ipoint.hxx>
24 #include <basegfx/vector/b2isize.hxx>
34 ::basegfx::B2IPoint maPos
;
35 ::basegfx::B2ISize maSize
;
36 ::basegfx::B2IPoint maBackup
;
39 explicit SurfaceRect( const ::basegfx::B2ISize
&rSize
) :
47 // coordinates contained in this rectangle are
48 // constrained to the following rules:
50 // 2) p.x <= pos.x+size.x
52 // 4) p.y <= pos.y+size.y
53 // in other words, 'size' means the number of pixels
54 // this rectangle encloses plus one. for example with pos[0,0]
55 // and size[512,512], p[512,512] would return inside.
56 // a size of [0,0] therefore denotes a one-by-one rectangle.
57 bool pointInside( sal_Int32 px
, sal_Int32 py
) const
59 const sal_Int32
x1(maPos
.getX());
60 const sal_Int32
y1(maPos
.getY());
61 const sal_Int32
x2(maPos
.getX()+maSize
.getX());
62 const sal_Int32
y2(maPos
.getY()+maSize
.getY());
63 if(px
< x1
) return false;
64 if(px
>= x2
) return false;
65 if(py
< y1
) return false;
66 if(py
>= y2
) return false;
70 // returns true if the horizontal line intersects the rect.
71 bool hLineIntersect( sal_Int32 lx1
, sal_Int32 lx2
, sal_Int32 ly
) const
73 const sal_Int32
x1(maPos
.getX());
74 const sal_Int32
y1(maPos
.getY());
75 const sal_Int32
x2(maPos
.getX()+maSize
.getX());
76 const sal_Int32
y2(maPos
.getY()+maSize
.getY());
77 if(ly
< y1
) return false;
78 if(ly
>= y2
) return false;
79 if((lx1
< x1
) && (lx2
< x1
)) return false;
80 if((lx1
>= x2
) && (lx2
>= x2
)) return false;
84 //! Returns true if the vertical line intersects the rect.
85 bool vLineIntersect( sal_Int32 lx
, sal_Int32 ly1
, sal_Int32 ly2
) const
87 const sal_Int32
x1(maPos
.getX());
88 const sal_Int32
y1(maPos
.getY());
89 const sal_Int32
x2(maPos
.getX()+maSize
.getX());
90 const sal_Int32
y2(maPos
.getY()+maSize
.getY());
91 if(lx
< x1
) return false;
92 if(lx
>= x2
) return false;
93 if((ly1
< y1
) && (ly2
< y1
)) return false;
94 if((ly1
>= y2
) && (ly2
>= y2
)) return false;
98 // returns true if the passed rect intersects this one.
99 bool intersection( const SurfaceRect
& r
) const
101 const sal_Int32
x1(maPos
.getX());
102 const sal_Int32
y1(maPos
.getY());
103 const sal_Int32
x2(maPos
.getX()+maSize
.getX());
104 const sal_Int32
y2(maPos
.getY()+maSize
.getY());
105 if(r
.hLineIntersect(x1
,x2
,y1
)) return true;
106 if(r
.hLineIntersect(x1
,x2
,y2
)) return true;
107 if(r
.vLineIntersect(x1
,y1
,y2
)) return true;
108 if(r
.vLineIntersect(x2
,y1
,y2
)) return true;
112 bool inside( const SurfaceRect
& r
) const
114 const sal_Int32
x1(maPos
.getX());
115 const sal_Int32
y1(maPos
.getY());
116 const sal_Int32
x2(maPos
.getX()+maSize
.getX());
117 const sal_Int32
y2(maPos
.getY()+maSize
.getY());
118 if(!(r
.pointInside(x1
,y1
))) return false;
119 if(!(r
.pointInside(x2
,y1
))) return false;
120 if(!(r
.pointInside(x2
,y2
))) return false;
121 if(!(r
.pointInside(x1
,y2
))) return false;
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */