fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / slideshow / source / engine / expressionnodefactory.cxx
blob9b6bffe42e88de7c49f99b061cf9e3b56a7e3ec7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 // must be first
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>
30 #include <functional>
31 #include <algorithm>
34 /* Implementation of ExpressionNodeFactory class */
36 namespace slideshow
38 namespace internal
40 namespace
42 class ConstantValueExpression : public ExpressionNode
44 public:
45 ConstantValueExpression( double rValue ) :
46 maValue( rValue )
50 virtual double operator()( double /*t*/ ) const SAL_OVERRIDE
52 return maValue;
55 virtual bool isConstant() const SAL_OVERRIDE
57 return true;
60 private:
61 double maValue;
64 class TValueExpression : public ExpressionNode
66 public:
67 TValueExpression()
71 virtual double operator()( double t ) const SAL_OVERRIDE
73 return t;
76 virtual bool isConstant() const SAL_OVERRIDE
78 return false;
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
86 size).
88 class BinaryExpressionBase : public ExpressionNode
90 public:
91 BinaryExpressionBase( const ExpressionNodeSharedPtr& rFirstArg,
92 const ExpressionNodeSharedPtr& rSecondArg ) :
93 mpFirstArg( rFirstArg ),
94 mpSecondArg( rSecondArg )
98 virtual bool isConstant() const SAL_OVERRIDE
100 return
101 mpFirstArg->isConstant() &&
102 mpSecondArg->isConstant();
105 protected:
106 ExpressionNodeSharedPtr mpFirstArg;
107 ExpressionNodeSharedPtr mpSecondArg;
110 class PlusExpression : public BinaryExpressionBase
112 public:
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
127 public:
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
142 public:
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
157 public:
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
172 public:
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
187 public:
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: */