Bumping manifests a=b2g-bump
[gecko.git] / dom / svg / SVGIntegerPairSMILType.cpp
blob41779327ba22919fdb14d9a5e055f0619f2656ab
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "SVGIntegerPairSMILType.h"
7 #include "nsSMILValue.h"
8 #include "nsMathUtils.h"
9 #include "nsDebug.h"
11 namespace mozilla {
13 void
14 SVGIntegerPairSMILType::Init(nsSMILValue& aValue) const
16 NS_ABORT_IF_FALSE(aValue.IsNull(), "Unexpected value type");
18 aValue.mU.mIntPair[0] = 0;
19 aValue.mU.mIntPair[1] = 0;
20 aValue.mType = this;
23 void
24 SVGIntegerPairSMILType::Destroy(nsSMILValue& aValue) const
26 NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value");
27 aValue.mU.mIntPair[0] = 0;
28 aValue.mU.mIntPair[1] = 0;
29 aValue.mType = nsSMILNullType::Singleton();
32 nsresult
33 SVGIntegerPairSMILType::Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const
35 NS_PRECONDITION(aDest.mType == aSrc.mType, "Incompatible SMIL types");
36 NS_PRECONDITION(aDest.mType == this, "Unexpected SMIL value");
38 aDest.mU.mIntPair[0] = aSrc.mU.mIntPair[0];
39 aDest.mU.mIntPair[1] = aSrc.mU.mIntPair[1];
40 return NS_OK;
43 bool
44 SVGIntegerPairSMILType::IsEqual(const nsSMILValue& aLeft,
45 const nsSMILValue& aRight) const
47 NS_PRECONDITION(aLeft.mType == aRight.mType, "Incompatible SMIL types");
48 NS_PRECONDITION(aLeft.mType == this, "Unexpected type for SMIL value");
50 return aLeft.mU.mIntPair[0] == aRight.mU.mIntPair[0] &&
51 aLeft.mU.mIntPair[1] == aRight.mU.mIntPair[1];
54 nsresult
55 SVGIntegerPairSMILType::Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd,
56 uint32_t aCount) const
58 NS_PRECONDITION(aValueToAdd.mType == aDest.mType,
59 "Trying to add invalid types");
60 NS_PRECONDITION(aValueToAdd.mType == this, "Unexpected source type");
62 aDest.mU.mIntPair[0] += aValueToAdd.mU.mIntPair[0] * aCount;
63 aDest.mU.mIntPair[1] += aValueToAdd.mU.mIntPair[1] * aCount;
65 return NS_OK;
68 nsresult
69 SVGIntegerPairSMILType::ComputeDistance(const nsSMILValue& aFrom,
70 const nsSMILValue& aTo,
71 double& aDistance) const
73 NS_PRECONDITION(aFrom.mType == aTo.mType,"Trying to compare different types");
74 NS_PRECONDITION(aFrom.mType == this, "Unexpected source type");
76 double delta[2];
77 delta[0] = aTo.mU.mIntPair[0] - aFrom.mU.mIntPair[0];
78 delta[1] = aTo.mU.mIntPair[1] - aFrom.mU.mIntPair[1];
80 aDistance = NS_hypot(delta[0], delta[1]);
81 return NS_OK;
84 nsresult
85 SVGIntegerPairSMILType::Interpolate(const nsSMILValue& aStartVal,
86 const nsSMILValue& aEndVal,
87 double aUnitDistance,
88 nsSMILValue& aResult) const
90 NS_PRECONDITION(aStartVal.mType == aEndVal.mType,
91 "Trying to interpolate different types");
92 NS_PRECONDITION(aStartVal.mType == this,
93 "Unexpected types for interpolation");
94 NS_PRECONDITION(aResult.mType == this, "Unexpected result type");
96 double currentVal[2];
97 currentVal[0] = aStartVal.mU.mIntPair[0] +
98 (aEndVal.mU.mIntPair[0] - aStartVal.mU.mIntPair[0]) * aUnitDistance;
99 currentVal[1] = aStartVal.mU.mIntPair[1] +
100 (aEndVal.mU.mIntPair[1] - aStartVal.mU.mIntPair[1]) * aUnitDistance;
102 aResult.mU.mIntPair[0] = NS_lround(currentVal[0]);
103 aResult.mU.mIntPair[1] = NS_lround(currentVal[1]);
104 return NS_OK;
107 } // namespace mozilla