vtransformnodes.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002, The Karbon Developers
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20
21#include "vpath.h"
22#include "vsegment.h"
23#include "vtransformnodes.h"
24
25
26VTransformNodes::VTransformNodes( const TQWMatrix& m )
27 : m_matrix( m )
28{
29}
30
31void
32VTransformNodes::visitVSubpath( VSubpath& path )
33{
34 path.first();
35 while( path.current() )
36 {
37 if( path.current()->isCurve() )
38 {
39 if( !path.current()->knotIsSelected() &&
40 path.current()->pointIsSelected( 1 ) &&
41 path.current()->next() &&
42 path.current()->next()->isCurve() &&
43 !path.current()->next()->pointIsSelected( 0 ) &&
44 path.current()->isSmooth() )
45 {
46 // Do extra reverse trafo for smooth beziers
47 TQWMatrix m2( m_matrix.m11(), m_matrix.m12(), m_matrix.m21(), m_matrix.m22(),
48 -m_matrix.dx(), -m_matrix.dy() );
49 path.current()->next()->setPoint( 0, path.current()->next()->point( 0 ).transform( m2 ) );
50 }
51 if( path.current()->pointIsSelected( 0 ) &&
52 path.current()->prev() &&
53 path.current()->prev()->isCurve() &&
54 !path.current()->prev()->knotIsSelected() &&
55 !path.current()->prev()->pointIsSelected( 1 ) &&
56 path.current()->prev()->isSmooth() )
57 {
58 // Do extra reverse trafo for smooth beziers
59 TQWMatrix m2( m_matrix.m11(), m_matrix.m12(), m_matrix.m21(), m_matrix.m22(),
60 -m_matrix.dx(), -m_matrix.dy() );
61 path.current()->prev()->setPoint( 1, path.current()->prev()->point( 1 ).transform( m2 ) );
62 }
63 }
64
65 for( uint i = 0; i < path.current()->degree(); ++i )
66 {
67 if( path.current()->pointIsSelected( i ) )
68 path.current()->setPoint( i, path.current()->point( i ).transform( m_matrix ) );
69 }
70
71 if( !success() )
72 setSuccess();
73 path.next();
74 }
75}
76
bool pointIsSelected(int i) const
Returns true if the point with index 0 <= i < degree() is selected.
Definition vsegment.h:173
bool knotIsSelected() const
Returns true if the knot is selected.
Definition vsegment.h:181
VSegment * next() const
Returns a pointer to the next not deleted segment, if stored in a VSubpath.
bool isSmooth(const VSegment &next) const
Calculates wether the tangent at the knot is exactly parallel to the tangent at p0 of the next segmen...
Definition vsegment.cpp:700
void setPoint(int i, const KoPoint &p)
Sets the segment's point with index 0 <= i < degree() to "p".
Definition vsegment.h:143
VSegment * prev() const
Returns a pointer to the previous not deleted segment, if stored in a VSubpath.
const KoPoint & point(int i) const
Returns the segment's point with index 0 <= i < degree().
Definition vsegment.h:115
VSubpath provides a sophisticated list of VSegment.
Definition vpath.h:43