michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsSMILFloatType.h" michael@0: #include "nsSMILValue.h" michael@0: #include "nsDebug.h" michael@0: #include michael@0: michael@0: void michael@0: nsSMILFloatType::Init(nsSMILValue& aValue) const michael@0: { michael@0: NS_PRECONDITION(aValue.IsNull(), "Unexpected value type"); michael@0: aValue.mU.mDouble = 0.0; michael@0: aValue.mType = this; michael@0: } michael@0: michael@0: void michael@0: nsSMILFloatType::Destroy(nsSMILValue& aValue) const michael@0: { michael@0: NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value"); michael@0: aValue.mU.mDouble = 0.0; michael@0: aValue.mType = nsSMILNullType::Singleton(); michael@0: } michael@0: michael@0: nsresult michael@0: nsSMILFloatType::Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const michael@0: { michael@0: NS_PRECONDITION(aDest.mType == aSrc.mType, "Incompatible SMIL types"); michael@0: NS_PRECONDITION(aDest.mType == this, "Unexpected SMIL value"); michael@0: aDest.mU.mDouble = aSrc.mU.mDouble; michael@0: return NS_OK; michael@0: } michael@0: michael@0: bool michael@0: nsSMILFloatType::IsEqual(const nsSMILValue& aLeft, michael@0: const nsSMILValue& aRight) const michael@0: { michael@0: NS_PRECONDITION(aLeft.mType == aRight.mType, "Incompatible SMIL types"); michael@0: NS_PRECONDITION(aLeft.mType == this, "Unexpected type for SMIL value"); michael@0: michael@0: return aLeft.mU.mDouble == aRight.mU.mDouble; michael@0: } michael@0: michael@0: nsresult michael@0: nsSMILFloatType::Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd, michael@0: uint32_t aCount) const michael@0: { michael@0: NS_PRECONDITION(aValueToAdd.mType == aDest.mType, michael@0: "Trying to add invalid types"); michael@0: NS_PRECONDITION(aValueToAdd.mType == this, "Unexpected source type"); michael@0: aDest.mU.mDouble += aValueToAdd.mU.mDouble * aCount; michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: nsSMILFloatType::ComputeDistance(const nsSMILValue& aFrom, michael@0: const nsSMILValue& aTo, michael@0: double& aDistance) const michael@0: { michael@0: NS_PRECONDITION(aFrom.mType == aTo.mType,"Trying to compare different types"); michael@0: NS_PRECONDITION(aFrom.mType == this, "Unexpected source type"); michael@0: michael@0: const double &from = aFrom.mU.mDouble; michael@0: const double &to = aTo.mU.mDouble; michael@0: michael@0: aDistance = fabs(to - from); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: nsSMILFloatType::Interpolate(const nsSMILValue& aStartVal, michael@0: const nsSMILValue& aEndVal, michael@0: double aUnitDistance, michael@0: nsSMILValue& aResult) const michael@0: { michael@0: NS_PRECONDITION(aStartVal.mType == aEndVal.mType, michael@0: "Trying to interpolate different types"); michael@0: NS_PRECONDITION(aStartVal.mType == this, michael@0: "Unexpected types for interpolation"); michael@0: NS_PRECONDITION(aResult.mType == this, "Unexpected result type"); michael@0: michael@0: const double &startVal = aStartVal.mU.mDouble; michael@0: const double &endVal = aEndVal.mU.mDouble; michael@0: michael@0: aResult.mU.mDouble = (startVal + (endVal - startVal) * aUnitDistance); michael@0: michael@0: return NS_OK; michael@0: }