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 22 #include <sal/types.h> 23 #include <basegfx/range/b2ibox.hxx> 24 25 26 namespace basegfx::utils 27 { 28 namespace RectClipFlags 29 { 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); 34 } 35 36 /** Calc clip mask for Cohen-Sutherland rectangle clip 37 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) 43 */ 44 template< class Point, class Rect > inline getCohenSutherlandClipFlags(const Point & rP,const Rect & rR)45 sal_uInt32 getCohenSutherlandClipFlags( const Point& rP, 46 const Rect& rR ) 47 { 48 // maxY | minY | maxX | minX 49 sal_uInt32 clip; 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; 54 return clip; 55 } 56 57 /// Cohen-Sutherland mask calculation - overload for boxes. 58 template< class Point > inline getCohenSutherlandClipFlags(const Point & rP,const B2IBox & rB)59 sal_uInt32 getCohenSutherlandClipFlags( const Point& rP, 60 const B2IBox& rB ) 61 { 62 // maxY | minY | maxX | minX 63 sal_uInt32 clip; 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; 68 return clip; 69 } 70 } 71 72 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 73