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 "nsSMILFloatType.h"
7 #include "nsSMILValue.h"
12 nsSMILFloatType::Init(nsSMILValue
& aValue
) const
14 NS_PRECONDITION(aValue
.IsNull(), "Unexpected value type");
15 aValue
.mU
.mDouble
= 0.0;
20 nsSMILFloatType::Destroy(nsSMILValue
& aValue
) const
22 NS_PRECONDITION(aValue
.mType
== this, "Unexpected SMIL value");
23 aValue
.mU
.mDouble
= 0.0;
24 aValue
.mType
= nsSMILNullType::Singleton();
28 nsSMILFloatType::Assign(nsSMILValue
& aDest
, const nsSMILValue
& aSrc
) const
30 NS_PRECONDITION(aDest
.mType
== aSrc
.mType
, "Incompatible SMIL types");
31 NS_PRECONDITION(aDest
.mType
== this, "Unexpected SMIL value");
32 aDest
.mU
.mDouble
= aSrc
.mU
.mDouble
;
37 nsSMILFloatType::IsEqual(const nsSMILValue
& aLeft
,
38 const nsSMILValue
& aRight
) const
40 NS_PRECONDITION(aLeft
.mType
== aRight
.mType
, "Incompatible SMIL types");
41 NS_PRECONDITION(aLeft
.mType
== this, "Unexpected type for SMIL value");
43 return aLeft
.mU
.mDouble
== aRight
.mU
.mDouble
;
47 nsSMILFloatType::Add(nsSMILValue
& aDest
, const nsSMILValue
& aValueToAdd
,
48 uint32_t aCount
) const
50 NS_PRECONDITION(aValueToAdd
.mType
== aDest
.mType
,
51 "Trying to add invalid types");
52 NS_PRECONDITION(aValueToAdd
.mType
== this, "Unexpected source type");
53 aDest
.mU
.mDouble
+= aValueToAdd
.mU
.mDouble
* aCount
;
58 nsSMILFloatType::ComputeDistance(const nsSMILValue
& aFrom
,
59 const nsSMILValue
& aTo
,
60 double& aDistance
) const
62 NS_PRECONDITION(aFrom
.mType
== aTo
.mType
,"Trying to compare different types");
63 NS_PRECONDITION(aFrom
.mType
== this, "Unexpected source type");
65 const double &from
= aFrom
.mU
.mDouble
;
66 const double &to
= aTo
.mU
.mDouble
;
68 aDistance
= fabs(to
- from
);
74 nsSMILFloatType::Interpolate(const nsSMILValue
& aStartVal
,
75 const nsSMILValue
& aEndVal
,
77 nsSMILValue
& aResult
) const
79 NS_PRECONDITION(aStartVal
.mType
== aEndVal
.mType
,
80 "Trying to interpolate different types");
81 NS_PRECONDITION(aStartVal
.mType
== this,
82 "Unexpected types for interpolation");
83 NS_PRECONDITION(aResult
.mType
== this, "Unexpected result type");
85 const double &startVal
= aStartVal
.mU
.mDouble
;
86 const double &endVal
= aEndVal
.mU
.mDouble
;
88 aResult
.mU
.mDouble
= (startVal
+ (endVal
- startVal
) * aUnitDistance
);