Bug 1816170 - Disable perftest-on-autoland cron. r=aglavic
[gecko.git] / dom / smil / SMILIntegerType.cpp
blobc1ac207836f887b6a787767978481ffa4f60f6d3
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 "SMILIntegerType.h"
9 #include "mozilla/SMILValue.h"
10 #include "nsDebug.h"
11 #include <math.h>
13 namespace mozilla {
15 void SMILIntegerType::Init(SMILValue& aValue) const {
16 MOZ_ASSERT(aValue.IsNull(), "Unexpected value type");
17 aValue.mU.mInt = 0;
18 aValue.mType = this;
21 void SMILIntegerType::Destroy(SMILValue& aValue) const {
22 MOZ_ASSERT(aValue.mType == this, "Unexpected SMIL value");
23 aValue.mU.mInt = 0;
24 aValue.mType = SMILNullType::Singleton();
27 nsresult SMILIntegerType::Assign(SMILValue& aDest,
28 const SMILValue& aSrc) const {
29 MOZ_ASSERT(aDest.mType == aSrc.mType, "Incompatible SMIL types");
30 MOZ_ASSERT(aDest.mType == this, "Unexpected SMIL value");
31 aDest.mU.mInt = aSrc.mU.mInt;
32 return NS_OK;
35 bool SMILIntegerType::IsEqual(const SMILValue& aLeft,
36 const SMILValue& aRight) const {
37 MOZ_ASSERT(aLeft.mType == aRight.mType, "Incompatible SMIL types");
38 MOZ_ASSERT(aLeft.mType == this, "Unexpected type for SMIL value");
40 return aLeft.mU.mInt == aRight.mU.mInt;
43 nsresult SMILIntegerType::Add(SMILValue& aDest, const SMILValue& aValueToAdd,
44 uint32_t aCount) const {
45 MOZ_ASSERT(aValueToAdd.mType == aDest.mType, "Trying to add invalid types");
46 MOZ_ASSERT(aValueToAdd.mType == this, "Unexpected source type");
47 aDest.mU.mInt += aValueToAdd.mU.mInt * aCount;
48 return NS_OK;
51 nsresult SMILIntegerType::ComputeDistance(const SMILValue& aFrom,
52 const SMILValue& aTo,
53 double& aDistance) const {
54 MOZ_ASSERT(aFrom.mType == aTo.mType, "Trying to compare different types");
55 MOZ_ASSERT(aFrom.mType == this, "Unexpected source type");
56 aDistance = fabs(double(aTo.mU.mInt - aFrom.mU.mInt));
57 return NS_OK;
60 nsresult SMILIntegerType::Interpolate(const SMILValue& aStartVal,
61 const SMILValue& aEndVal,
62 double aUnitDistance,
63 SMILValue& aResult) const {
64 MOZ_ASSERT(aStartVal.mType == aEndVal.mType,
65 "Trying to interpolate different types");
66 MOZ_ASSERT(aStartVal.mType == this, "Unexpected types for interpolation");
67 MOZ_ASSERT(aResult.mType == this, "Unexpected result type");
69 const double startVal = double(aStartVal.mU.mInt);
70 const double endVal = double(aEndVal.mU.mInt);
71 const double currentVal = startVal + (endVal - startVal) * aUnitDistance;
73 // When currentVal is exactly midway between its two nearest integers, we
74 // jump to the "next" integer to provide simple, easy to remember and
75 // consistent behaviour (from the SMIL author's point of view).
77 if (startVal < endVal) {
78 aResult.mU.mInt = int64_t(floor(currentVal + 0.5)); // round mid up
79 } else {
80 aResult.mU.mInt = int64_t(ceil(currentVal - 0.5)); // round mid down
83 return NS_OK;
86 } // namespace mozilla