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 .
25 #include <basegfx/point/b3dpoint.hxx>
26 #include <basegfx/vector/b3dvector.hxx>
27 #include <basegfx/basegfxdllapi.h>
36 namespace basegfx::utils
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.
47 BASEGFX_DLLPUBLIC
void checkClosed(B3DPolygon
& rCandidate
);
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
);
53 // get size of polygon. Control vectors are included in that ranges.
54 BASEGFX_DLLPUBLIC B3DRange
getRange(const B3DPolygon
& rCandidate
);
56 // get length of polygon
57 BASEGFX_DLLPUBLIC
double getLength(const B3DPolygon
& rCandidate
);
59 /** Apply given LineDashing to given polygon
61 For a description see applyLineDashing in b2dpolygontoos.hxx
62 Also 2nd version with callbacks, see comments in 2D version
64 void applyLineDashing(
65 const B3DPolygon
& rCandidate
,
66 const std::vector
<double>& rDotDashArray
,
67 const std::function
<void(const basegfx::B3DPolygon
& rSnippet
)>& rLineTargetCallback
,
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);
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
79 B3DPolygon
applyDefaultNormalsSphere( const B3DPolygon
& rCandidate
, const B3DPoint
& rCenter
);
81 /** invert normals for given 3d geometry.
83 BASEGFX_DLLPUBLIC B3DPolygon
invertNormals( const B3DPolygon
& rCandidate
);
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.
90 B3DPolygon
applyDefaultTextureCoordinatesParallel( const B3DPolygon
& rCandidate
, const B3DRange
& rRange
, bool bChangeX
, bool bChangeY
);
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.
97 B3DPolygon
applyDefaultTextureCoordinatesSphere( const B3DPolygon
& rCandidate
, const B3DPoint
& rCenter
, bool bChangeX
, bool bChangeY
);
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
);
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
);
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
);
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
);
113 /** snap some polygon coordinates to discrete coordinates
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
123 The modified version of the source polygon
125 BASEGFX_DLLPUBLIC B3DPolygon
snapPointsOfHorizontalOrVerticalEdges(const B3DPolygon
& rCandidate
);
127 } // end of namespace basegfx::utils
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */