Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / basegfx / tools / rectcliptools.hxx
blob9c4fd78b6b356778e28bd84742fcf3adbe356b60
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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_BASEGFX_TOOLS_RECTCLIPTOOLS_HXX
21 #define INCLUDED_BASEGFX_TOOLS_RECTCLIPTOOLS_HXX
23 #include <sal/types.h>
24 #include <basegfx/range/b2ibox.hxx>
27 namespace basegfx
29 namespace tools
31 namespace RectClipFlags
33 static const sal_uInt32 LEFT = (sal_Int32)0x01;
34 static const sal_uInt32 RIGHT = (sal_Int32)0x02;
35 static const sal_uInt32 TOP = (sal_Int32)0x04;
36 static const sal_uInt32 BOTTOM = (sal_Int32)0x08;
39 /** Calc clip mask for Cohen-Sutherland rectangle clip
41 This function returns a clip mask used for the
42 Cohen-Sutherland rectangle clip method, where one or more
43 of the lower four bits are set, if the given point is
44 outside one or more of the four half planes defining the
45 rectangle (see RectClipFlags for possible values)
47 template< class Point, class Rect > inline
48 sal_uInt32 getCohenSutherlandClipFlags( const Point& rP,
49 const Rect& rR )
51 // maxY | minY | maxX | minX
52 sal_uInt32 clip = (rP.getX() < rR.getMinX()) << 0;
53 clip |= (rP.getX() > rR.getMaxX()) << 1;
54 clip |= (rP.getY() < rR.getMinY()) << 2;
55 clip |= (rP.getY() > rR.getMaxY()) << 3;
56 return clip;
59 /// Cohen-Sutherland mask calculation - overload for boxes.
60 template< class Point > inline
61 sal_uInt32 getCohenSutherlandClipFlags( const Point& rP,
62 const B2IBox& rB )
64 // maxY | minY | maxX | minX
65 sal_uInt32 clip = (rP.getX() < rB.getMinX()) << 0;
66 clip |= (rP.getX() >= rB.getMaxX()) << 1;
67 clip |= (rP.getY() < rB.getMinY()) << 2;
68 clip |= (rP.getY() >= rB.getMaxY()) << 3;
69 return clip;
75 #endif // INCLUDED_BASEGFX_TOOLS_RECTCLIPTOOLS_HXX
77 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */