1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_slideshow.hxx" 30 31 // must be first 32 #include <canvas/debug.hxx> 33 #include <expressionnodefactory.hxx> 34 35 #include <canvas/verbosetrace.hxx> 36 37 #include <basegfx/matrix/b2dhommatrix.hxx> 38 #include <basegfx/point/b2dpoint.hxx> 39 40 #include <functional> 41 #include <algorithm> 42 43 44 /* Implementation of ExpressionNodeFactory class */ 45 46 namespace slideshow 47 { 48 namespace internal 49 { 50 namespace 51 { 52 class ConstantValueExpression : public ExpressionNode 53 { 54 public: 55 ConstantValueExpression( double rValue ) : 56 maValue( rValue ) 57 { 58 } 59 60 virtual double operator()( double /*t*/ ) const 61 { 62 return maValue; 63 } 64 65 virtual bool isConstant() const 66 { 67 return true; 68 } 69 70 private: 71 double maValue; 72 }; 73 74 class TValueExpression : public ExpressionNode 75 { 76 public: 77 TValueExpression() 78 { 79 } 80 81 virtual double operator()( double t ) const 82 { 83 return t; 84 } 85 86 virtual bool isConstant() const 87 { 88 return false; 89 } 90 }; 91 92 /** Base class for following binary functions (*+-/) 93 94 Does not pay off to have all this as a template, since 95 we'd have to hold the functor as a member (+33% object 96 size). 97 */ 98 class BinaryExpressionBase : public ExpressionNode 99 { 100 public: 101 BinaryExpressionBase( const ExpressionNodeSharedPtr& rFirstArg, 102 const ExpressionNodeSharedPtr& rSecondArg ) : 103 mpFirstArg( rFirstArg ), 104 mpSecondArg( rSecondArg ) 105 { 106 } 107 108 virtual bool isConstant() const 109 { 110 return 111 mpFirstArg->isConstant() && 112 mpSecondArg->isConstant(); 113 } 114 115 protected: 116 ExpressionNodeSharedPtr mpFirstArg; 117 ExpressionNodeSharedPtr mpSecondArg; 118 }; 119 120 class PlusExpression : public BinaryExpressionBase 121 { 122 public: 123 PlusExpression( const ExpressionNodeSharedPtr& rFirstArg, 124 const ExpressionNodeSharedPtr& rSecondArg ) : 125 BinaryExpressionBase( rFirstArg, rSecondArg ) 126 { 127 } 128 129 virtual double operator()( double t ) const 130 { 131 return (*mpFirstArg)(t) + (*mpSecondArg)(t); 132 } 133 }; 134 135 class MinusExpression : public BinaryExpressionBase 136 { 137 public: 138 MinusExpression( const ExpressionNodeSharedPtr& rFirstArg, 139 const ExpressionNodeSharedPtr& rSecondArg ) : 140 BinaryExpressionBase( rFirstArg, rSecondArg ) 141 { 142 } 143 144 virtual double operator()( double t ) const 145 { 146 return (*mpFirstArg)(t) - (*mpSecondArg)(t); 147 } 148 }; 149 150 class MultipliesExpression : public BinaryExpressionBase 151 { 152 public: 153 MultipliesExpression( const ExpressionNodeSharedPtr& rFirstArg, 154 const ExpressionNodeSharedPtr& rSecondArg ) : 155 BinaryExpressionBase( rFirstArg, rSecondArg ) 156 { 157 } 158 159 virtual double operator()( double t ) const 160 { 161 return (*mpFirstArg)(t) * (*mpSecondArg)(t); 162 } 163 }; 164 165 class DividesExpression : public BinaryExpressionBase 166 { 167 public: 168 DividesExpression( const ExpressionNodeSharedPtr& rFirstArg, 169 const ExpressionNodeSharedPtr& rSecondArg ) : 170 BinaryExpressionBase( rFirstArg, rSecondArg ) 171 { 172 } 173 174 virtual double operator()( double t ) const 175 { 176 return (*mpFirstArg)(t) / (*mpSecondArg)(t); 177 } 178 }; 179 180 class ComposedExpression : public BinaryExpressionBase 181 { 182 public: 183 ComposedExpression( const ExpressionNodeSharedPtr& rFirstArg, 184 const ExpressionNodeSharedPtr& rSecondArg ) : 185 BinaryExpressionBase( rFirstArg, rSecondArg ) 186 { 187 } 188 189 virtual double operator()( double t ) const 190 { 191 return (*mpFirstArg)( (*mpSecondArg)(t) ); 192 } 193 }; 194 195 class MinExpression : public BinaryExpressionBase 196 { 197 public: 198 MinExpression( const ExpressionNodeSharedPtr& rFirstArg, 199 const ExpressionNodeSharedPtr& rSecondArg ) : 200 BinaryExpressionBase( rFirstArg, rSecondArg ) 201 { 202 } 203 204 virtual double operator()( double t ) const 205 { 206 return ::std::min( (*mpFirstArg)(t), (*mpSecondArg)(t) ); 207 } 208 }; 209 210 class MaxExpression : public BinaryExpressionBase 211 { 212 public: 213 MaxExpression( const ExpressionNodeSharedPtr& rFirstArg, 214 const ExpressionNodeSharedPtr& rSecondArg ) : 215 BinaryExpressionBase( rFirstArg, rSecondArg ) 216 { 217 } 218 219 virtual double operator()( double t ) const 220 { 221 return ::std::max( (*mpFirstArg)(t), (*mpSecondArg)(t) ); 222 } 223 }; 224 } 225 226 ExpressionNodeSharedPtr ExpressionNodeFactory::createConstantValueExpression( double rConstantValue ) 227 { 228 return ExpressionNodeSharedPtr( new ConstantValueExpression(rConstantValue) ); 229 } 230 231 ExpressionNodeSharedPtr ExpressionNodeFactory::createValueTExpression() 232 { 233 return ExpressionNodeSharedPtr( new TValueExpression() ); 234 } 235 236 ExpressionNodeSharedPtr ExpressionNodeFactory::createPlusExpression( const ExpressionNodeSharedPtr& rLHS, 237 const ExpressionNodeSharedPtr& rRHS ) 238 { 239 return ExpressionNodeSharedPtr( new PlusExpression(rLHS, rRHS) ); 240 } 241 242 ExpressionNodeSharedPtr ExpressionNodeFactory::createMinusExpression( const ExpressionNodeSharedPtr& rLHS, 243 const ExpressionNodeSharedPtr& rRHS ) 244 { 245 return ExpressionNodeSharedPtr( new MinusExpression(rLHS, rRHS) ); 246 } 247 248 ExpressionNodeSharedPtr ExpressionNodeFactory::createMultipliesExpression( const ExpressionNodeSharedPtr& rLHS, 249 const ExpressionNodeSharedPtr& rRHS ) 250 { 251 return ExpressionNodeSharedPtr( new MultipliesExpression(rLHS, rRHS) ); 252 } 253 254 ExpressionNodeSharedPtr ExpressionNodeFactory::createDividesExpression( const ExpressionNodeSharedPtr& rLHS, 255 const ExpressionNodeSharedPtr& rRHS ) 256 { 257 return ExpressionNodeSharedPtr( new DividesExpression(rLHS, rRHS) ); 258 } 259 260 ExpressionNodeSharedPtr ExpressionNodeFactory::createComposedExpression ( const ExpressionNodeSharedPtr& rOuterFunction, 261 const ExpressionNodeSharedPtr& rInnerFunction ) 262 { 263 return ExpressionNodeSharedPtr( new ComposedExpression(rOuterFunction, rInnerFunction) ); 264 } 265 266 ExpressionNodeSharedPtr ExpressionNodeFactory::createMinExpression ( const ExpressionNodeSharedPtr& rOuterFunction, 267 const ExpressionNodeSharedPtr& rInnerFunction ) 268 { 269 return ExpressionNodeSharedPtr( new MinExpression(rOuterFunction, rInnerFunction) ); 270 } 271 272 ExpressionNodeSharedPtr ExpressionNodeFactory::createMaxExpression ( const ExpressionNodeSharedPtr& rOuterFunction, 273 const ExpressionNodeSharedPtr& rInnerFunction ) 274 { 275 return ExpressionNodeSharedPtr( new MaxExpression(rOuterFunction, rInnerFunction) ); 276 } 277 278 } 279 } 280