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 <vector> 23 #include <functional> 24 25 #include <basegfx/point/b3dpoint.hxx> 26 #include <basegfx/vector/b3dvector.hxx> 27 #include <basegfx/basegfxdllapi.h> 28 29 namespace basegfx 30 { 31 class B3DPolyPolygon; 32 class B3DPolygon; 33 class B3DRange; 34 } 35 36 namespace basegfx::utils 37 { 38 // B3DPolygon tools 39 40 /** Check if given polygon is closed. This is kind of a 41 'classic' method to support old polygon definitions. 42 Those old polygon definitions define the closed state 43 of the polygon using identical start and endpoints. This 44 method corrects this (removes double start/end points) 45 and sets the Closed()-state of the polygon correctly. 46 */ 47 BASEGFX_DLLPUBLIC void checkClosed(B3DPolygon& rCandidate); 48 49 // Get successor and predecessor indices. Returning the same index means there 50 // is none. Same for successor. 51 BASEGFX_DLLPUBLIC sal_uInt32 getIndexOfSuccessor(sal_uInt32 nIndex, const B3DPolygon& rCandidate); 52 53 // get size of polygon. Control vectors are included in that ranges. 54 BASEGFX_DLLPUBLIC B3DRange getRange(const B3DPolygon& rCandidate); 55 56 // get length of polygon 57 BASEGFX_DLLPUBLIC double getLength(const B3DPolygon& rCandidate); 58 59 /** Apply given LineDashing to given polygon 60 61 For a description see applyLineDashing in b2dpolygontoos.hxx 62 Also 2nd version with callbacks, see comments in 2D version 63 */ 64 BASEGFX_DLLPUBLIC void applyLineDashing( 65 const B3DPolygon& rCandidate, 66 const std::vector<double>& rDotDashArray, 67 std::function<void(const basegfx::B3DPolygon& rSnippet)> aLineTargetCallback, 68 double fDotDashLength = 0.0); 69 BASEGFX_DLLPUBLIC void applyLineDashing( 70 const B3DPolygon& rCandidate, 71 const ::std::vector<double>& rDotDashArray, 72 B3DPolyPolygon* pLineTarget, 73 double fDotDashLength = 0.0); 74 75 /** Create/replace normals for given 3d geometry with default normals from given center to outside. 76 rCandidate: the 3d geometry to change 77 rCenter: the center of the 3d geometry 78 */ 79 BASEGFX_DLLPUBLIC B3DPolygon applyDefaultNormalsSphere( const B3DPolygon& rCandidate, const B3DPoint& rCenter); 80 81 /** invert normals for given 3d geometry. 82 */ 83 BASEGFX_DLLPUBLIC B3DPolygon invertNormals( const B3DPolygon& rCandidate); 84 85 /** Create/replace texture coordinates for given 3d geometry with parallel projected one 86 rRange: the full range of the 3d geometry 87 If bChangeX, x texture coordinate will be recalculated. 88 If bChangeY, y texture coordinate will be recalculated. 89 */ 90 BASEGFX_DLLPUBLIC B3DPolygon applyDefaultTextureCoordinatesParallel( const B3DPolygon& rCandidate, const B3DRange& rRange, bool bChangeX, bool bChangeY); 91 92 /** Create/replace texture coordinates for given 3d geometry with spherical one 93 rCenter: the centre of the used 3d geometry 94 If bChangeX, x texture coordinate will be recalculated. 95 If bChangeY, y texture coordinate will be recalculated. 96 */ 97 BASEGFX_DLLPUBLIC B3DPolygon applyDefaultTextureCoordinatesSphere( const B3DPolygon& rCandidate, const B3DPoint& rCenter, bool bChangeX, bool bChangeY); 98 99 // isInside tests for B3DPoint. On border is not inside as long as not true is given in bWithBorder flag. 100 BASEGFX_DLLPUBLIC bool isInside(const B3DPolygon& rCandidate, const B3DPoint& rPoint, bool bWithBorder); 101 102 // calculates if given point is on given line, taking care of the numerical epsilon 103 BASEGFX_DLLPUBLIC bool isPointOnLine(const B3DPoint& rStart, const B3DPoint& rEnd, const B3DPoint& rCandidate, bool bWithPoints); 104 105 // calculates if given point is on given polygon, taking care of the numerical epsilon. Uses 106 // isPointOnLine internally 107 BASEGFX_DLLPUBLIC bool isPointOnPolygon(const B3DPolygon& rCandidate, const B3DPoint& rPoint); 108 109 // helper to get a fCut position between a plane (given with normal and a point) 110 // and a line given by start and end point 111 BASEGFX_DLLPUBLIC bool getCutBetweenLineAndPlane(const B3DVector& rPlaneNormal, const B3DPoint& rPlanePoint, const B3DPoint& rEdgeStart, const B3DPoint& rEdgeEnd, double& fCut); 112 113 /** snap some polygon coordinates to discrete coordinates 114 115 This method allows to snap some polygon points to discrete (integer) values 116 which equals e.g. a snap to discrete coordinates. It will snap points of 117 horizontal and vertical edges 118 119 @param rCandidate 120 The source polygon 121 122 @return 123 The modified version of the source polygon 124 */ 125 BASEGFX_DLLPUBLIC B3DPolygon snapPointsOfHorizontalOrVerticalEdges(const B3DPolygon& rCandidate); 126 127 } // end of namespace basegfx::utils 128 129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 130