Material Motion Exploring solutions that will empower creators with the tools needed to describe and implement rich, interactive motion on any platform. Edit this page · History
$._map distanceFrom abs
Status Interface level Implementation level Library
Stable as of February 20, 2017 L2: Interaction creator L3: Stream creator material-motion
platformsrctests
iOS (Swift) View View
distanceFrom
upstream (T: <number | Point>)
location (T: <number | Point>)
(number) downstream

distanceFrom specification

This is the engineering specification for the MotionObservable operator: distanceFrom.

Overview

distanceFrom emits the absolute distance from the upstream value and the provided location.

Example usage

stream.distanceFrom(location: 50)

upstream  location  |  downstream
20        50        |  30
40        50        |  10
80        50        |  30

MVP

Expose a 1-dimensional distanceFrom operator API

Use _map to implement the operator. Accept a location number. Emit a number which is the result of abs(upstreamValue - location).

class MotionObservable<number> {
  public func distance(from location: number) -> MotionObservable<number>

Expose a 2-dimensional distanceFrom operator API

Use _map to implement the operator. Accept a location point. Emit a number which is the result of sqrt((upstreamValue.x - location.x)^2 + (upstreamValue.y - location.y)^2).

class MotionObservable<Point2D> {
  public func distance(from location: Point2D) -> MotionObservable<number>