예제 #1
0
 /// <summary>
 /// Take between
 /// </summary>
 /// <param name="start">Start</param>
 /// <param name="end">End</param>
 public IEnumerable <Instruction> Take(IndexOffset start, IndexOffset end)
 {
     for (int x = (int)start.Index, m = (int)end.Index; x <= m; x++)
     {
         yield return(base[x]);
     }
 }
예제 #2
0
 /// <summary>
 /// Take enter
 /// </summary>
 /// <param name="start">Start</param>
 public IEnumerable <Instruction> Take(IndexOffset start)
 {
     for (int x = (int)start.Index, m = Count; x < m; x++)
     {
         yield return(base[x]);
     }
 }
        /// <summary>
        /// Calculate number of words to fit complete instruction bytecode.
        /// </summary>
        /// <returns>Number of words in instruction bytecode.</returns>
        public override uint GetWordCount()
        {
            uint wordCount = 0;

            wordCount += IndexOffset.GetWordCount();
            wordCount += PackedIndices.GetWordCount();
            return(wordCount);
        }
예제 #4
0
 public AnalysisConfiguration(FileInfo file = null, IndexOffset zeroBaseOffset = IndexOffset.Zero, bool?shouldIgnoreHeaderRow = null, bool?shouldIgnoreTrailerRow = null, bool?shouldIncludeRowIdColumn = null, bool?shouldIncludeFlagColumn = null, List <IndexDefinition> indexDefinitions = null)
 {
     this.File                     = file;
     this.IndexOffset              = zeroBaseOffset;
     this.ShouldIgnoreHeaderRow    = shouldIgnoreHeaderRow;
     this.ShouldIgnoreTrailerRow   = shouldIgnoreTrailerRow;
     this.ShouldIncludeRowIdColumn = shouldIncludeRowIdColumn;
     this.ShouldIncludeFlagColumn  = shouldIncludeFlagColumn;
     this.IndexDefinitions         = indexDefinitions;
 }
예제 #5
0
        /// <summary>
        /// Get method of
        /// </summary>
        /// <param name="location">Location</param>
        public Method GetMethodOf(IndexOffset location)
        {
            foreach (Method m in this)
            {
                if (location.IndexBetween(m.Start.Index, m.End.Index))
                {
                    return(m);
                }
            }

            return(null);
        }
예제 #6
0
        /// <summary>
        /// Get module of
        /// </summary>
        /// <param name="location">Location</param>
        public Module GetModuleOf(IndexOffset location)
        {
            foreach (Module m in this)
            {
                if (location.IndexBetween(m.Start.Index, m.End.Index))
                {
                    return(m);
                }
            }

            return(null);
        }
예제 #7
0
        /// <summary>
        /// Select grid row
        /// </summary>
        /// <param name="index">Index</param>
        public void SelectInstruction(IndexOffset index)
        {
            if (index == null)
            {
                return;
            }

            if (InvokeRequired)
            {
                Invoke(new Action <IndexOffset>(SelectInstruction), index);
                return;
            }

            GridOpCode.CurrentCell        = GridOpCode.Rows[(int)index.Index].Cells.Cast <DataGridViewCell>().LastOrDefault();
            GridOpCode.FirstDisplayedCell = GridOpCode.CurrentCell;
            tabControl1.SelectedIndex     = 0;
        }
예제 #8
0
        public UVAnimation Construct(Entity entity, params string[] meshNames)
        {
            var model = this.Models.Get(entity);

            var indexOffset = new IndexOffset[meshNames.Length];

            for (var i = 0; i < meshNames.Length; i++)
            {
                var name  = meshNames[i];
                var index = GetMeshIndex(model.Model, name);

                indexOffset[i] = new IndexOffset(name, index);
            }

            var animation = new UVAnimation(entity, indexOffset);

            this.Container.Add(animation);

            return(animation);
        }
예제 #9
0
 /// <summary>
 /// Add index/offset
 /// </summary>
 /// <param name="i">Index</param>
 public void Add(IndexOffset i)
 {
     _OffsetToIndex.Add(i.Offset, i.Index);
     _IndexToOffset.Add(i.Index, i.Offset);
 }
예제 #10
0
 public int getNewIndex(int index)
 {
     return(IndexOffset.getNewIndex(offsets, index, originalCount));
 }
예제 #11
0
 public void Add(IndexOffset offset)
 {
     offsets.Add(offset);
 }
 /// <summary>
 /// Write instruction operands into bytecode stream.
 /// </summary>
 /// <param name="writer">Bytecode writer.</param>
 public override void WriteOperands(WordWriter writer)
 {
     IndexOffset.Write(writer);
     PackedIndices.Write(writer);
 }
예제 #13
0
    public void cutShape(Shape stencil, bool splitFurther = true)
    {
        if (stencil.Direction != this.Direction)
        {
            throw new UnityException("Trying to cut shape with stencil of different thread type! shape: " + Direction + ", stencil: " + stencil.Direction);
        }

        //Show paths (for debugging)
        //showPath(points);
        //showPath(stencilPoints);

        //Gather overlap info
        List <IntersectionData> intersectionData = new List <IntersectionData>();

        for (int i = 0; i < GlobalPoints.Count; i++)
        {
            int i2 = (i + 1) % GlobalPoints.Count;

            //Line Checking
            LineSegment targetLine = new LineSegment(GlobalPoints, i);
            //Check to see if the bounds overlap
            if (stencil.bounds.Intersects(targetLine.Bounds))
            {
                bool startInStencil = stencil.OverlapPoint(targetLine.startPos);
                bool endInStencil   = stencil.OverlapPoint(targetLine.endPos);
                //Check which stencil edges intersect the line segment
                bool intersectsSegment = false;
                for (int j = 0; j < stencil.GlobalPoints.Count; j++)
                {
                    LineSegment stencilLine  = new LineSegment(stencil.GlobalPoints, j);
                    Vector2     intersection = Vector2.zero;
                    bool        intersects   = targetLine.Intersects(stencilLine, ref intersection);
                    //If it intersects,
                    if (intersects)
                    {
                        //Record a data point
                        intersectsSegment = true;
                        float            distanceToPoint = (intersection - targetLine.startPos).magnitude;
                        IntersectionData interdata       = new IntersectionData(intersection, i, j, intersects, startInStencil, endInStencil, distanceToPoint);
                        intersectionData.Add(interdata);
                    }
                }
                //If no line segment intersections were found,
                if (!intersectsSegment)
                {
                    //but one or more end points are in the stencil,
                    if (startInStencil || endInStencil)
                    {
                        //Make an intersection data point anyway, with slightly different arguments
                        IntersectionData interdata = new IntersectionData(Vector2.zero, i, -1, IntersectionData.IntersectionType.INSIDE);
                        intersectionData.Add(interdata);
                    }
                }
                //else,
                else
                {
                    //do nothing because the bounds lied about the line segment and stencil colliding
                    //don't worry, it's a known thing that can happen:
                    //bounds checking is quick but liable to give false positives
                }
            }
        }

        //
        // Refine intersection data entries
        //

        //Sort the data entries
        intersectionData.Sort(new IntersectionData.IntersectionDataComparer());

        //Set the intersection type of the data
        int side = 0;//0 =not set, 1 =inside, -1 =outside

        foreach (IntersectionData interdata in intersectionData)
        {
            if (side == 0)
            {
                side = (interdata.startsInStencil) ? 1 : -1;
            }
            if (interdata.segmentIntersection)
            {
                side          *= -1;
                interdata.type = (side > 0) ? IntersectionData.IntersectionType.ENTER : IntersectionData.IntersectionType.EXIT;
            }
            else
            {
                interdata.type = (side > 0) ? IntersectionData.IntersectionType.INSIDE : IntersectionData.IntersectionType.OUTSIDE;
            }
        }
        IntersectionData.printDataList(intersectionData, GlobalPoints);

        //
        //Start cutting
        //

        //Replace line segments inside the stencil
        int dataCount = intersectionData.Count;
        //Search for start of vein of changes
        List <Vein> veins = new List <Vein>();

        //only need to go through the loop once,
        //because the veins will find their own end points:
        //here we just need to find the start of each vein
        for (int iData = 0; iData < dataCount; iData++)
        {
            IntersectionData interdata = intersectionData[iData];
            //if this segment enters the stencil at this data point,
            if (interdata.type == IntersectionData.IntersectionType.ENTER)
            {
                //then it's a vein start
                Vein vein = new Vein(iData, interdata, intersectionData);
                veins.Add(vein);
            }
        }
        //Process found veins
        if (veins.Count == 1)
        {
            Vector2[] newPath = veins[0].getStencilPath(stencil.GlobalPoints);
            //Replace vein with stencil path
            int removeCount = veins[0].getRemoveCount(GlobalPoints.Count);
            replacePoints(newPath, veins[0].VeinStart + 1, removeCount);
        }
        else
        {
            //Process all the veins
            IndexOffset.IndexOffsetContainer offsets = new IndexOffset.IndexOffsetContainer(GlobalPoints.Count);
            for (int i = 0; i < veins.Count; i++)
            {
                Vein vein = veins[i];
                //Update vein with new offsets
                vein.updateIndexes(offsets);
                //Check next vein
                bool slices = false;
                if (i < veins.Count - 1)
                {
                    Vein vein2 = veins[i + 1];
                    vein.updateIndexes(offsets);
                    slices = vein.formsSlice(vein2, stencil.GlobalPoints.Count);
                    Debug.Log("slices: " + slices);
                    if (slices)
                    {
                        vein.slice(vein2);
                        if (splitFurther)
                        {
                            if (this.pc2d)
                            {
                                //make a new collider to make the new piece
                                PolygonCollider2D pc2dNew = GameObject.Instantiate(pc2d.gameObject)
                                                            .GetComponent <PolygonCollider2D>();
                                Shape newShape = new Shape(pc2dNew);
                                newShape.rotatePoints(vein2.VeinStart);
                                newShape.finalize();
                                childrenShapes.Add(newShape);
                                pc2dNew.transform.parent   = pc2d.transform.parent;
                                pc2dNew.transform.position = pc2d.transform.position;
                                newShape.cutShape(stencil, false);
                            }
                        }
                        //skip the next vein
                        i++;
                    }
                }
                if (true || !slices)
                {
                    //Replace vein with stencil path
                    Vector2[] newPath     = vein.getStencilPath(stencil.GlobalPoints);
                    int       removeCount = vein.getRemoveCount(GlobalPoints.Count);
                    replacePoints(newPath, vein.VeinStart + 1, removeCount);
                    //Add offset to the collection
                    IndexOffset offset = new IndexOffset(vein.VeinStart, newPath.Length - removeCount);
                    offsets.Add(offset);
                }
            }
        }

        //
        // Finish up
        //
        finalize();
    }