1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <canvas/debug.hxx>
23 #include <expressionnodefactory.hxx>
25 #include <canvas/verbosetrace.hxx>
27 #include <basegfx/matrix/b2dhommatrix.hxx>
28 #include <basegfx/point/b2dpoint.hxx>
34 /* Implementation of ExpressionNodeFactory class */
42 class ConstantValueExpression
: public ExpressionNode
45 ConstantValueExpression( double rValue
) :
50 virtual double operator()( double /*t*/ ) const SAL_OVERRIDE
55 virtual bool isConstant() const SAL_OVERRIDE
64 class TValueExpression
: public ExpressionNode
71 virtual double operator()( double t
) const SAL_OVERRIDE
76 virtual bool isConstant() const SAL_OVERRIDE
82 /** Base class for following binary functions (*+-/)
84 Does not pay off to have all this as a template, since
85 we'd have to hold the functor as a member (+33% object
88 class BinaryExpressionBase
: public ExpressionNode
91 BinaryExpressionBase( const ExpressionNodeSharedPtr
& rFirstArg
,
92 const ExpressionNodeSharedPtr
& rSecondArg
) :
93 mpFirstArg( rFirstArg
),
94 mpSecondArg( rSecondArg
)
98 virtual bool isConstant() const SAL_OVERRIDE
101 mpFirstArg
->isConstant() &&
102 mpSecondArg
->isConstant();
106 ExpressionNodeSharedPtr mpFirstArg
;
107 ExpressionNodeSharedPtr mpSecondArg
;
110 class PlusExpression
: public BinaryExpressionBase
113 PlusExpression( const ExpressionNodeSharedPtr
& rFirstArg
,
114 const ExpressionNodeSharedPtr
& rSecondArg
) :
115 BinaryExpressionBase( rFirstArg
, rSecondArg
)
119 virtual double operator()( double t
) const SAL_OVERRIDE
121 return (*mpFirstArg
)(t
) + (*mpSecondArg
)(t
);
125 class MinusExpression
: public BinaryExpressionBase
128 MinusExpression( const ExpressionNodeSharedPtr
& rFirstArg
,
129 const ExpressionNodeSharedPtr
& rSecondArg
) :
130 BinaryExpressionBase( rFirstArg
, rSecondArg
)
134 virtual double operator()( double t
) const SAL_OVERRIDE
136 return (*mpFirstArg
)(t
) - (*mpSecondArg
)(t
);
140 class MultipliesExpression
: public BinaryExpressionBase
143 MultipliesExpression( const ExpressionNodeSharedPtr
& rFirstArg
,
144 const ExpressionNodeSharedPtr
& rSecondArg
) :
145 BinaryExpressionBase( rFirstArg
, rSecondArg
)
149 virtual double operator()( double t
) const SAL_OVERRIDE
151 return (*mpFirstArg
)(t
) * (*mpSecondArg
)(t
);
155 class DividesExpression
: public BinaryExpressionBase
158 DividesExpression( const ExpressionNodeSharedPtr
& rFirstArg
,
159 const ExpressionNodeSharedPtr
& rSecondArg
) :
160 BinaryExpressionBase( rFirstArg
, rSecondArg
)
164 virtual double operator()( double t
) const SAL_OVERRIDE
166 return (*mpFirstArg
)(t
) / (*mpSecondArg
)(t
);
170 class MinExpression
: public BinaryExpressionBase
173 MinExpression( const ExpressionNodeSharedPtr
& rFirstArg
,
174 const ExpressionNodeSharedPtr
& rSecondArg
) :
175 BinaryExpressionBase( rFirstArg
, rSecondArg
)
179 virtual double operator()( double t
) const SAL_OVERRIDE
181 return ::std::min( (*mpFirstArg
)(t
), (*mpSecondArg
)(t
) );
185 class MaxExpression
: public BinaryExpressionBase
188 MaxExpression( const ExpressionNodeSharedPtr
& rFirstArg
,
189 const ExpressionNodeSharedPtr
& rSecondArg
) :
190 BinaryExpressionBase( rFirstArg
, rSecondArg
)
194 virtual double operator()( double t
) const SAL_OVERRIDE
196 return ::std::max( (*mpFirstArg
)(t
), (*mpSecondArg
)(t
) );
201 ExpressionNodeSharedPtr
ExpressionNodeFactory::createConstantValueExpression( double rConstantValue
)
203 return ExpressionNodeSharedPtr( new ConstantValueExpression(rConstantValue
) );
206 ExpressionNodeSharedPtr
ExpressionNodeFactory::createValueTExpression()
208 return ExpressionNodeSharedPtr( new TValueExpression() );
211 ExpressionNodeSharedPtr
ExpressionNodeFactory::createPlusExpression( const ExpressionNodeSharedPtr
& rLHS
,
212 const ExpressionNodeSharedPtr
& rRHS
)
214 return ExpressionNodeSharedPtr( new PlusExpression(rLHS
, rRHS
) );
217 ExpressionNodeSharedPtr
ExpressionNodeFactory::createMinusExpression( const ExpressionNodeSharedPtr
& rLHS
,
218 const ExpressionNodeSharedPtr
& rRHS
)
220 return ExpressionNodeSharedPtr( new MinusExpression(rLHS
, rRHS
) );
223 ExpressionNodeSharedPtr
ExpressionNodeFactory::createMultipliesExpression( const ExpressionNodeSharedPtr
& rLHS
,
224 const ExpressionNodeSharedPtr
& rRHS
)
226 return ExpressionNodeSharedPtr( new MultipliesExpression(rLHS
, rRHS
) );
229 ExpressionNodeSharedPtr
ExpressionNodeFactory::createDividesExpression( const ExpressionNodeSharedPtr
& rLHS
,
230 const ExpressionNodeSharedPtr
& rRHS
)
232 return ExpressionNodeSharedPtr( new DividesExpression(rLHS
, rRHS
) );
235 ExpressionNodeSharedPtr
ExpressionNodeFactory::createMinExpression ( const ExpressionNodeSharedPtr
& rOuterFunction
,
236 const ExpressionNodeSharedPtr
& rInnerFunction
)
238 return ExpressionNodeSharedPtr( new MinExpression(rOuterFunction
, rInnerFunction
) );
241 ExpressionNodeSharedPtr
ExpressionNodeFactory::createMaxExpression ( const ExpressionNodeSharedPtr
& rOuterFunction
,
242 const ExpressionNodeSharedPtr
& rInnerFunction
)
244 return ExpressionNodeSharedPtr( new MaxExpression(rOuterFunction
, rInnerFunction
) );
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */