no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / smil / SMILFloatType.cpp
blobac50cfe8d28272afd3c32bd2e8ced85e5a27d5cc
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "SMILFloatType.h"
9 #include "mozilla/SMILValue.h"
10 #include "nsDebug.h"
11 #include <math.h>
13 namespace mozilla {
15 void SMILFloatType::Init(SMILValue& aValue) const {
16 MOZ_ASSERT(aValue.IsNull(), "Unexpected value type");
17 aValue.mU.mDouble = 0.0;
18 aValue.mType = this;
21 void SMILFloatType::Destroy(SMILValue& aValue) const {
22 MOZ_ASSERT(aValue.mType == this, "Unexpected SMIL value");
23 aValue.mU.mDouble = 0.0;
24 aValue.mType = SMILNullType::Singleton();
27 nsresult SMILFloatType::Assign(SMILValue& aDest, const SMILValue& aSrc) const {
28 MOZ_ASSERT(aDest.mType == aSrc.mType, "Incompatible SMIL types");
29 MOZ_ASSERT(aDest.mType == this, "Unexpected SMIL value");
30 aDest.mU.mDouble = aSrc.mU.mDouble;
31 return NS_OK;
34 bool SMILFloatType::IsEqual(const SMILValue& aLeft,
35 const SMILValue& aRight) const {
36 MOZ_ASSERT(aLeft.mType == aRight.mType, "Incompatible SMIL types");
37 MOZ_ASSERT(aLeft.mType == this, "Unexpected type for SMIL value");
39 return aLeft.mU.mDouble == aRight.mU.mDouble;
42 nsresult SMILFloatType::Add(SMILValue& aDest, const SMILValue& aValueToAdd,
43 uint32_t aCount) const {
44 MOZ_ASSERT(aValueToAdd.mType == aDest.mType, "Trying to add invalid types");
45 MOZ_ASSERT(aValueToAdd.mType == this, "Unexpected source type");
46 aDest.mU.mDouble += aValueToAdd.mU.mDouble * aCount;
47 return NS_OK;
50 nsresult SMILFloatType::ComputeDistance(const SMILValue& aFrom,
51 const SMILValue& aTo,
52 double& aDistance) const {
53 MOZ_ASSERT(aFrom.mType == aTo.mType, "Trying to compare different types");
54 MOZ_ASSERT(aFrom.mType == this, "Unexpected source type");
56 const double& from = aFrom.mU.mDouble;
57 const double& to = aTo.mU.mDouble;
59 aDistance = fabs(to - from);
61 return NS_OK;
64 nsresult SMILFloatType::Interpolate(const SMILValue& aStartVal,
65 const SMILValue& aEndVal,
66 double aUnitDistance,
67 SMILValue& aResult) const {
68 MOZ_ASSERT(aStartVal.mType == aEndVal.mType,
69 "Trying to interpolate different types");
70 MOZ_ASSERT(aStartVal.mType == this, "Unexpected types for interpolation");
71 MOZ_ASSERT(aResult.mType == this, "Unexpected result type");
73 const double& startVal = aStartVal.mU.mDouble;
74 const double& endVal = aEndVal.mU.mDouble;
76 aResult.mU.mDouble = (startVal + (endVal - startVal) * aUnitDistance);
78 return NS_OK;
81 } // namespace mozilla