public async Task ApplyAsync(IDocumentOperations operations, IReadOnlyList <StreamAction> streams,
                                     CancellationToken cancellation)
        {
            // Doing the filtering here to prevent unnecessary network round trips by allowing
            // an aggregate projection to "work" on a stream with no matching events
            var filteredStreams = streams
                                  .Where(x => Projection.AppliesTo(x.Events.Select(x => x.EventType)))
                                  .ToArray();

            var slices = Slicer.Slice(filteredStreams, Tenancy);

            var martenSession = (DocumentSessionBase)operations;

            foreach (var slice in slices)
            {
                IStorageOperation?operation;

                // TODO -- this can only apply to the last event
                if (Projection.MatchesAnyDeleteType(slice))
                {
                    operation = Storage.DeleteForId(slice.Id, slice.Tenant);
                }
                else
                {
                    operation = await DetermineOperation(martenSession, slice, cancellation);
                }

                if (operation != null)
                {
                    operations.QueueOperation(operation);
                }
            }
        }
Example #2
0
    public static Polyline[][] Create(Mesh mesh, double height, Interval modelRegion)
    {
        var slicer = new Slicer(mesh, height, modelRegion);

        slicer.Slice();
        return(slicer.Contours);
    }
    /**
     * This function will slice the provided object by the plane defined in this
     * GameObject. We use the GameObject this script is attached to define the position
     * and direction of our cutting Plane. Results are then returned to the user.
     */
    public SlicedHull SliceObject(GameObject obj)
    {
        EzySlice.Plane cuttingPlane = ComputePlaneAgainst(obj);

        // finally, slice the object and return the results. SlicedHull will have all the mesh
        // details which the application can use to do whatever it wants to do
        return(Slicer.Slice(obj, cuttingPlane));
    }
Example #4
0
        public Property Slice_returns_first_collections_with_maxCount_elements()
        {
            return(Prop.ForAll <List <int> >(array =>
            {
                var slicer = new Slicer <int>(array, _MaxCount);
                var slices = slicer.Slice();

                return slices.Reverse().Skip(1).All(sl => sl.Length == _MaxCount);
            }));
        }
Example #5
0
        public Property Slice_returns_original_elements()
        {
            return(Prop.ForAll <List <int> >(array =>
            {
                var slicer = new Slicer <int>(array, _MaxCount);
                var slices = slicer.Slice();

                return array.SequenceEqual(slices.SelectMany(sl => sl));
            }));
        }
        public async ValueTask <EventRangeGroup> GroupEvents(DocumentStore store, EventRange range, CancellationToken cancellationToken)
        {
            IReadOnlyList <TenantSliceGroup <TDoc, TId> > groups;

            using (var session = store.QuerySession())
            {
                groups = await Slicer.Slice(session, range.Events, store.Tenancy);
            }

            return(new TenantSliceRange <TDoc, TId>(store, this, range, groups, cancellationToken));
        }
        public void Slice_InsertFourFaces_2Returned()
        {
            //Mesh has 10 vertices, of which 8 are unique. It has 4 faces.
            //We're slicing halfway through the third face, so we should end up with 2 faces and 5 vertices.
            string location   = testModelLocation + @"\fourTriangles.ply";
            CVMesh mesh       = PLYHandler.ReadMesh(location);
            float  lowerLimit = 58.5f;
            float  upperLimit = 1000f;

            Slicer.xMin = float.MinValue;
            Slicer.xMax = float.MaxValue;
            CVMesh sliced = uut.Slice(mesh, lowerLimit, upperLimit, false);

            Assert.AreEqual(5, sliced.Vertices.Count);
            Assert.AreEqual(0, sliced.Faces[0].index1);
            Assert.AreEqual(1, sliced.Faces[0].index2);
            Assert.AreEqual(2, sliced.Faces[0].index3);
            Assert.AreEqual(3, sliced.Faces[1].index1);
            Assert.AreEqual(2, sliced.Faces[1].index2);
            Assert.AreEqual(4, sliced.Faces[1].index3);
        }
Example #8
0
    private void OnTriggerExit(Collider other)
    {
        _triggerExitTipPosition = _tip.transform.position;

        //Create a triangle between the tip and base so that we can get the normal
        Vector3 side1 = _triggerExitTipPosition - _triggerEnterTipPosition;
        Vector3 side2 = _triggerExitTipPosition - _triggerEnterBasePosition;

        //Get the point perpendicular to the triangle above which is the normal
        //https://docs.unity3d.com/Manual/ComputingNormalPerpendicularVector.html
        Vector3 normal = Vector3.Cross(side1, side2).normalized;

        //Transform the normal so that it is aligned with the object we are slicing's transform.
        Vector3 transformedNormal = ((Vector3)(other.gameObject.transform.localToWorldMatrix.transpose * normal)).normalized;

        //Get the enter position relative to the object we're cutting's local transform
        Vector3 transformedStartingPoint = other.gameObject.transform.InverseTransformPoint(_triggerEnterTipPosition);

        Plane plane = new Plane();

        plane.SetNormalAndPosition(
            transformedNormal,
            transformedStartingPoint);

        var direction = Vector3.Dot(Vector3.up, transformedNormal);

        //Flip the plane so that we always know which side the positive mesh is on
        if (direction < 0)
        {
            plane = plane.flipped;
        }

        if (!_animation.isPlaying || other.gameObject.tag != "Tree")
        {
            return;
        }

        GameObject[] slices = Slicer.Slice(plane, other.gameObject);
        Destroy(other.gameObject);

        Rigidbody rigidbody = slices[1].GetComponent <Rigidbody>();
        Vector3   newNormal = transformedNormal + Vector3.up * _forceAppliedToCut;

        rigidbody.AddForce(newNormal, ForceMode.Impulse);
    }
        public override void OnPreprocessAsset(IAkyuiLoader loader, ref byte[] bytes, ref IAsset asset, ref Dictionary <string, object> userData)
        {
            if (!(asset is SpriteAsset spriteAsset))
            {
                return;
            }

            var extension = Path.GetExtension(asset.FileName);

            if (spriteAsset.Border != null)
            {
                return;
            }
            if (extension != ".png" && extension != ".jpg" && extension != ".jpeg")
            {
                return;
            }

            var texture = new Texture2D(2, 2);

            texture.LoadImage(bytes);

            var sliced = Slicer.Slice(texture, options);

            if (extension == ".png")
            {
                bytes = sliced.Texture.EncodeToPNG();
            }
            if (extension == ".jpg" || extension == ".jpeg")
            {
                bytes = sliced.Texture.EncodeToJPG();
            }

            spriteAsset.Border = new Border(
                sliced.Border.Top,
                sliced.Border.Right,
                sliced.Border.Bottom,
                sliced.Border.Left
                );
        }
Example #10
0
    /**
     * This function will slice the provided object by the plane defined in this
     * GameObject. We use the GameObject this script is attached to define the position
     * and direction of our cutting Plane. Results are then returned to the user.
     */
    public SlicedHull SliceObject(GameObject obj)
    {
        // ensure to generate an EzySlice version of the Plane instead of the
        // default Unity.
        EzySlice.Plane cuttingPlane = new EzySlice.Plane();

        // since this GameObject represents our Plane's coordinates, we first need
        // to bring the Plane into the coordinate frame of the object we want to slice
        // this is because the Mesh data is always in local coordinates
        // we need the position of the plane and direction
        Vector3 refUp = obj.transform.InverseTransformDirection(transform.up);
        Vector3 refPt = obj.transform.InverseTransformPoint(transform.position);

        // once we have the coordinates we need, we can initialize our plane with the new
        // coordinates (now in obj's coordinate frame) and safely perform the slice
        // operation
        cuttingPlane.Compute(refPt, refUp);

        // finally, slice the object and return the results. SlicedHull will have all the mesh
        // details which the application can use to do whatever it wants to do
        return(Slicer.Slice(obj, cuttingPlane));
    }
Example #11
0
        public async Task ApplyAsync(IDocumentOperations operations, IReadOnlyList <StreamAction> streams,
                                     CancellationToken cancellation)
        {
            var slices = Slicer.Slice(streams, Tenancy);

            var martenSession = (DocumentSessionBase)operations;

            foreach (var slice in slices)
            {
                IStorageOperation operation = null;
                if (Projection.MatchesAnyDeleteType(slice))
                {
                    operation = Storage.DeleteForId(slice.Id, slice.Tenant);
                }
                else
                {
                    operation = await DetermineOperation(martenSession, slice, cancellation);
                }

                operations.QueueOperation(operation);
            }
        }
Example #12
0
        public static IEnumerable <IJavascriptObject[]> Slice(this IWebView webView, IEnumerable <IJavascriptObject> elements)
        {
            var slicer = new Slicer <IJavascriptObject>(elements, webView.GetMaxAcceptableArguments());

            return(slicer.Slice());
        }
Example #13
0
        public static IEnumerable <IJavascriptObject[]> Slice(this IWebView webView, IList <IJavascriptObject> elements)
        {
            var slicer = new Slicer <IJavascriptObject>(elements, webView.MaxFunctionArgumentsNumber);

            return(slicer.Slice());
        }
Example #14
0
        public void SliceFirstElement()
        {
            UnityEventListenerMock slicedMock = new UnityEventListenerMock();

            subject.Sliced.AddListener(slicedMock.Listen);
            UnityEventListenerMock remainedMock = new UnityEventListenerMock();

            subject.Remained.AddListener(remainedMock.Listen);

            List <CollisionNotifier.EventData> collisionList = new List <CollisionNotifier.EventData>();
            GameObject oneContainer;

            CollisionNotifier.EventData oneData = CollisionNotifierHelper.GetEventData(out oneContainer);
            oneContainer.name = "one";
            collisionList.Add(oneData);

            GameObject twoContainer;

            CollisionNotifier.EventData twoData = CollisionNotifierHelper.GetEventData(out twoContainer);
            twoContainer.name = "two";
            collisionList.Add(twoData);

            GameObject threeContainer;

            CollisionNotifier.EventData threeData = CollisionNotifierHelper.GetEventData(out threeContainer);
            threeContainer.name = "three";
            collisionList.Add(threeData);

            GameObject fourContainer;

            CollisionNotifier.EventData fourData = CollisionNotifierHelper.GetEventData(out fourContainer);
            fourContainer.name = "four";
            collisionList.Add(fourData);

            GameObject fiveContainer;

            CollisionNotifier.EventData fiveData = CollisionNotifierHelper.GetEventData(out fiveContainer);
            fiveContainer.name = "five";
            collisionList.Add(fiveData);

            GameObject sixContainer;

            CollisionNotifier.EventData sixData = CollisionNotifierHelper.GetEventData(out sixContainer);
            sixContainer.name = "six";
            collisionList.Add(sixData);

            ActiveCollisionsContainer.EventData eventData = new ActiveCollisionsContainer.EventData().Set(collisionList);

            subject.StartIndex = 0;
            subject.Length     = 1;

            Assert.AreEqual("one,two,three,four,five,six", ActiveCollisionsHelper.GetNamesOfActiveCollisions(eventData));

            Assert.IsFalse(slicedMock.Received);
            Assert.IsFalse(remainedMock.Received);

            ActiveCollisionsContainer.EventData remainedList;
            ActiveCollisionsContainer.EventData slicedList = subject.Slice(eventData, out remainedList);

            Assert.IsTrue(slicedMock.Received);
            Assert.IsTrue(remainedMock.Received);

            Assert.AreEqual("one", ActiveCollisionsHelper.GetNamesOfActiveCollisions(slicedList));
            Assert.AreEqual("two,three,four,five,six", ActiveCollisionsHelper.GetNamesOfActiveCollisions(remainedList));

            Object.DestroyImmediate(oneContainer);
            Object.DestroyImmediate(twoContainer);
            Object.DestroyImmediate(threeContainer);
            Object.DestroyImmediate(fourContainer);
            Object.DestroyImmediate(fiveContainer);
            Object.DestroyImmediate(sixContainer);
        }
Example #15
0
        public EventRangeGroup GroupEvents(DocumentStore store, EventRange range, CancellationToken cancellationToken)
        {
            var groups = Slicer.Slice(range.Events, store.Tenancy);

            return(new TenantSliceRange <TDoc, TId>(store, this, range, groups, cancellationToken));
        }
Example #16
0
 public void Slice_Succeeds()
 {
     _slicer.Slice(new Mesh());
 }