1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: calculat.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #include <tools/solar.h>
46 /** @descr This class clips single lines and polygons at a given rectangle.
47 All of it's methods are static, therefore no object has to be created.
49 It uses the Liang-Biarsky parametric line-clipping algorithm as described in:
50 Computer Graphics: principles and practice, 2nd ed.,
51 James D. Foley et al.,
52 Section 3.12.4 on page 117.
54 class SchCalculationHelper
57 /** like Rectangle::IsInside, but the result is FALSE, if
58 the Point is on the Border of the Rectangle
60 // static BOOL IsPointInsideRectangle( const Point& rPoint, const Rectangle& rRect );
62 /** @descr The line is clipped at the rectangle. If the line lies completely or partly
63 inside the clipping area then TRUE is returned and the line is modified accordingly.
64 If the line lies completely outside the clipping area then FALSE is returned and the
65 line remains unmodified.
66 The line may be degenerate in that both of it's end points have the same
68 @param aLine The line to be clipped. It is modified to a part that lies completely
69 inside the clipping area if such a part exists.
70 @param rRectangle The clipping area.
71 @return TRUE is returned if the line lies completely or partly inside the clipping area.
74 /** @descr The intersection between an open polygon and a rectangle is
75 calculated and the resulting lines are placed into the poly-polygon aResult.
76 @param rPolygon The polygon is required to be open, ie. it's start and end point
77 have different coordinates and that it is continuous, ie. has no holes.
78 @param rRectangle The clipping area.
79 @param aResult The resulting lines that are the parts of the given polygon lying inside
80 the clipping area are stored into aResult whose prior content is deleted first.
82 static void IntersectPolygonWithRectangle( const XPolygon
& rPolygon
, const Rectangle
& rRectangle
,
83 XPolyPolygon
& aResult
);
85 /** @descr Calculates the intersection between a set of open polygons and a
86 rectangle. This function iterates over all polygons contained in
87 rPolyPolygon and calls IntersectPolygonWithRectangle() for it.
88 The resulting XPolyPolygons are then put together into aResult.
89 @param rPolyPolygon A set of polygons that must be open.
90 @param rRectangle The clipping region
91 @param rOutResult The resulting lines representing rPolyPolygon clipped
95 /** @descr calculates natural cubic splines for the given set of points.
97 @param rPoints is a vector of tuples containing x and y coordinate of
98 points that are to be interpolated.
99 @param nGranularity The number of interpolation points between two
100 x-values given in rPoints
102 @param rOutResult A polygon (split up into more, if the number of points
103 is too high as to fit into a single XPolygon) that contains all
104 line segments between the interpolated points. It should contain
105 (rPoints.size() * nGranularity) points.
107 @param nDPIX resolution in x-direction to reduce the number of points.
108 A value of 0 (default) means do not take into account.
110 @param nDPIY resolution in y-direction to reduce the number of points.
111 A value of 0 (default) means do not take into account.
115 /** @descr The line given by it's two endpoints rP0 and rP1 is clipped at the rectangle
116 rRectangle. If there is at least a part of it visible then TRUE is returned and
117 the endpoints of that part are stored in rP0 and rP1. The points rP0 and rP1
118 may have the same coordinates.
119 @param rP0 Start point of the line to clip. Modified to contain a start point inside
120 the clipping area if possible.
121 @param rP1 End point of the line to clip. Modified to contain an end point inside
122 the clipping area if possible.
123 @param rRectangle Clipping area.
124 @return If the line lies completely or partly inside the clipping area then TRUE
125 is returned. If the line lies completely outside then FALSE is returned and rP0 and
126 rP1 are left unmodified.
128 static BOOL
clip2d (Point
& rP0
, Point
& rP1
, const Rectangle
& rRectangle
);
130 /** @descr This is a supporting function for clip2d. It computes a new parametric
131 value for an entering (dTE) or leaving (dTL) intersection point with one
132 of the edges bounding the clipping area.
133 For explanation of the parameters please refer to the literature reference
136 static BOOL
CLIPt (double fDenom
, double fNum
, double & fTE
, double & fTL
);
139 } //namespace binfilter