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 .
21 #include <expressionnodefactory.hxx>
23 #include <basegfx/matrix/b2dhommatrix.hxx>
24 #include <basegfx/point/b2dpoint.hxx>
30 /* Implementation of ExpressionNodeFactory class */
38 class ConstantValueExpression
: public ExpressionNode
41 explicit ConstantValueExpression( double rValue
) :
46 virtual double operator()( double /*t*/ ) const override
51 virtual bool isConstant() const override
60 class TValueExpression
: public ExpressionNode
67 virtual double operator()( double t
) const override
72 virtual bool isConstant() const override
78 /** Base class for following binary functions (*+-/)
80 Does not pay off to have all this as a template, since
81 we'd have to hold the functor as a member (+33% object
84 class BinaryExpressionBase
: public ExpressionNode
87 BinaryExpressionBase( const std::shared_ptr
<ExpressionNode
>& rFirstArg
,
88 const std::shared_ptr
<ExpressionNode
>& rSecondArg
) :
89 mpFirstArg( rFirstArg
),
90 mpSecondArg( rSecondArg
)
94 virtual bool isConstant() const override
97 mpFirstArg
->isConstant() &&
98 mpSecondArg
->isConstant();
102 std::shared_ptr
<ExpressionNode
> mpFirstArg
;
103 std::shared_ptr
<ExpressionNode
> mpSecondArg
;
106 class PlusExpression
: public BinaryExpressionBase
109 PlusExpression( const std::shared_ptr
<ExpressionNode
>& rFirstArg
,
110 const std::shared_ptr
<ExpressionNode
>& rSecondArg
) :
111 BinaryExpressionBase( rFirstArg
, rSecondArg
)
115 virtual double operator()( double t
) const override
117 return (*mpFirstArg
)(t
) + (*mpSecondArg
)(t
);
121 class MinusExpression
: public BinaryExpressionBase
124 MinusExpression( const std::shared_ptr
<ExpressionNode
>& rFirstArg
,
125 const std::shared_ptr
<ExpressionNode
>& rSecondArg
) :
126 BinaryExpressionBase( rFirstArg
, rSecondArg
)
130 virtual double operator()( double t
) const override
132 return (*mpFirstArg
)(t
) - (*mpSecondArg
)(t
);
136 class MultipliesExpression
: public BinaryExpressionBase
139 MultipliesExpression( const std::shared_ptr
<ExpressionNode
>& rFirstArg
,
140 const std::shared_ptr
<ExpressionNode
>& rSecondArg
) :
141 BinaryExpressionBase( rFirstArg
, rSecondArg
)
145 virtual double operator()( double t
) const override
147 return (*mpFirstArg
)(t
) * (*mpSecondArg
)(t
);
151 class DividesExpression
: public BinaryExpressionBase
154 DividesExpression( const std::shared_ptr
<ExpressionNode
>& rFirstArg
,
155 const std::shared_ptr
<ExpressionNode
>& rSecondArg
) :
156 BinaryExpressionBase( rFirstArg
, rSecondArg
)
160 virtual double operator()( double t
) const override
162 return (*mpFirstArg
)(t
) / (*mpSecondArg
)(t
);
166 class MinExpression
: public BinaryExpressionBase
169 MinExpression( const std::shared_ptr
<ExpressionNode
>& rFirstArg
,
170 const std::shared_ptr
<ExpressionNode
>& rSecondArg
) :
171 BinaryExpressionBase( rFirstArg
, rSecondArg
)
175 virtual double operator()( double t
) const override
177 return ::std::min( (*mpFirstArg
)(t
), (*mpSecondArg
)(t
) );
181 class MaxExpression
: public BinaryExpressionBase
184 MaxExpression( const std::shared_ptr
<ExpressionNode
>& rFirstArg
,
185 const std::shared_ptr
<ExpressionNode
>& rSecondArg
) :
186 BinaryExpressionBase( rFirstArg
, rSecondArg
)
190 virtual double operator()( double t
) const override
192 return ::std::max( (*mpFirstArg
)(t
), (*mpSecondArg
)(t
) );
197 std::shared_ptr
<ExpressionNode
> ExpressionNodeFactory::createConstantValueExpression( double rConstantValue
)
199 return std::shared_ptr
<ExpressionNode
>( new ConstantValueExpression(rConstantValue
) );
202 std::shared_ptr
<ExpressionNode
> ExpressionNodeFactory::createValueTExpression()
204 return std::shared_ptr
<ExpressionNode
>( new TValueExpression() );
207 std::shared_ptr
<ExpressionNode
> ExpressionNodeFactory::createPlusExpression( const std::shared_ptr
<ExpressionNode
>& rLHS
,
208 const std::shared_ptr
<ExpressionNode
>& rRHS
)
210 return std::shared_ptr
<ExpressionNode
>( new PlusExpression(rLHS
, rRHS
) );
213 std::shared_ptr
<ExpressionNode
> ExpressionNodeFactory::createMinusExpression( const std::shared_ptr
<ExpressionNode
>& rLHS
,
214 const std::shared_ptr
<ExpressionNode
>& rRHS
)
216 return std::shared_ptr
<ExpressionNode
>( new MinusExpression(rLHS
, rRHS
) );
219 std::shared_ptr
<ExpressionNode
> ExpressionNodeFactory::createMultipliesExpression( const std::shared_ptr
<ExpressionNode
>& rLHS
,
220 const std::shared_ptr
<ExpressionNode
>& rRHS
)
222 return std::shared_ptr
<ExpressionNode
>( new MultipliesExpression(rLHS
, rRHS
) );
225 std::shared_ptr
<ExpressionNode
> ExpressionNodeFactory::createDividesExpression( const std::shared_ptr
<ExpressionNode
>& rLHS
,
226 const std::shared_ptr
<ExpressionNode
>& rRHS
)
228 return std::shared_ptr
<ExpressionNode
>( new DividesExpression(rLHS
, rRHS
) );
231 std::shared_ptr
<ExpressionNode
> ExpressionNodeFactory::createMinExpression ( const std::shared_ptr
<ExpressionNode
>& rOuterFunction
,
232 const std::shared_ptr
<ExpressionNode
>& rInnerFunction
)
234 return std::shared_ptr
<ExpressionNode
>( new MinExpression(rOuterFunction
, rInnerFunction
) );
237 std::shared_ptr
<ExpressionNode
> ExpressionNodeFactory::createMaxExpression ( const std::shared_ptr
<ExpressionNode
>& rOuterFunction
,
238 const std::shared_ptr
<ExpressionNode
>& rInnerFunction
)
240 return std::shared_ptr
<ExpressionNode
>( new MaxExpression(rOuterFunction
, rInnerFunction
) );
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */