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: liangbarsky.cxx,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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basegfx.hxx"
34 #include "basegfx/tools/tools.hxx"
35 #include "basegfx/numeric/ftools.hxx"
36 #include "basegfx/range/b2drange.hxx"
45 // see Foley/vanDam, pp. 122 for the Liang-Barsky line
47 inline bool liangBarskyClipT( double nDenom
,
55 t
= nNumerator
/ nDenom
;
63 t
= nNumerator
/ nDenom
;
69 else if( nNumerator
> 0 )
78 // see Foley/vanDam, pp. 122 for the Liang-Barsky line
80 bool liangBarskyClip2D( ::basegfx::B2DPoint
& io_rStart
,
81 ::basegfx::B2DPoint
& io_rEnd
,
82 const ::basegfx::B2DRange
& rClipRect
)
84 const double nDX( io_rEnd
.getX() - io_rStart
.getX() );
85 const double nDY( io_rEnd
.getY() - io_rStart
.getY() );
87 if( ::basegfx::fTools::equalZero( nDX
) &&
88 ::basegfx::fTools::equalZero( nDY
) )
90 return rClipRect
.isInside( io_rStart
);
96 if( liangBarskyClipT(nDX
, rClipRect
.getMinX() - io_rStart
.getX(),
97 nTE
, nTL
) ) // inside wrt. left edge
99 if( liangBarskyClipT(-nDX
, io_rStart
.getX() - rClipRect
.getMaxX(),
100 nTE
, nTL
) ) // inside wrt. right edge
102 if( liangBarskyClipT(nDY
, rClipRect
.getMinY() - io_rStart
.getY(),
103 nTE
, nTL
) ) // inside wrt. bottom edge
105 if( liangBarskyClipT(-nDY
, io_rStart
.getY() - rClipRect
.getMaxY(),
106 nTE
, nTL
) ) // inside wrt. top edge
108 // compute actual intersection points,
109 // if nTL has changed
112 io_rEnd
.setX( io_rStart
.getX() + nTL
*nDX
);
113 io_rEnd
.setY( io_rStart
.getY() + nTL
*nDY
);
116 // compute actual intersection points,
117 // if nTE has changed
120 io_rStart
.setX( io_rStart
.getX() + nTE
*nDX
);
121 io_rStart
.setY( io_rStart
.getY() + nTE
*nDY
);
124 // line is (at least partially) visible