1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_basegfx.hxx"
31 #include "basegfx/tools/tools.hxx"
32 #include "basegfx/numeric/ftools.hxx"
33 #include "basegfx/range/b2drange.hxx"
42 // see Foley/vanDam, pp. 122 for the Liang-Barsky line
44 inline bool liangBarskyClipT( double nDenom
,
52 t
= nNumerator
/ nDenom
;
60 t
= nNumerator
/ nDenom
;
66 else if( nNumerator
> 0 )
75 // see Foley/vanDam, pp. 122 for the Liang-Barsky line
77 bool liangBarskyClip2D( ::basegfx::B2DPoint
& io_rStart
,
78 ::basegfx::B2DPoint
& io_rEnd
,
79 const ::basegfx::B2DRange
& rClipRect
)
81 const double nDX( io_rEnd
.getX() - io_rStart
.getX() );
82 const double nDY( io_rEnd
.getY() - io_rStart
.getY() );
84 if( ::basegfx::fTools::equalZero( nDX
) &&
85 ::basegfx::fTools::equalZero( nDY
) )
87 return rClipRect
.isInside( io_rStart
);
93 if( liangBarskyClipT(nDX
, rClipRect
.getMinX() - io_rStart
.getX(),
94 nTE
, nTL
) ) // inside wrt. left edge
96 if( liangBarskyClipT(-nDX
, io_rStart
.getX() - rClipRect
.getMaxX(),
97 nTE
, nTL
) ) // inside wrt. right edge
99 if( liangBarskyClipT(nDY
, rClipRect
.getMinY() - io_rStart
.getY(),
100 nTE
, nTL
) ) // inside wrt. bottom edge
102 if( liangBarskyClipT(-nDY
, io_rStart
.getY() - rClipRect
.getMaxY(),
103 nTE
, nTL
) ) // inside wrt. top edge
105 // compute actual intersection points,
106 // if nTL has changed
109 io_rEnd
.setX( io_rStart
.getX() + nTL
*nDX
);
110 io_rEnd
.setY( io_rStart
.getY() + nTL
*nDY
);
113 // compute actual intersection points,
114 // if nTE has changed
117 io_rStart
.setX( io_rStart
.getX() + nTE
*nDX
);
118 io_rStart
.setY( io_rStart
.getY() + nTE
*nDY
);
121 // line is (at least partially) visible