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 "SVGIntegerPairSMILType.h"
9 #include "mozilla/SMILValue.h"
10 #include "nsMathUtils.h"
15 void SVGIntegerPairSMILType::Init(SMILValue
& aValue
) const {
16 MOZ_ASSERT(aValue
.IsNull(), "Unexpected value type");
18 aValue
.mU
.mIntPair
[0] = 0;
19 aValue
.mU
.mIntPair
[1] = 0;
23 void SVGIntegerPairSMILType::Destroy(SMILValue
& aValue
) const {
24 MOZ_ASSERT(aValue
.mType
== this, "Unexpected SMIL value");
25 aValue
.mU
.mIntPair
[0] = 0;
26 aValue
.mU
.mIntPair
[1] = 0;
27 aValue
.mType
= SMILNullType::Singleton();
30 nsresult
SVGIntegerPairSMILType::Assign(SMILValue
& aDest
,
31 const SMILValue
& aSrc
) const {
32 MOZ_ASSERT(aDest
.mType
== aSrc
.mType
, "Incompatible SMIL types");
33 MOZ_ASSERT(aDest
.mType
== this, "Unexpected SMIL value");
35 aDest
.mU
.mIntPair
[0] = aSrc
.mU
.mIntPair
[0];
36 aDest
.mU
.mIntPair
[1] = aSrc
.mU
.mIntPair
[1];
40 bool SVGIntegerPairSMILType::IsEqual(const SMILValue
& aLeft
,
41 const SMILValue
& aRight
) const {
42 MOZ_ASSERT(aLeft
.mType
== aRight
.mType
, "Incompatible SMIL types");
43 MOZ_ASSERT(aLeft
.mType
== this, "Unexpected type for SMIL value");
45 return aLeft
.mU
.mIntPair
[0] == aRight
.mU
.mIntPair
[0] &&
46 aLeft
.mU
.mIntPair
[1] == aRight
.mU
.mIntPair
[1];
49 nsresult
SVGIntegerPairSMILType::Add(SMILValue
& aDest
,
50 const SMILValue
& aValueToAdd
,
51 uint32_t aCount
) const {
52 MOZ_ASSERT(aValueToAdd
.mType
== aDest
.mType
, "Trying to add invalid types");
53 MOZ_ASSERT(aValueToAdd
.mType
== this, "Unexpected source type");
55 aDest
.mU
.mIntPair
[0] += aValueToAdd
.mU
.mIntPair
[0] * aCount
;
56 aDest
.mU
.mIntPair
[1] += aValueToAdd
.mU
.mIntPair
[1] * aCount
;
61 nsresult
SVGIntegerPairSMILType::ComputeDistance(const SMILValue
& aFrom
,
63 double& aDistance
) const {
64 MOZ_ASSERT(aFrom
.mType
== aTo
.mType
, "Trying to compare different types");
65 MOZ_ASSERT(aFrom
.mType
== this, "Unexpected source type");
68 delta
[0] = aTo
.mU
.mIntPair
[0] - aFrom
.mU
.mIntPair
[0];
69 delta
[1] = aTo
.mU
.mIntPair
[1] - aFrom
.mU
.mIntPair
[1];
71 aDistance
= NS_hypot(delta
[0], delta
[1]);
75 nsresult
SVGIntegerPairSMILType::Interpolate(const SMILValue
& aStartVal
,
76 const SMILValue
& aEndVal
,
78 SMILValue
& aResult
) const {
79 MOZ_ASSERT(aStartVal
.mType
== aEndVal
.mType
,
80 "Trying to interpolate different types");
81 MOZ_ASSERT(aStartVal
.mType
== this, "Unexpected types for interpolation");
82 MOZ_ASSERT(aResult
.mType
== this, "Unexpected result type");
86 aStartVal
.mU
.mIntPair
[0] +
87 (aEndVal
.mU
.mIntPair
[0] - aStartVal
.mU
.mIntPair
[0]) * aUnitDistance
;
89 aStartVal
.mU
.mIntPair
[1] +
90 (aEndVal
.mU
.mIntPair
[1] - aStartVal
.mU
.mIntPair
[1]) * aUnitDistance
;
92 aResult
.mU
.mIntPair
[0] = NS_lround(currentVal
[0]);
93 aResult
.mU
.mIntPair
[1] = NS_lround(currentVal
[1]);
97 } // namespace mozilla