// TODO: better name for days?
 public static IObservable<float> MovingAverage(this IObservable<float> prices, int days)
 {
     return prices
         .Buffer(days, 1)
         .Where(x => x.Count == days)
         .Select(x => x.Average());
 }
Esempio n. 2
0
 public static IBuffer Buffer(this IContextObjectFactory factory, BufferTarget creationTarget, int sizeInBytes, BufferUsageHint usageHint, Array initialData)
 {
     var handle = GCHandle.Alloc(initialData, GCHandleType.Pinned);
      var result = factory.Buffer(creationTarget, sizeInBytes, usageHint, handle.AddrOfPinnedObject());
      handle.Free();
      return result;
 }
        /// <summary>
        /// Assumes that polygon is closed, ie first and last points are the same
        /// </summary>
        /// <param name="polygon"></param>
        /// <param name="up"></param>
        /// <returns></returns>
        public static bool OrientationClosed(this IEnumerable<Vector3> polygon, Vector3 up)
        {
            var sum = Vector3.Zero;
            foreach (var b in polygon.Buffer(2, 1))
            {
                if (b.Count == 2)
                    sum = sum + Vector3.Cross(b[0], b[1])/b[0].Length()/b[1].Length();
            }

            return Vector3.Dot(up, sum) > 0;

        } 
Esempio n. 4
0
 /// <summary>
 /// Indicates if this geometry is within the distance of (buffer intersects) another geometry.
 /// </summary>
 /// <param name="shape">The current geometry.</param>
 /// <param name="comparisonShape">The geometry to compare with.</param>
 /// <param name="distance">The distance in the map unit of the current shape.</param>
 /// <returns>True or false.</returns>
 public static bool Within(this IGeometry shape, IGeometry comparisonShape, double distance)
 {
     return shape.Buffer(distance).Intersects(comparisonShape);
 }