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 .
22 #include <sal/types.h>
23 #include <basegfx/range/b2ibox.hxx>
26 namespace basegfx::utils
28 namespace RectClipFlags
30 const sal_uInt32 LEFT
= sal_Int32(0x01);
31 const sal_uInt32 RIGHT
= sal_Int32(0x02);
32 const sal_uInt32 TOP
= sal_Int32(0x04);
33 const sal_uInt32 BOTTOM
= sal_Int32(0x08);
36 /** Calc clip mask for Cohen-Sutherland rectangle clip
38 This function returns a clip mask used for the
39 Cohen-Sutherland rectangle clip method, where one or more
40 of the lower four bits are set, if the given point is
41 outside one or more of the four half planes defining the
42 rectangle (see RectClipFlags for possible values)
44 template< class Point
, class Rect
> inline
45 sal_uInt32
getCohenSutherlandClipFlags( const Point
& rP
,
48 // maxY | minY | maxX | minX
50 clip
= (rP
.getX() < rR
.getMinX()) << 0;
51 clip
|= (rP
.getX() > rR
.getMaxX()) << 1;
52 clip
|= (rP
.getY() < rR
.getMinY()) << 2;
53 clip
|= (rP
.getY() > rR
.getMaxY()) << 3;
57 /// Cohen-Sutherland mask calculation - overload for boxes.
58 template< class Point
> inline
59 sal_uInt32
getCohenSutherlandClipFlags( const Point
& rP
,
62 // maxY | minY | maxX | minX
64 clip
= (rP
.getX() < rB
.getMinX()) << 0;
65 clip
|= (rP
.getX() >= rB
.getMaxX()) << 1;
66 clip
|= (rP
.getY() < rB
.getMinY()) << 2;
67 clip
|= (rP
.getY() >= rB
.getMaxY()) << 3;
72 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */