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: expressionnodefactory.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_slideshow.hxx"
35 #include <canvas/debug.hxx>
36 #include <expressionnodefactory.hxx>
38 #include <canvas/verbosetrace.hxx>
40 #include <basegfx/matrix/b2dhommatrix.hxx>
41 #include <basegfx/point/b2dpoint.hxx>
47 /* Implementation of ExpressionNodeFactory class */
55 class ConstantValueExpression
: public ExpressionNode
58 ConstantValueExpression( double rValue
) :
63 virtual double operator()( double /*t*/ ) const
68 virtual bool isConstant() const
77 class TValueExpression
: public ExpressionNode
84 virtual double operator()( double t
) const
89 virtual bool isConstant() const
95 /** Base class for following binary functions (*+-/)
97 Does not pay off to have all this as a template, since
98 we'd have to hold the functor as a member (+33% object
101 class BinaryExpressionBase
: public ExpressionNode
104 BinaryExpressionBase( const ExpressionNodeSharedPtr
& rFirstArg
,
105 const ExpressionNodeSharedPtr
& rSecondArg
) :
106 mpFirstArg( rFirstArg
),
107 mpSecondArg( rSecondArg
)
111 virtual bool isConstant() const
114 mpFirstArg
->isConstant() &&
115 mpSecondArg
->isConstant();
119 ExpressionNodeSharedPtr mpFirstArg
;
120 ExpressionNodeSharedPtr mpSecondArg
;
123 class PlusExpression
: public BinaryExpressionBase
126 PlusExpression( const ExpressionNodeSharedPtr
& rFirstArg
,
127 const ExpressionNodeSharedPtr
& rSecondArg
) :
128 BinaryExpressionBase( rFirstArg
, rSecondArg
)
132 virtual double operator()( double t
) const
134 return (*mpFirstArg
)(t
) + (*mpSecondArg
)(t
);
138 class MinusExpression
: public BinaryExpressionBase
141 MinusExpression( const ExpressionNodeSharedPtr
& rFirstArg
,
142 const ExpressionNodeSharedPtr
& rSecondArg
) :
143 BinaryExpressionBase( rFirstArg
, rSecondArg
)
147 virtual double operator()( double t
) const
149 return (*mpFirstArg
)(t
) - (*mpSecondArg
)(t
);
153 class MultipliesExpression
: public BinaryExpressionBase
156 MultipliesExpression( const ExpressionNodeSharedPtr
& rFirstArg
,
157 const ExpressionNodeSharedPtr
& rSecondArg
) :
158 BinaryExpressionBase( rFirstArg
, rSecondArg
)
162 virtual double operator()( double t
) const
164 return (*mpFirstArg
)(t
) * (*mpSecondArg
)(t
);
168 class DividesExpression
: public BinaryExpressionBase
171 DividesExpression( const ExpressionNodeSharedPtr
& rFirstArg
,
172 const ExpressionNodeSharedPtr
& rSecondArg
) :
173 BinaryExpressionBase( rFirstArg
, rSecondArg
)
177 virtual double operator()( double t
) const
179 return (*mpFirstArg
)(t
) / (*mpSecondArg
)(t
);
183 class ComposedExpression
: public BinaryExpressionBase
186 ComposedExpression( const ExpressionNodeSharedPtr
& rFirstArg
,
187 const ExpressionNodeSharedPtr
& rSecondArg
) :
188 BinaryExpressionBase( rFirstArg
, rSecondArg
)
192 virtual double operator()( double t
) const
194 return (*mpFirstArg
)( (*mpSecondArg
)(t
) );
198 class MinExpression
: public BinaryExpressionBase
201 MinExpression( const ExpressionNodeSharedPtr
& rFirstArg
,
202 const ExpressionNodeSharedPtr
& rSecondArg
) :
203 BinaryExpressionBase( rFirstArg
, rSecondArg
)
207 virtual double operator()( double t
) const
209 return ::std::min( (*mpFirstArg
)(t
), (*mpSecondArg
)(t
) );
213 class MaxExpression
: public BinaryExpressionBase
216 MaxExpression( const ExpressionNodeSharedPtr
& rFirstArg
,
217 const ExpressionNodeSharedPtr
& rSecondArg
) :
218 BinaryExpressionBase( rFirstArg
, rSecondArg
)
222 virtual double operator()( double t
) const
224 return ::std::max( (*mpFirstArg
)(t
), (*mpSecondArg
)(t
) );
229 ExpressionNodeSharedPtr
ExpressionNodeFactory::createConstantValueExpression( double rConstantValue
)
231 return ExpressionNodeSharedPtr( new ConstantValueExpression(rConstantValue
) );
234 ExpressionNodeSharedPtr
ExpressionNodeFactory::createValueTExpression()
236 return ExpressionNodeSharedPtr( new TValueExpression() );
239 ExpressionNodeSharedPtr
ExpressionNodeFactory::createPlusExpression( const ExpressionNodeSharedPtr
& rLHS
,
240 const ExpressionNodeSharedPtr
& rRHS
)
242 return ExpressionNodeSharedPtr( new PlusExpression(rLHS
, rRHS
) );
245 ExpressionNodeSharedPtr
ExpressionNodeFactory::createMinusExpression( const ExpressionNodeSharedPtr
& rLHS
,
246 const ExpressionNodeSharedPtr
& rRHS
)
248 return ExpressionNodeSharedPtr( new MinusExpression(rLHS
, rRHS
) );
251 ExpressionNodeSharedPtr
ExpressionNodeFactory::createMultipliesExpression( const ExpressionNodeSharedPtr
& rLHS
,
252 const ExpressionNodeSharedPtr
& rRHS
)
254 return ExpressionNodeSharedPtr( new MultipliesExpression(rLHS
, rRHS
) );
257 ExpressionNodeSharedPtr
ExpressionNodeFactory::createDividesExpression( const ExpressionNodeSharedPtr
& rLHS
,
258 const ExpressionNodeSharedPtr
& rRHS
)
260 return ExpressionNodeSharedPtr( new DividesExpression(rLHS
, rRHS
) );
263 ExpressionNodeSharedPtr
ExpressionNodeFactory::createComposedExpression ( const ExpressionNodeSharedPtr
& rOuterFunction
,
264 const ExpressionNodeSharedPtr
& rInnerFunction
)
266 return ExpressionNodeSharedPtr( new ComposedExpression(rOuterFunction
, rInnerFunction
) );
269 ExpressionNodeSharedPtr
ExpressionNodeFactory::createMinExpression ( const ExpressionNodeSharedPtr
& rOuterFunction
,
270 const ExpressionNodeSharedPtr
& rInnerFunction
)
272 return ExpressionNodeSharedPtr( new MinExpression(rOuterFunction
, rInnerFunction
) );
275 ExpressionNodeSharedPtr
ExpressionNodeFactory::createMaxExpression ( const ExpressionNodeSharedPtr
& rOuterFunction
,
276 const ExpressionNodeSharedPtr
& rInnerFunction
)
278 return ExpressionNodeSharedPtr( new MaxExpression(rOuterFunction
, rInnerFunction
) );