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"
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;
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();
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];
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];
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
;
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");
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]);
85 SVGIntegerPairSMILType::Interpolate(const nsSMILValue
& aStartVal
,
86 const nsSMILValue
& aEndVal
,
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");
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]);
107 } // namespace mozilla