void Animation::play() { PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand); if (!playing()) m_startTime = nullValue(); if (playStateInternal() == Idle) { // We may not go into the pending state, but setting it to something other // than Idle here will force an update. ASSERT(isNull(m_startTime)); m_playState = Pending; m_held = true; m_holdTime = 0; } m_finished = false; unpauseInternal(); if (!m_content) return; double currentTime = this->currentTimeInternal(); if (m_playbackRate > 0 && (currentTime < 0 || currentTime >= effectEnd())) { m_startTime = nullValue(); setCurrentTimeInternal(0, TimingUpdateOnDemand); } else if (m_playbackRate < 0 && (currentTime <= 0 || currentTime > effectEnd())) { m_startTime = nullValue(); setCurrentTimeInternal(effectEnd(), TimingUpdateOnDemand); } }
void AnimationPlayer::setCurrentTimeInternal(double newCurrentTime, TimingUpdateReason reason) { ASSERT(std::isfinite(newCurrentTime)); bool oldHeld = m_held; bool outdated = false; bool isLimited = limited(newCurrentTime); m_held = m_paused || !m_playbackRate || isLimited || std::isnan(m_startTime); if (m_held) { if (!oldHeld || m_holdTime != newCurrentTime) outdated = true; m_holdTime = newCurrentTime; if (m_paused || !m_playbackRate) { m_startTime = nullValue(); } else if (isLimited && std::isnan(m_startTime) && reason == TimingUpdateForAnimationFrame) { m_startTime = calculateStartTime(newCurrentTime); } } else { m_holdTime = nullValue(); m_startTime = calculateStartTime(newCurrentTime); m_finished = false; outdated = true; } if (outdated) { setOutdated(); } }
wchar_t* String::copyValue(const wchar_t* _pwstData) { if (_pwstData == nullValue()) { return nullValue(); } return os_wcsdup(_pwstData); }
Player::Player(DocumentTimeline& timeline, TimedItem* content) : m_pauseStartTime(nullValue()) , m_playbackRate(1) , m_timeDrift(0) , m_startTime(nullValue()) , m_content(content) , m_timeline(timeline) , m_isPausedForTesting(false) { if (m_content) m_content->attach(this); }
bool Animation::update(TimingUpdateReason reason) { if (!m_timeline) return false; PlayStateUpdateScope updateScope(*this, reason, DoNotSetCompositorPending); clearOutdated(); bool idle = playStateInternal() == Idle; if (m_content) { double inheritedTime = idle || isNull(m_timeline->currentTimeInternal()) ? nullValue() : currentTimeInternal(); if (!isNull(inheritedTime)) { double timeForClipping = m_held && (!limited(inheritedTime) || isNull(m_startTime)) // Use hold time when there is no start time. ? inheritedTime // Use calculated current time when the animation is limited. : calculateCurrentTime(); if (clipped(timeForClipping)) inheritedTime = nullValue(); } // Special case for end-exclusivity when playing backwards. if (inheritedTime == 0 && m_playbackRate < 0) inheritedTime = -1; m_content->updateInheritedTime(inheritedTime, reason); } if ((idle || limited()) && !m_finished) { if (reason == TimingUpdateForAnimationFrame && (idle || hasStartTime())) { if (idle) { // TODO(dstockwell): Fire the cancel event. } else { const AtomicString& eventType = EventTypeNames::finish; if (executionContext() && hasEventListeners(eventType)) { double eventCurrentTime = currentTimeInternal() * 1000; m_pendingFinishedEvent = AnimationPlayerEvent::create(eventType, eventCurrentTime, timeline()->currentTime()); m_pendingFinishedEvent->setTarget(this); m_pendingFinishedEvent->setCurrentTarget(this); m_timeline->document()->enqueueAnimationFrameEvent(m_pendingFinishedEvent); } } m_finished = true; } } ASSERT(!m_outdated); return !m_finished || std::isfinite(timeToEffectChange()); }
void AnimationPlayer::updateTimingState(double newCurrentTime) { ASSERT(!isNull(newCurrentTime)); bool oldHeld = m_held; m_held = m_paused || !m_playbackRate || limited(newCurrentTime); if (m_held) { if (!oldHeld || m_holdTime != newCurrentTime) setOutdated(); m_holdTime = newCurrentTime; m_storedTimeLag = nullValue(); } else { m_holdTime = nullValue(); m_storedTimeLag = currentTimeWithoutLag() - newCurrentTime; setOutdated(); } }
bool AnimationPlayer::update(TimingUpdateReason reason) { if (!m_timeline) return false; updateCurrentTimingState(reason); m_outdated = false; if (m_content) { double inheritedTime = isNull(m_timeline->currentTimeInternal()) ? nullValue() : currentTimeInternal(); m_content->updateInheritedTime(inheritedTime, reason); } if (finished() && !m_finished) { if (reason == TimingUpdateForAnimationFrame && hasStartTime()) { const AtomicString& eventType = EventTypeNames::finish; if (executionContext() && hasEventListeners(eventType)) { m_pendingFinishedEvent = AnimationPlayerEvent::create(eventType, currentTime(), timeline()->currentTime()); m_pendingFinishedEvent->setTarget(this); m_pendingFinishedEvent->setCurrentTarget(this); m_timeline->document()->enqueueAnimationFrameEvent(m_pendingFinishedEvent); } m_finished = true; } } ASSERT(!m_outdated); return !m_finished || !finished(); }
AnimationPlayer::AnimationPlayer(ExecutionContext* executionContext, AnimationTimeline& timeline, AnimationNode* content) : ActiveDOMObject(executionContext) , m_playState(Idle) , m_playbackRate(1) , m_startTime(nullValue()) , m_holdTime(0) , m_sequenceNumber(nextSequenceNumber()) , m_content(content) , m_timeline(&timeline) , m_paused(false) , m_held(true) , m_isPausedForTesting(false) , m_outdated(true) , m_finished(true) , m_compositorState(nullptr) , m_compositorPending(true) , m_compositorGroup(0) , m_currentTimePending(false) , m_stateIsBeingUpdated(false) { if (m_content) { if (m_content->player()) { m_content->player()->cancel(); m_content->player()->setSource(0); } m_content->attach(this); } }
bool AnimationPlayer::update(TimingUpdateReason reason) { if (!m_timeline) return false; PlayStateUpdateScope updateScope(*this, reason, DoNotSetCompositorPending); m_outdated = false; bool idle = playStateInternal() == Idle; if (m_content) { double inheritedTime = idle || isNull(m_timeline->currentTimeInternal()) ? nullValue() : currentTimeInternal(); // Special case for end-exclusivity when playing backwards. if (inheritedTime == 0 && m_playbackRate < 0) inheritedTime = -1; m_content->updateInheritedTime(inheritedTime, reason); } if ((idle || finished()) && !m_finished) { if (reason == TimingUpdateForAnimationFrame && (idle || hasStartTime())) { const AtomicString& eventType = EventTypeNames::finish; if (executionContext() && hasEventListeners(eventType)) { double eventCurrentTime = currentTimeInternal() * 1000; m_pendingFinishedEvent = AnimationPlayerEvent::create(eventType, eventCurrentTime, timeline()->currentTime()); m_pendingFinishedEvent->setTarget(this); m_pendingFinishedEvent->setCurrentTarget(this); m_timeline->document()->enqueueAnimationFrameEvent(m_pendingFinishedEvent); } m_finished = true; } } ASSERT(!m_outdated); return !m_finished; }
Animation::Animation(ExecutionContext* executionContext, AnimationTimeline& timeline, AnimationEffect* content) : ActiveDOMObject(executionContext) , m_playState(Idle) , m_playbackRate(1) , m_startTime(nullValue()) , m_holdTime(0) , m_startClip(-std::numeric_limits<double>::infinity()) , m_endClip(std::numeric_limits<double>::infinity()) , m_sequenceNumber(nextSequenceNumber()) , m_content(content) , m_timeline(&timeline) , m_paused(false) , m_held(true) , m_isPausedForTesting(false) , m_isCompositedAnimationDisabledForTesting(false) , m_outdated(false) , m_finished(true) , m_compositorState(nullptr) , m_compositorPending(false) , m_compositorGroup(0) , m_currentTimePending(false) , m_stateIsBeingUpdated(false) { if (m_content) { if (m_content->animation()) { m_content->animation()->cancel(); m_content->animation()->setEffect(0); } m_content->attach(this); } InspectorInstrumentation::didCreateAnimation(m_timeline->document(), m_sequenceNumber); }
double SmallerOverlapExtractor::extract(const OsmMap& map, const ConstElementPtr& target, const ConstElementPtr& candidate) const { ElementConverter ec(map.shared_from_this()); shared_ptr<Geometry> g1 = ec.convertToGeometry(target); shared_ptr<Geometry> g2 = ec.convertToGeometry(candidate); if (g1->isEmpty() || g2->isEmpty()) { return nullValue(); } auto_ptr<Geometry> overlap; try { overlap.reset(g1->intersection(g2.get())); } catch (geos::util::TopologyException& e) { g1.reset(GeometryUtils::validateGeometry(g1.get())); g2.reset(GeometryUtils::validateGeometry(g2.get())); overlap.reset(g2->intersection(g1.get())); } double a1 = g1->getArea(); double a2 = g2->getArea(); double overlapArea = overlap->getArea(); if (a1 == 0.0 || a2 == 0.0) { return 0.0; } return std::min(1.0, overlapArea / min(a1, a2)); }
groovyBCCommon<Type>::groovyBCCommon ( bool hasGradient, bool isPoint, string fractionExpression ) : evaluateDuringConstruction_(false), debug_(false), hasGradient_(hasGradient), fractionExpression_(isPoint ? "toPoint("+fractionExpression+")" : fractionExpression) { valueExpression_ = nullValue(); if(hasGradient_) { gradientExpression_ = nullValue(); } }
void String::deleteData(wchar_t* data) { if (data && data != nullValue()) { // data are always allocated using C-like malloc API FREE(data); } }
double WayFeatureExtractor::extract(const OsmMap& map, const shared_ptr<const Element>& target, const shared_ptr<const Element>& candidate) const { vector<double> scores; if (target->getElementType() == ElementType::Way && candidate->getElementType() == ElementType::Way) { scores.push_back(_extract(map, dynamic_pointer_cast<const Way>(target), dynamic_pointer_cast<const Way>(candidate))); } else if (target->getElementType() == ElementType::Relation && candidate->getElementType() == ElementType::Relation) { ConstRelationPtr r1 = dynamic_pointer_cast<const Relation>(target); ConstRelationPtr r2 = dynamic_pointer_cast<const Relation>(candidate); if (r1->getType() == Relation::MULTILINESTRING && r2->getType() == Relation::MULTILINESTRING && r1->getMembers().size() == r2->getMembers().size()) { for (size_t i = 0; i < r1->getMembers().size(); i++) { ElementId eid1 = r1->getMembers()[i].getElementId(); ElementId eid2 = r2->getMembers()[i].getElementId(); if (eid1.getType() != ElementType::Way || eid2.getType() != ElementType::Way) { return nullValue(); } scores.push_back(_extract(map, map.getWay(eid1), map.getWay(eid2))); } } else { return nullValue(); } } else { return nullValue(); } return _agg->aggregate(scores); }
AnimationEffect::AnimationEffect(const Timing& timing, EventDelegate* eventDelegate) : m_animation(nullptr) , m_timing(timing) , m_eventDelegate(eventDelegate) , m_calculated() , m_needsUpdate(true) , m_lastUpdateTime(nullValue()) { m_timing.assertValid(); }
AnimationPlayer::AnimationPlayer(DocumentTimeline& timeline, TimedItem* content) : m_playbackRate(1) , m_startTime(nullValue()) , m_holdTime(nullValue()) , m_storedTimeLag(0) , m_content(content) , m_timeline(&timeline) , m_paused(false) , m_held(false) , m_isPausedForTesting(false) , m_outdated(false) , m_sequenceNumber(nextSequenceNumber()) { if (m_content) { if (m_content->player()) m_content->player()->cancel(); m_content->attach(this); } }
wchar_t* String::copyValue(wchar_t* _pwstData) { if (_pwstData == nullValue()) { return nullValue(); } try { return os_wcsdup(_pwstData); } catch (std::bad_alloc & /*e*/) { char message[bsiz]; os_sprintf(message, _("Can not allocate data.\n")); throw ast::InternalError(message); } return NULL; }
void AnimationPlayer::updateCurrentTimingState() { if (m_held) { updateTimingState(m_holdTime); return; } if (!limited(currentTimeWithLag())) return; m_held = true; m_holdTime = m_playbackRate < 0 ? 0 : sourceEnd(); m_storedTimeLag = nullValue(); }
AnimationNode::AnimationNode(const Timing& timing, PassOwnPtrWillBeRawPtr<EventDelegate> eventDelegate) : m_parent(nullptr) , m_startTime(0) , m_player(nullptr) , m_timing(timing) , m_eventDelegate(eventDelegate) , m_calculated() , m_needsUpdate(true) , m_lastUpdateTime(nullValue()) { m_timing.assertValid(); }
bool AnimationPlayer::update() { m_outdated = false; if (!m_timeline || !m_content) return false; double inheritedTime = isNull(m_timeline->currentTime()) ? nullValue() : currentTime(); m_content->updateInheritedTime(inheritedTime); ASSERT(!m_outdated); return m_content->isCurrent() || m_content->isInEffect(); }
void Animation::cancel() { PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand); if (playStateInternal() == Idle) return; m_holdTime = currentTimeInternal(); m_held = true; // TODO m_playState = Idle; m_startTime = nullValue(); m_currentTimePending = false; }
void Player::setPausedImpl(bool newValue) { if (pausedInternal() == newValue) return; if (newValue) { // FIXME: resume compositor animation rather than pull back to main-thread cancelAnimationOnCompositor(); m_pauseStartTime = currentTime(); } else { m_timeDrift = pausedTimeDrift(); m_pauseStartTime = nullValue(); } }
double HausdorffDistanceExtractor::distance(const OsmMap &map, const shared_ptr<const Element>& target, const shared_ptr<const Element> &candidate) const { ElementConverter ec(map.shared_from_this()); shared_ptr<Geometry> g1 = ec.convertToGeometry(target); shared_ptr<Geometry> g2 = ec.convertToGeometry(candidate); if (g1->isEmpty() || g2->isEmpty()) { return nullValue(); } return max(VertexHausdorffDistance(*g1, *g2).getDistance(), VertexHausdorffDistance(*g2, *g1).getDistance()); }
void AnimationPlayer::play() { if (!playing()) m_startTime = nullValue(); setCompositorPending(); unpauseInternal(); if (!m_content) return; double currentTime = this->currentTimeInternal(); if (m_playbackRate > 0 && (currentTime < 0 || currentTime >= sourceEnd())) setCurrentTimeInternal(0, TimingUpdateOnDemand); else if (m_playbackRate < 0 && (currentTime <= 0 || currentTime > sourceEnd())) setCurrentTimeInternal(sourceEnd(), TimingUpdateOnDemand); m_finished = false; }
double NameExtractor::extract(const ConstElementPtr& target, const ConstElementPtr& candidate) const { QStringList targetNames = target->getTags().getNames(); targetNames.append(target->getTags().getPseudoNames()); QStringList candidateNames = candidate->getTags().getNames(); candidateNames.append(candidate->getTags().getPseudoNames()); double score = -1; for (int i = 0; i < targetNames.size(); i++) { for (int j = 0; j < candidateNames.size(); j++) { double thisScore = _d->compare(targetNames[i], candidateNames[j]); score = max(thisScore, score); } } if (score == -1) { return nullValue(); } else { // LOG_INFO("score: " << score << " weight: " << weight); // LOG_INFO("target: " << target->toString()); // LOG_INFO("candidate: " << candidate->toString()); // if (candidate->getTags()["REF2"].contains(target->getTags()["REF1"])) // { // LOG_INFO(getName() << " | Match: " << score << " | " << // target->getTags().getNames().join(";") << " | " << // candidate->getTags().getNames().join(";")) // } // else // { // LOG_INFO(getName() << " | Miss: " << score << " | " << // target->getTags().getNames().join(";") << " | " << // candidate->getTags().getNames().join(";")) // } } return score; }
bool Player::update(double* timeToEffectChange, bool* didTriggerStyleRecalc) { if (!m_content) { if (timeToEffectChange) *timeToEffectChange = std::numeric_limits<double>::infinity(); if (didTriggerStyleRecalc) *didTriggerStyleRecalc = false; return false; } double inheritedTime = isNull(m_timeline.currentTime()) ? nullValue() : currentTime(); bool didTriggerStyleRecalcLocal = m_content->updateInheritedTime(inheritedTime); if (timeToEffectChange) *timeToEffectChange = m_content->timeToEffectChange(); if (didTriggerStyleRecalc) *didTriggerStyleRecalc = didTriggerStyleRecalcLocal; return m_content->isCurrent() || m_content->isInEffect(); }
void AnimationPlayer::cancel() { PlayStateUpdateScope updateScope(*this, TimingUpdateOnDemand); if (playStateInternal() == Idle) return; m_holdTime = currentTimeInternal(); m_held = true; // TODO m_playState = Idle; m_startTime = nullValue(); m_currentTimePending = false; // after cancelation, transitions must be downgraded or they'll fail // to be considered when retriggering themselves. This can happen if // the transition is captured through getAnimationPlayers then played. if (m_content && m_content->isAnimation()) toAnimation(m_content.get())->downgradeToNormalAnimation(); }
double takeLocalTime() { const double result = m_localTime; m_localTime = nullValue(); return result; }
// Creates an AnimChannel from a Maya compound attribute if there is meaningful // data. This means we found data that is non-identity. // // returns true if we extracted an AnimChannel and false otherwise (e.g., the // data was identity). static bool _GatherAnimChannel( XFormOpType opType, const MFnTransform& iTrans, MString parentName, MString xName, MString yName, MString zName, std::vector<AnimChannel>* oAnimChanList, bool isWritingAnimation, bool setOpName) { AnimChannel chan; chan.opType = opType; chan.isInverse = false; if (setOpName) { chan.opName = parentName.asChar(); } // We default to single precision (later we set the main translate op and // shear to double) chan.precision = UsdGeomXformOp::PrecisionFloat; unsigned int validComponents = 0; // this is to handle the case where there is a connection to the parent // plug but not to the child plugs, if the connection is there and you are // not forcing static, then all of the children are considered animated int parentSample = PxrUsdMayaUtil::getSampledType(iTrans.findPlug(parentName),false); // Determine what plug are needed based on default value & being // connected/animated MStringArray channels; channels.append(parentName+xName); channels.append(parentName+yName); channels.append(parentName+zName); GfVec3d nullValue(opType == SCALE ? 1.0 : 0.0); for (unsigned int i = 0; i<3; i++) { // Find the plug and retrieve the data as the channel default value. It // won't be updated if the channel is NOT ANIMATED chan.plug[i] = iTrans.findPlug(channels[i]); double plugValue = chan.plug[i].asDouble(); chan.defValue[i] = opType == ROTATE ? GfRadiansToDegrees(plugValue) : plugValue; chan.sampleType[i] = NO_XFORM; // If we allow animation and either the parentsample or local sample is // not 0 then we havea ANIMATED sample else we have a scale and the // value is NOT 1 or if the value is NOT 0 then we have a static xform if ((parentSample != 0 || PxrUsdMayaUtil::getSampledType(chan.plug[i], true) != 0) && isWritingAnimation) { chan.sampleType[i] = ANIMATED; validComponents++; } else if (!GfIsClose(chan.defValue[i], nullValue[i], 1e-7)) { chan.sampleType[i] = STATIC; validComponents++; } } // If there are valid component, then we will add the animation channel. // Rotates with 1 component will be optimized to single axis rotation if (validComponents>0) { if (opType == SCALE) { chan.usdOpType = UsdGeomXformOp::TypeScale; } else if (opType == TRANSLATE) { chan.usdOpType = UsdGeomXformOp::TypeTranslate; // The main translate is set to double precision if (parentName == "translate") { chan.precision = UsdGeomXformOp::PrecisionDouble; } } else if (opType == ROTATE) { chan.usdOpType = UsdGeomXformOp::TypeRotateXYZ; if (validComponents == 1) { if (chan.sampleType[0] != NO_XFORM) chan.usdOpType = UsdGeomXformOp::TypeRotateX; if (chan.sampleType[1] != NO_XFORM) chan.usdOpType = UsdGeomXformOp::TypeRotateY; if (chan.sampleType[2] != NO_XFORM) chan.usdOpType = UsdGeomXformOp::TypeRotateZ; } else { // Rotation Order ONLY applies to the "rotate" attribute if (parentName == "rotate") { switch (iTrans.rotationOrder()) { case MTransformationMatrix::kYZX: chan.usdOpType = UsdGeomXformOp::TypeRotateYZX; break; case MTransformationMatrix::kZXY: chan.usdOpType = UsdGeomXformOp::TypeRotateZXY; break; case MTransformationMatrix::kXZY: chan.usdOpType = UsdGeomXformOp::TypeRotateXZY; break; case MTransformationMatrix::kYXZ: chan.usdOpType = UsdGeomXformOp::TypeRotateYXZ; break; case MTransformationMatrix::kZYX: chan.usdOpType = UsdGeomXformOp::TypeRotateZYX; break; default: break; } } } } else if (opType == SHEAR) { chan.usdOpType = UsdGeomXformOp::TypeTransform; chan.precision = UsdGeomXformOp::PrecisionDouble; } else { return false; } oAnimChanList->push_back(chan); return true; } return false; }
double takeTimeToNextIteration() { const double result = m_timeToNextIteration; m_timeToNextIteration = nullValue(); return result; }