Bug 1892041 - Part 1: Update test262 features. r=spidermonkey-reviewers,dminor
[gecko.git] / dom / svg / SVGNumberPairSMILType.cpp
blobf0c6a6186203fd1ebe5fc041cef5188f57088ceb
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 "SVGNumberPairSMILType.h"
9 #include "mozilla/SMILValue.h"
10 #include "nsMathUtils.h"
11 #include "nsDebug.h"
13 namespace mozilla {
15 /*static*/
16 SVGNumberPairSMILType SVGNumberPairSMILType::sSingleton;
18 void SVGNumberPairSMILType::Init(SMILValue& aValue) const {
19 MOZ_ASSERT(aValue.IsNull(), "Unexpected value type");
21 aValue.mU.mNumberPair[0] = 0;
22 aValue.mU.mNumberPair[1] = 0;
23 aValue.mType = this;
26 void SVGNumberPairSMILType::Destroy(SMILValue& aValue) const {
27 MOZ_ASSERT(aValue.mType == this, "Unexpected SMIL value");
28 aValue.mU.mNumberPair[0] = 0;
29 aValue.mU.mNumberPair[1] = 0;
30 aValue.mType = SMILNullType::Singleton();
33 nsresult SVGNumberPairSMILType::Assign(SMILValue& aDest,
34 const SMILValue& aSrc) const {
35 MOZ_ASSERT(aDest.mType == aSrc.mType, "Incompatible SMIL types");
36 MOZ_ASSERT(aDest.mType == this, "Unexpected SMIL value");
38 aDest.mU.mNumberPair[0] = aSrc.mU.mNumberPair[0];
39 aDest.mU.mNumberPair[1] = aSrc.mU.mNumberPair[1];
40 return NS_OK;
43 bool SVGNumberPairSMILType::IsEqual(const SMILValue& aLeft,
44 const SMILValue& aRight) const {
45 MOZ_ASSERT(aLeft.mType == aRight.mType, "Incompatible SMIL types");
46 MOZ_ASSERT(aLeft.mType == this, "Unexpected type for SMIL value");
48 return aLeft.mU.mNumberPair[0] == aRight.mU.mNumberPair[0] &&
49 aLeft.mU.mNumberPair[1] == aRight.mU.mNumberPair[1];
52 nsresult SVGNumberPairSMILType::Add(SMILValue& aDest,
53 const SMILValue& aValueToAdd,
54 uint32_t aCount) const {
55 MOZ_ASSERT(aValueToAdd.mType == aDest.mType, "Trying to add invalid types");
56 MOZ_ASSERT(aValueToAdd.mType == this, "Unexpected source type");
58 aDest.mU.mNumberPair[0] += aValueToAdd.mU.mNumberPair[0] * aCount;
59 aDest.mU.mNumberPair[1] += aValueToAdd.mU.mNumberPair[1] * aCount;
61 return NS_OK;
64 nsresult SVGNumberPairSMILType::ComputeDistance(const SMILValue& aFrom,
65 const SMILValue& aTo,
66 double& aDistance) const {
67 MOZ_ASSERT(aFrom.mType == aTo.mType, "Trying to compare different types");
68 MOZ_ASSERT(aFrom.mType == this, "Unexpected source type");
70 double delta[2];
71 delta[0] = aTo.mU.mNumberPair[0] - aFrom.mU.mNumberPair[0];
72 delta[1] = aTo.mU.mNumberPair[1] - aFrom.mU.mNumberPair[1];
74 aDistance = NS_hypot(delta[0], delta[1]);
75 return NS_OK;
78 nsresult SVGNumberPairSMILType::Interpolate(const SMILValue& aStartVal,
79 const SMILValue& aEndVal,
80 double aUnitDistance,
81 SMILValue& aResult) const {
82 MOZ_ASSERT(aStartVal.mType == aEndVal.mType,
83 "Trying to interpolate different types");
84 MOZ_ASSERT(aStartVal.mType == this, "Unexpected types for interpolation");
85 MOZ_ASSERT(aResult.mType == this, "Unexpected result type");
87 aResult.mU.mNumberPair[0] =
88 float(aStartVal.mU.mNumberPair[0] +
89 (aEndVal.mU.mNumberPair[0] - aStartVal.mU.mNumberPair[0]) *
90 aUnitDistance);
91 aResult.mU.mNumberPair[1] =
92 float(aStartVal.mU.mNumberPair[1] +
93 (aEndVal.mU.mNumberPair[1] - aStartVal.mU.mNumberPair[1]) *
94 aUnitDistance);
95 return NS_OK;
98 } // namespace mozilla