示例#1
0
        /// <summary>
        /// Convert to logic.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="culture"></param>
        /// <param name="value"></param>
        /// <param name="destinationType"></param>
        /// <returns></returns>
        public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
        {
            EdgePointCollection edgePointCollection = value as EdgePointCollection;

            if (edgePointCollection != null)
            {
                System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
                stringBuilder.Append("[");

                for (int i = 0; i < edgePointCollection.Count; i++)
                {
                    EdgePoint edgePoint = edgePointCollection[i];
                    stringBuilder.Append(EdgePointConverter.ConvertToString(culture, edgePoint));

                    if (i < edgePointCollection.Count - 1)
                    {
                        stringBuilder.Append("; ");
                    }
                }

                stringBuilder.Append("]");
                return(stringBuilder.ToString());
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
示例#2
0
    void VoidStormPuzzle(State stoneState)
    {
        List <int> edgePointsToShuffle = new List <int>();
        int        edgePointSelected;

        switch (stoneState)
        {
        case State.NONE:
            edgePointSelected = Random.Range(0, edgePoints.Length);
            edgePoints[edgePointSelected].GetComponent <EdgePoint>().SetState(State.Blue);
            for (int i = 0; i < edgePoints.Length; i++)
            {
                edgePoints[i].GetComponent <Collider>().enabled = true;
                if (i != edgePointSelected)
                {
                    edgePoints[i].GetComponent <EdgePoint>().SetState(State.Red);
                }
            }
            break;

        case State.Red:
            foreach (GameObject EdgePoint in edgePoints)
            {
                EdgePoint.GetComponent <EdgePoint>().SetState(State.NONE);
                EdgePoint.GetComponent <Collider>().enabled = false;
            }
            break;

        case State.Green:
            break;

        case State.Blue:
            for (int i = 0; i < edgePoints.Length; i++)
            {
                if (edgePoints[i].GetComponent <EdgePoint>().GetState() == State.Red)
                {
                    edgePointsToShuffle.Add(i);
                }
            }

            if (edgePointsToShuffle.Count > 1)
            {
                edgePointSelected = Random.Range(0, edgePointsToShuffle.Count);
                edgePoints[edgePointsToShuffle[edgePointSelected]].GetComponent <EdgePoint>().SetState(State.Blue);
            }

            else
            {
                foreach (GameObject EdgePoint in edgePoints)
                {
                    EdgePoint.GetComponent <EdgePoint>().SetState(State.NONE);
                    EdgePoint.GetComponent <Collider>().enabled = false;
                }

                playerStat.GainExp(75f);
                voidStormAttack = true;
            }
            break;
        }
    }
 public Edge(EdgePoint a, EdgePoint b, float r, cpVect n)
 {
     this.a = a;
     this.b = b;
     this.r = r;
     this.n = n;
 }
示例#4
0
    void MakeMeshData(float t)
    {
        // assign the current position
        Vector3 position = player.transform.position;

        // 根据距离改变取样数和插值数
        float dist = Vector3.Distance(position, m_camera.gameObject.transform.position);

        for (int i = blurStage; i > 0; i--)
        {
            amountOfPoints = initPointNum;
            sampleRate     = initSampleRate;
            if (dist > i * blurDist)
            {
                amountOfPoints = initPointNum + 1 - (i) * initPointNum / blurStage;
                sampleRate     = i * initSampleRate;
                break;
            }
        }


        if (sections.Count == 0 || (position - sections[0].point).sqrMagnitude > 0)
        {
            EdgePoint p = new EdgePoint(position, t);
            p.upDir = position + width * player.transform.TransformDirection(Vector3.up);

            sections.Insert(0, p);
        }
    }
    List <EdgePoint> FindEquiDistancedPoints(int p_layerIndex, int p_lastSelectedPoint = -1)
    {
        List <EdgePoint>  selectedHits = new List <EdgePoint>();
        List <RaycastHit> allHits      = allEdgeLoops[p_layerIndex];

        //RaycastHit lastSelectedHit = new RaycastHit();
        EdgePoint lastSelectedHit = new EdgePoint();

        //RaycastHit prevHit = new RaycastHit();
        EdgePoint prevHit = new EdgePoint();


        float angleBetweenPoints;
        int   currentIndex         = 0;
        int   lastSelectedHitIndex = 0;

        //For all rows other than the bottom one, we need to select a start point in proximity of any point from previous row
        if (p_lastSelectedPoint == -1)
        {
            lastSelectedHit.index = 0;
            lastSelectedHit.hit   = allHits[0];
            selectedHits.Add(lastSelectedHit);
        }
        else
        {
            prevHit       = new EdgePoint();
            prevHit.index = 0;
            prevHit.hit   = allHits[0];
            foreach (RaycastHit hit in allHits)
            {
                if (Vector3.Distance(hit.point, allEdgeLoops[p_layerIndex - 1][p_lastSelectedPoint].point) >= verticalPlacementDistance)
                {
                    selectedHits.Add(prevHit);
                    lastSelectedHit = prevHit;
                    break;
                }
                prevHit       = new EdgePoint();
                prevHit.index = currentIndex;
                prevHit.hit   = hit;
                currentIndex++;
            }
        }

        currentIndex = 0;
        foreach (RaycastHit hit in allHits)
        {
            if (Vector3.Distance(hit.point, lastSelectedHit.hit.point) >= horizontalPlacementDistance)
            {
                selectedHits.Add(prevHit);
                lastSelectedHit = prevHit;
            }
            prevHit       = new EdgePoint();
            prevHit.index = currentIndex;
            prevHit.hit   = hit;
            currentIndex++;
        }

        return(selectedHits);
    }
示例#6
0
 /// <summary>
 /// Converts an edge point to its string representation.
 /// </summary>
 /// <param name="culture"></param>
 /// <param name="point"></param>
 /// <returns></returns>
 internal static string ConvertToString(CultureInfo culture, EdgePoint point)
 {
     object[] objArr = new object[3];
     objArr[0] = point.Point.X.ToString(culture);
     objArr[1] = point.Point.Y.ToString(culture);
     objArr[2] = point.PointType.ToString();
     return(System.String.Format(culture, "({0} : {1} : {2})", objArr));
 }
示例#7
0
        /// <summary>
        /// Convert to logic.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="culture"></param>
        /// <param name="value"></param>
        /// <param name="destinationType"></param>
        /// <returns></returns>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            EdgePoint edgePoint = value as EdgePoint;

            if ((edgePoint != null) && destinationType == typeof(string))
            {
                return(EdgePointConverter.ConvertToString(culture, edgePoint));
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
示例#8
0
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="edgePoint">Edge point.</param>
        /// <param name="edgePointType">EdgePointVMType.</param>
        public EdgePointViewModel(ViewModelStore viewModelStore, EdgePoint edgePoint, EdgePointVMType edgePointType)
            : base(viewModelStore)
        {
            this.EdgePoint          = edgePoint;
            this.EdgePointType      = edgePointType;
            this.EdgePointSide      = EdgePointVMSide.None;
            this.EdgePointOperation = EdgePointVMOperation.Move;

            this.TranslateX = 0;
            this.TranslateY = 0;

            UpdateTranslateCoordinates();
        }
            /// <summary>
            /// Calculates the similarity between this point and either 1 or 2 previous points representing a line segment
            /// This function decides how appropriately this point would fit into a path joining 'point'
            /// Comparison factors include: thickness of this valley compared to the last, valley colour, relative directions of the valleys
            /// </summary>
            /// <param name="point">Point to compare with</param>
            /// <param name="previousPoint">Point prior to 'point', if applicable</param>
            /// <returns>A floating-point similarity value between 0 and 1 where 1 is virtually identical</returns>
            public SimilarityPack CalculateSimilarity(EdgePoint point, EdgePoint previousPoint = null)
            {
                SimilarityPack similarity = new SimilarityPack()
                {
                    Colour    = ImageMath.PixelDifference(ColourUnderPoint, point.ColourUnderPoint),
                    Direction = 1.0f,
                    Length    = 1.0f,
                    Width     = 1.0f,
                    Distance  = 1.0f,
                };

                if (previousPoint != null)
                {
                    Vector2 previousVector = new Vector2(point.X - previousPoint.X, point.Y - previousPoint.Y);
                    Vector2 currentVector  = new Vector2(X - point.X, Y - point.Y);

                    if (previousVector.LengthSquared() > 0 && currentVector.LengthSquared() > 0)
                    {
                        // Direction similarity: Use the dot product of the normalised segment vectors
                        similarity.Direction = Vector2.Dot(previousVector / previousVector.Length(), currentVector / currentVector.Length());

                        // Length similarity: Use the smaller length divided by the bigger length.....?
                        similarity.Length = previousVector.Length() / currentVector.Length();

                        if (similarity.Length > 1.0f)
                        {
                            similarity.Length = 1.0f / similarity.Length; // swap the division operands lazily
                        }
                    }
                }

                if (point.LastPoint != null && LastPoint != null)
                {
                    // Width similarity: Use the smaller width divided by the bigger width?
                    similarity.Width = Vector2.Distance(new Vector2(X, Y), new Vector2(LastPoint.X, LastPoint.Y)) /
                                       Vector2.Distance(new Vector2(point.X, point.Y), new Vector2(point.LastPoint.X, point.LastPoint.Y));

                    if (similarity.Width > 1.0f)
                    {
                        similarity.Width = 1.0f / similarity.Width;
                    }
                }

                if (previousPoint == null)
                {
                    float distanceToPoint = Vector2.Distance(new Vector2(X, Y), new Vector2(point.X, point.Y));
                    similarity.Distance = distanceToPoint > 0 ? 1.0f / distanceToPoint : 1.0f;
                }

                return(similarity);
            }
示例#10
0
        private void ConnectEdgePoints(IEnumerable <EdgePoint>[] gridLines, List <Highlighter> highlighters)
        {
            // We want to join lines of similar edge lengths together. If we're coming from the tips of the fingers, we're fine increasing the width over time
            // If we're coming from the opposite, we're fine decreasing the width
            // Basically, we want to track whether the width increases or decreases as we go along
            List <EdgePoint> finalEdgeList = new List <EdgePoint>();

            for (int i = Input.LastClickPosition.X / gridInterval; i < gridLines.Count(); ++i)
            {
                EdgePoint      mostSimilarPoint  = null;
                SimilarityPack highestSimilarity = new SimilarityPack();

                foreach (EdgePoint p in gridLines[i])
                {
                    SimilarityPack similarity;

                    if (finalEdgeList.Count == 0)
                    {
                        similarity          = new SimilarityPack();
                        similarity.Distance = 1.0f / ((p.X - Input.LastClickPosition.X) * (p.X - Input.LastClickPosition.X) + (p.Y - Input.LastClickPosition.Y) * (p.Y - Input.LastClickPosition.Y));
                    }
                    else if (finalEdgeList.Count == 1)
                    {
                        similarity = p.CalculateSimilarity(finalEdgeList[0], null);
                    }
                    else
                    {
                        similarity = p.CalculateSimilarity(finalEdgeList[finalEdgeList.Count - 1], finalEdgeList[finalEdgeList.Count - 2]);
                    }

                    if (similarity.OverallSimilarity >= highestSimilarity.OverallSimilarity)
                    {
                        mostSimilarPoint  = p;
                        highestSimilarity = similarity;
                    }
                }

                finalEdgeList.Add(mostSimilarPoint);
                DebugInfo += highestSimilarity.Info + "\r\n";
            }

            for (int i = 1; i < finalEdgeList.Count; ++i)
            {
                highlighters.Add(new EdgeHighlighter(new Point(finalEdgeList[i - 1].X, finalEdgeList[i - 1].Y), new Point(finalEdgeList[i].X, finalEdgeList[i].Y))
                {
                    Pen = new Pen(Color.Green, 1.0f)
                });
            }
        }
示例#11
0
            public unsafe EdgePoint(int x, int y, ref ImageReader reader, ref EdgePoint lastPoint)
            {
                // Set vars
                X = x;
                Y = y;

                ColourUnderPoint = Color.FromArgb((int)reader.PixelRows[y][x]);

                LastPoint = lastPoint;

                SegmentCentre        = new Point(x, y);
                AverageSegmentColour = ColourUnderPoint;

                // Interpolate data from previous point if the point is available
                if (lastPoint != null)
                {
                    int xDiff = lastPoint.X - x, yDiff = lastPoint.Y - y;
                    int diffSize = (int)Math.Sqrt(xDiff * xDiff + yDiff * yDiff);

                    if (diffSize > 0)
                    {
                        // Backtrace along the line between this point and the last
                        uint r = 0, g = 0, b = 0;
                        for (int curX = x, curY = y, iteration = 0;
                             iteration < diffSize;
                             ++iteration, curX = x + (iteration * xDiff) / diffSize, curY = y + (iteration * yDiff) / diffSize)
                        {
                            b += reader.PixelRows[curY][curX] & 0xFF;
                            g += (reader.PixelRows[curY][curX] >> 8) & 0xFF;
                            r += (reader.PixelRows[curY][curX] >> 16) & 0xFF;
                        }

                        // Determine the average colour
                        AverageSegmentColour = Color.FromArgb((int)r / diffSize, (int)g / diffSize, (int)b / diffSize);
                        SegmentCentre        = new Point(x + xDiff / 2, y + yDiff / 2);
                    }
                }
            }
示例#12
0
 public Edge(EdgePoint sp, EdgePoint ep, EdgeType type)
 {
     StartPoint = sp; EndPoint = ep; Type = type;
 }
示例#13
0
        private List <Edge> getEdges()
        {
            List <Edge> edges = new List <Edge>();
            Dictionary <double, Edge>           pitchEdge = new Dictionary <double, Edge>();
            Dictionary <double, int>            refCnts   = new Dictionary <double, int>();
            Dictionary <double, List <double> > refs      = new Dictionary <double, List <double> >();

            foreach (MusicNote note in GetNotes())
            {
                List <double> keys = new List <double>(refCnts.Keys);

                if (note.Start)
                {
                    if (refs.ContainsKey(note.RoundedPitch))
                    {
                        refs[note.RoundedPitch] = keys;
                    }
                    else
                    {
                        refs.Add(note.RoundedPitch, keys);
                    }
                    if (keys.Count > 0)
                    {
                        foreach (double d in keys)
                        {
                            if (refCnts.ContainsKey(d))
                            {
                                refCnts[d]++;
                            }
                            else
                            {
                                refCnts.Add(d, 1);
                            }
                        }
                    }

                    double sx0 = getX(note.TimeInSec);
                    double sy0 = getY(note.RoundedPitch);
                    Edge   se  = new Edge(new EdgePoint(sx0, sy0), null, EdgeType.On);

                    #region 線を引く
                    if (keys.Count > 0)
                    {
                        foreach (double d in refs[note.RoundedPitch])
                        {
                            if (pitchEdge.ContainsKey(d))
                            {
                                Edge      oe       = pitchEdge[d];
                                EdgePoint prevEndP = oe.EndPoint;

                                int       x = se.StartPoint.Point.X; int y = prevEndP.Point.Y;
                                EdgePoint newP = new EdgePoint(x, y);

                                #region 横線(off)
                                Edge fe = prevEndP.Edges.Find((e) =>
                                {
                                    return(
                                        e.StartPoint == prevEndP &&
                                        e.EndPoint.Point.X == x &&
                                        e.EndPoint.Point.Y == y &&
                                        e.Type == EdgeType.Off);
                                });
                                if (fe == null)
                                {
                                    Edge offe = new Edge(prevEndP, newP, EdgeType.Off);
                                    edges.Add(offe);
                                }
                                else if (fe.EndPoint.Point.X < x)
                                {
                                    fe.EndPoint.Point.X = x;
                                }
                                #endregion

                                #region 縦線
                                if (newP.Point.Y != se.StartPoint.Point.Y)
                                {
                                    Edge de = new Edge(newP, se.StartPoint, EdgeType.Dip);
                                    edges.Add(de);
                                }
                                #endregion
                            }
                        }
                    }
                    else if (note.TimeInSec > 0)
                    {
                        #region 開始までの線
                        double x0 = 0;
                        double y0 = getY(note.RoundedPitch);
                        double x1 = getX(note.TimeInSec);
                        double y1 = y0;
                        edges.Add(new Edge(new EdgePoint(x0, y0), new EdgePoint(x1, y1), EdgeType.Off));
                        #endregion
                    }
                    #endregion

                    if (pitchEdge.ContainsKey(note.RoundedPitch))
                    {
                        pitchEdge[note.RoundedPitch] = se;
                    }
                    else
                    {
                        pitchEdge.Add(note.RoundedPitch, se);
                    }
                }
                else
                {
                    if (refs.ContainsKey(note.RoundedPitch))
                    {
                        foreach (double d in refs[note.RoundedPitch])
                        {
                            if (refCnts.ContainsKey(d))
                            {
                                refCnts[d]--;
                                if (refCnts[d] == 0)
                                {
                                    refCnts.Remove(d);
                                }
                            }
                        }
                        refs.Remove(note.RoundedPitch);
                    }

                    if (!refCnts.ContainsKey(note.RoundedPitch))
                    {
                        refCnts.Add(note.RoundedPitch, 0);
                    }
                    else
                    {
                        refCnts[note.RoundedPitch]++;
                    }

                    #region 線を引く
                    #region 横線(on)
                    if (pitchEdge.ContainsKey(note.RoundedPitch))
                    {
                        double x = getX(note.TimeInSec);
                        double y = getY(note.RoundedPitch);;
                        Edge   e = pitchEdge[note.RoundedPitch];
                        e.EndPoint = new EdgePoint(x, y);

                        edges.Add(e);
                    }
                    #endregion
                    #endregion
                }
            }

            #region 終了後の横線
            if (refCnts.Count > 0)
            {
                foreach (double d in refCnts.Keys)
                {
                    if (pitchEdge.ContainsKey(d))
                    {
                        double x = getX(Length);
                        double y = getY(d);
                        Edge   e = pitchEdge[d];
                        if (e.EndPoint == null)
                        {
                            e.EndPoint = new EdgePoint(x, y);
                            edges.Add(e);
                        }
                    }
                }
            }
            #endregion

            pitchEdge.Clear(); pitchEdge = null;
            refCnts.Clear(); refCnts     = null;
            refs.Clear(); refs           = null;

            return(edges);
        }
示例#14
0
        private List<Edge> getEdges()
        {
            List<Edge> edges = new List<Edge>();
            Dictionary<double, Edge> pitchEdge = new Dictionary<double, Edge>();
            Dictionary<double, int> refCnts = new Dictionary<double, int>();
            Dictionary<double, List<double>> refs = new Dictionary<double, List<double>>();

            foreach (MusicNote note in GetNotes())
            {
                List<double> keys = new List<double>(refCnts.Keys);

                if (note.Start)
                {
                    if (refs.ContainsKey(note.RoundedPitch))
                        refs[note.RoundedPitch] = keys;
                    else
                        refs.Add(note.RoundedPitch, keys);
                    if (keys.Count > 0)
                    {
                        foreach (double d in keys)
                        {
                            if (refCnts.ContainsKey(d)) refCnts[d]++;
                            else refCnts.Add(d, 1);
                        }
                    }

                    double sx0 = getX(note.TimeInSec);
                    double sy0 = getY(note.RoundedPitch);
                    Edge se = new Edge(new EdgePoint(sx0, sy0), null, EdgeType.On);

                    #region 線を引く
                    if (keys.Count > 0)
                    {
                        foreach (double d in refs[note.RoundedPitch])
                        {
                            if (pitchEdge.ContainsKey(d))
                            {
                                Edge oe = pitchEdge[d];
                                EdgePoint prevEndP = oe.EndPoint;

                                int x = se.StartPoint.Point.X; int y = prevEndP.Point.Y;
                                EdgePoint newP = new EdgePoint(x, y);

                                #region 横線(off)
                                Edge fe = prevEndP.Edges.Find((e) =>
                                {
                                    return (
                                        e.StartPoint == prevEndP &&
                                        e.EndPoint.Point.X == x &&
                                        e.EndPoint.Point.Y == y &&
                                        e.Type == EdgeType.Off);
                                });
                                if (fe == null)
                                {
                                    Edge offe = new Edge(prevEndP, newP, EdgeType.Off);
                                    edges.Add(offe);
                                }
                                else if (fe.EndPoint.Point.X < x)
                                {
                                    fe.EndPoint.Point.X = x;
                                }
                                #endregion

                                #region 縦線
                                if (newP.Point.Y != se.StartPoint.Point.Y)
                                {
                                    Edge de = new Edge(newP, se.StartPoint, EdgeType.Dip);
                                    edges.Add(de);
                                }
                                #endregion
                            }
                        }
                    }
                    else if (note.TimeInSec > 0)
                    {
                        #region 開始までの線
                        double x0 = 0;
                        double y0 = getY(note.RoundedPitch);
                        double x1 = getX(note.TimeInSec);
                        double y1 = y0;
                        edges.Add(new Edge(new EdgePoint(x0, y0), new EdgePoint(x1, y1), EdgeType.Off));
                        #endregion
                    }
                    #endregion

                    if (pitchEdge.ContainsKey(note.RoundedPitch)) pitchEdge[note.RoundedPitch] = se;
                    else pitchEdge.Add(note.RoundedPitch, se);
                }
                else
                {
                    if (refs.ContainsKey(note.RoundedPitch))
                    {
                        foreach (double d in refs[note.RoundedPitch])
                        {
                            if (refCnts.ContainsKey(d))
                            {
                                refCnts[d]--;
                                if (refCnts[d] == 0) refCnts.Remove(d);
                            }
                        }
                        refs.Remove(note.RoundedPitch);
                    }

                    if (!refCnts.ContainsKey(note.RoundedPitch)) refCnts.Add(note.RoundedPitch, 0);
                    else refCnts[note.RoundedPitch]++;

                    #region 線を引く
                    #region 横線(on)
                    if (pitchEdge.ContainsKey(note.RoundedPitch))
                    {
                        double x = getX(note.TimeInSec);
                        double y = getY(note.RoundedPitch); ;
                        Edge e = pitchEdge[note.RoundedPitch];
                        e.EndPoint = new EdgePoint(x, y);

                        edges.Add(e);
                    }
                    #endregion
                    #endregion
                }
            }

            #region 終了後の横線
            if (refCnts.Count > 0)
            {
                foreach (double d in refCnts.Keys)
                {
                    if (pitchEdge.ContainsKey(d))
                    {
                        double x = getX(Length);
                        double y = getY(d);
                        Edge e = pitchEdge[d];
                        if (e.EndPoint == null)
                        {
                            e.EndPoint = new EdgePoint(x, y);
                            edges.Add(e);
                        }
                    }
                }
            }
            #endregion

            pitchEdge.Clear(); pitchEdge = null;
            refCnts.Clear(); refCnts = null;
            refs.Clear(); refs = null;

            return edges;
        }
示例#15
0
 public Edge(EdgePoint sp, EdgePoint ep, EdgeType type)
 {
     StartPoint = sp; EndPoint = ep; Type = type;
 }
示例#16
0
        protected virtual void UpdateEdgePoints()
        {
            if (EdgePoints == null)
            {
                this.edgePointsVM = new ObservableCollection <EdgePointViewModel>();
            }

            EdgePoints.Clear();
            for (int i = 0; i < this.ShapeElement.EdgePoints.Count; i++)
            {
                EdgePointVMType t = EdgePointVMType.Normal;
                if (i == 0)
                {
                    t = EdgePointVMType.Start;
                }
                else if (i == this.ShapeElement.EdgePoints.Count - 1)
                {
                    t = EdgePointVMType.End;
                }
                else
                {
                    continue;   // TODO
                }
                EdgePointViewModel vm = new EdgePointViewModel(this.ViewModelStore, this.ShapeElement.EdgePoints[i], t);
                if (i > 0 && i < this.ShapeElement.EdgePoints.Count - 1)
                {
                    //vm.EdgePointOperation = EdgePointVMOperation.m
                }
                else
                {
                    RectangleD bounds;
                    if (t == EdgePointVMType.Start)
                    {
                        bounds = this.ShapeElement.FromShape.AbsoluteBounds;
                    }
                    else
                    {
                        bounds = this.ShapeElement.ToShape.AbsoluteBounds;
                    }

                    EdgePoint     p         = this.ShapeElement.EdgePoints[i];
                    LinkPlacement placement = LinkShape.GetLinkPlacement(bounds, new PointD(p.X, p.Y));
                    switch (placement)
                    {
                    case LinkPlacement.Bottom:
                        vm.EdgePointSide = EdgePointVMSide.Bottom;
                        break;

                    case LinkPlacement.Left:
                        vm.EdgePointSide = EdgePointVMSide.Left;
                        break;

                    case LinkPlacement.Right:
                        vm.EdgePointSide = EdgePointVMSide.Right;
                        break;

                    case LinkPlacement.Top:
                        vm.EdgePointSide = EdgePointVMSide.Top;
                        break;
                    }
                }
                EdgePoints.Add(vm);
            }

            OnPropertyChanged("EdgePoints");
            OnPropertyChanged("StartEdgePoint");
            OnPropertyChanged("EndEdgePoint");
            OnPropertyChanged("MiddleEdgePoint");
        }
示例#17
0
        static Color3 EvaluateMSDF(Shape shape, int[] windings, MultiDistance[] contourSD, Vector2 p, double range)
        {
            int contourCount = contourSD.Length;

            p += new Vector2(0.5f, 0.5f);

            EdgePoint sr = new EdgePoint {
                minDistance = new SignedDistance(-1e240, 1)
            };
            EdgePoint sg = new EdgePoint {
                minDistance = new SignedDistance(-1e240, 1)
            };
            EdgePoint sb = new EdgePoint {
                minDistance = new SignedDistance(-1e240, 1)
            };

            double d       = Math.Abs(SignedDistance.Infinite.distance);
            double negDist = -SignedDistance.Infinite.distance;
            double posDist = SignedDistance.Infinite.distance;
            int    winding = 0;

            for (int i = 0; i < contourCount; i++)
            {
                Contour   contour = shape.Contours[i];
                EdgePoint r       = new EdgePoint {
                    minDistance = new SignedDistance(-1e240, 1)
                };
                EdgePoint g = new EdgePoint {
                    minDistance = new SignedDistance(-1e240, 1)
                };
                EdgePoint b = new EdgePoint {
                    minDistance = new SignedDistance(-1e240, 1)
                };

                for (int j = 0; j < contour.Edges.Count; j++)
                {
                    EdgeSegment edge = contour.Edges[j];
                    double      param;

                    SignedDistance distance = edge.GetSignedDistance(p, out param);
                    if ((edge.Color & EdgeColor.Red) == EdgeColor.Red && distance < r.minDistance)
                    {
                        r.minDistance = distance;
                        r.nearEdge    = edge;
                        r.nearParam   = param;
                    }
                    if ((edge.Color & EdgeColor.Green) == EdgeColor.Green && distance < g.minDistance)
                    {
                        g.minDistance = distance;
                        g.nearEdge    = edge;
                        g.nearParam   = param;
                    }
                    if ((edge.Color & EdgeColor.Blue) == EdgeColor.Blue && distance < b.minDistance)
                    {
                        b.minDistance = distance;
                        b.nearEdge    = edge;
                        b.nearParam   = param;
                    }
                }

                if (r.minDistance < sr.minDistance)
                {
                    sr = r;
                }
                if (g.minDistance < sg.minDistance)
                {
                    sg = g;
                }
                if (b.minDistance < sb.minDistance)
                {
                    sb = b;
                }

                double medMinDistance = Math.Abs(Median(r.minDistance.distance, g.minDistance.distance, b.minDistance.distance));

                if (medMinDistance < d)
                {
                    d       = medMinDistance;
                    winding = -windings[i];
                }

                if (r.nearEdge != null)
                {
                    r.nearEdge.DistanceToPseudoDistance(ref r.minDistance, p, r.nearParam);
                }
                if (g.nearEdge != null)
                {
                    g.nearEdge.DistanceToPseudoDistance(ref g.minDistance, p, g.nearParam);
                }
                if (b.nearEdge != null)
                {
                    b.nearEdge.DistanceToPseudoDistance(ref b.minDistance, p, b.nearParam);
                }

                medMinDistance = Median(r.minDistance.distance, g.minDistance.distance, b.minDistance.distance);

                contourSD[i].r   = r.minDistance.distance;
                contourSD[i].g   = g.minDistance.distance;
                contourSD[i].b   = b.minDistance.distance;
                contourSD[i].med = medMinDistance;

                if (windings[i] > 0 && medMinDistance >= 0 && Math.Abs(medMinDistance) < Math.Abs(posDist))
                {
                    posDist = medMinDistance;
                }
                if (windings[i] < 0 && medMinDistance <= 0 && Math.Abs(medMinDistance) < Math.Abs(negDist))
                {
                    negDist = medMinDistance;
                }
            }

            if (sr.nearEdge != null)
            {
                sr.nearEdge.DistanceToPseudoDistance(ref sr.minDistance, p, sr.nearParam);
            }
            if (sg.nearEdge != null)
            {
                sg.nearEdge.DistanceToPseudoDistance(ref sg.minDistance, p, sg.nearParam);
            }
            if (sb.nearEdge != null)
            {
                sb.nearEdge.DistanceToPseudoDistance(ref sb.minDistance, p, sb.nearParam);
            }

            MultiDistance msd = new MultiDistance {
                r   = SignedDistance.Infinite.distance,
                g   = SignedDistance.Infinite.distance,
                b   = SignedDistance.Infinite.distance,
                med = SignedDistance.Infinite.distance,
            };

            if (posDist >= 0 && Math.Abs(posDist) <= Math.Abs(negDist))
            {
                msd.med = SignedDistance.Infinite.distance;
                winding = 1;
                for (int i = 0; i < contourCount; i++)
                {
                    if (windings[i] > 0 && contourSD[i].med > msd.med && Math.Abs(contourSD[i].med) < Math.Abs(negDist))
                    {
                        msd = contourSD[i];
                    }
                }
            }
            else if (negDist <= 0 && Math.Abs(negDist) <= Math.Abs(posDist))
            {
                msd.med = -SignedDistance.Infinite.distance;
                winding = -1;
                for (int i = 0; i < contourCount; i++)
                {
                    if (windings[i] < 0 && contourSD[i].med < msd.med && Math.Abs(contourSD[i].med) < Math.Abs(posDist))
                    {
                        msd = contourSD[i];
                    }
                }
            }

            for (int i = 0; i < contourCount; i++)
            {
                if (windings[i] != winding && Math.Abs(contourSD[i].med) < Math.Abs(msd.med))
                {
                    msd = contourSD[i];
                }
            }

            if (Median(sr.minDistance.distance, sg.minDistance.distance, sb.minDistance.distance) == msd.med)
            {
                msd.r = sr.minDistance.distance;
                msd.g = sg.minDistance.distance;
                msd.b = sb.minDistance.distance;
            }

            return(new Color3((float)(msd.r / range) + 0.5f, (float)(msd.g / range) + 0.5f, (float)(msd.b / range) + 0.5f));
        }
    void GeneratePath(int p_layerIndex = 0, int p_startPosition = 0)
    {
        //List<RaycastHit> currentLayer = allEdgeLoops[p_layerIndex];
        List <EdgePoint> selectedPoints;
        EdgePoint        lastSelectedPoint = new EdgePoint();
        float            angleBetweenPoints;
        bool             skipBlock = false;
        bool             nextLine  = false;
        int index;

        if (p_layerIndex == allEdgeLoops.Count - 1)
        {
            //If we have reached the last layer, STOP
            return;
        }

        selectedPoints = FindEquiDistancedPoints(p_layerIndex);

        index = 0;
        //foreach(RaycastHit hit in currentLayer)
        foreach (EdgePoint hit in selectedPoints)
        {
            //Go through nodes in the current layer and select nodes to be used as a part of the path

            if (skipBlock)
            {
                //If a block was skipped last time,
                //Do not skip again this time
                skipBlock = false;
            }
            else
            {
                //IF LAST ACTION != SKIP 1 BLOCK
                //  Decide if 1 block needs to be skipped (Randomly)
                skipBlock = Random.Range(1, 100) % 2 == 0 ? true : false;
            }

            if (!skipBlock)
            {
                //If the prev hit and current hit are pointing in completely different direction (deviating over 20 degrees)
                angleBetweenPoints = Vector3.Angle(hit.hit.normal, lastSelectedPoint.hit.normal);
                if (angleBetweenPoints >= 20.0f)
                {
                    Debug.DrawRay(hit.hit.point,
                                  hit.hit.normal,
                                  Color.blue,
                                  3.0f);

                    //InstantiateBridge(p_layerIndex, lastSelectedPoint.index, hit.index);
                    InstantiateBridge_UniquePoints(p_layerIndex, lastSelectedPoint.index, hit.index);
                }
                else
                {
                    Debug.DrawRay(hit.hit.point,
                                  hit.hit.normal,
                                  Color.green,
                                  3.0f);
                }

                //Instantiate a node at this point
                InstantiateNode(hit.hit.point, hit.hit.normal);
                lastSelectedPoint = hit;
            }


            //if this is the last node of this level
            if (index == selectedPoints.Count - 1)
            {
                //  GO to next level
                GeneratePath(p_layerIndex + 1);
                break;
            }
            else
            {
                //  Decide if we need to go to to next level
                nextLine = Random.Range(1, 999) % 7.5 == 0 ? true : false;
                if (nextLine)
                {
                    GeneratePath(p_layerIndex + 1);
                    break;
                }
            }
            index++;
        }
    }
示例#19
0
        private static void UpdateConnectors(GeometryGraph graph)
        {
            foreach (Edge edge in graph.Edges)
            {
                BinaryLinkShape linkShape = (BinaryLinkShape)edge.UserData;

                // need to mark the connector as dirty. this is the easiest way to do this
                linkShape.ManuallyRouted = !linkShape.ManuallyRouted;
                linkShape.FixedFrom      = VGFixedCode.NotFixed;
                linkShape.FixedTo        = VGFixedCode.NotFixed;

                // make the labels follow the lines
                foreach (LineLabelShape lineLabelShape in linkShape.RelativeChildShapes.OfType <LineLabelShape>())
                {
                    lineLabelShape.ManuallySized  = false;
                    lineLabelShape.ManuallyPlaced = false;
                }

                linkShape.EdgePoints.Clear();

                // MSAGL deals in line segments; DSL deals in points
                // with the segments, tne end of one == the beginning of the next, so we can use just the beginning point
                // of each segment.
                // But we have to hang on to the end point so that, when we hit the last segment, we can finish off the
                // set of points
                if (edge.Curve is LineSegment lineSegment)
                {
                    // When curve is a single line segment.
                    linkShape.EdgePoints.Add(new EdgePoint(lineSegment.Start.X, lineSegment.Start.Y, VGPointType.Normal));
                    linkShape.EdgePoints.Add(new EdgePoint(lineSegment.End.X, lineSegment.End.Y, VGPointType.Normal));
                }
                else if (edge.Curve is Curve curve)
                {
                    //// When curve is a complex segment.
                    EdgePoint lastPoint = null;

                    foreach (ICurve segment in curve.Segments)
                    {
                        switch (segment.GetType().Name)
                        {
                        case "LineSegment":
                            LineSegment line = segment as LineSegment;
                            linkShape.EdgePoints.Add(new EdgePoint(line.Start.X, line.Start.Y, VGPointType.Normal));
                            lastPoint = new EdgePoint(line.End.X, line.End.Y, VGPointType.Normal);

                            break;

                        case "CubicBezierSegment":
                            CubicBezierSegment bezier = segment as CubicBezierSegment;

                            // there are 4 segments. Store all but the last one
                            linkShape.EdgePoints.Add(new EdgePoint(bezier.B(0).X, bezier.B(0).Y, VGPointType.Normal));
                            linkShape.EdgePoints.Add(new EdgePoint(bezier.B(1).X, bezier.B(1).Y, VGPointType.Normal));
                            linkShape.EdgePoints.Add(new EdgePoint(bezier.B(2).X, bezier.B(2).Y, VGPointType.Normal));
                            lastPoint = new EdgePoint(bezier.B(3).X, bezier.B(3).Y, VGPointType.Normal);

                            break;

                        case "Ellipse":
                            // rather than draw a curved line, we'll bust the curve into 5 parts and draw those as straight lines
                            Ellipse ellipse  = segment as Ellipse;
                            double  interval = (ellipse.ParEnd - ellipse.ParStart) / 5.0;
                            lastPoint = null;

                            for (double i = ellipse.ParStart; i <= ellipse.ParEnd; i += interval)
                            {
                                Point p = ellipse.Center
                                          + (Math.Cos(i) * ellipse.AxisA)
                                          + (Math.Sin(i) * ellipse.AxisB);

                                // we'll remember the one we just calculated, but store away the one we calculated last time around
                                // (if there _was_ a last time around). That way, when we're done, we'll have stored all of them except
                                // for the last one
                                if (lastPoint != null)
                                {
                                    linkShape.EdgePoints.Add(lastPoint);
                                }

                                lastPoint = new EdgePoint(p.X, p.Y, VGPointType.Normal);
                            }

                            break;
                        }
                    }

                    // finally tuck away the last one. Now we don't have duplicate points in our list
                    if (lastPoint != null)
                    {
                        linkShape.EdgePoints.Add(lastPoint);
                    }
                }

                // since we're not changing the nodes this edge connects, this really doesn't do much.
                // what it DOES do, however, is call ConnectEdgeToNodes, which is an internal method we'd otherwise
                // be unable to access
                linkShape.Connect(linkShape.FromShape, linkShape.ToShape);
                linkShape.ManuallyRouted = false;
            }
        }
示例#20
0
 public Edge(EdgePoint a, EdgePoint b, float r, cpVect n)
 {
     this.a = a;
     this.b = b;
     this.r = r;
     this.n = n;
 }
        public static bool BShoot(EdgePoint edgePoint, Layout layout)
        {
            Rectangle rect = layout.ToRectangle();

            return(rect.Contains(edgePoint.LeftPoint) || rect.Contains(edgePoint.RightPoint) || rect.Contains(edgePoint.TopPoint) || rect.Contains(edgePoint.ButtomPoint));
        }
示例#22
0
            protected override FloatRgb ComputePixel(ref InstanceContext ctx)
            {
                EdgePoint sr = EdgePoint.Default, sg = EdgePoint.Default, sb = EdgePoint.Default;
                var       d = Math.Abs(SignedDistance.Infinite.Distance);

                for (var i = 0; i < Shape.Count; ++i)
                {
                    EdgePoint r = EdgePoint.Default, g = EdgePoint.Default, b = EdgePoint.Default;

                    MsdfScanContourEdges(Shape[i], ctx.P, ref r, ref g, ref b);

                    if (r.MinDistance < sr.MinDistance)
                    {
                        sr = r;
                    }
                    if (g.MinDistance < sg.MinDistance)
                    {
                        sg = g;
                    }
                    if (b.MinDistance < sb.MinDistance)
                    {
                        sb = b;
                    }

                    var medMinDistance = Math.Abs(Arithmetic.Median(r.MinDistance.Distance,
                                                                    g.MinDistance.Distance,
                                                                    b.MinDistance.Distance));

                    if (medMinDistance < d)
                    {
                        d           = medMinDistance;
                        ctx.Winding = -Windings[i];
                    }

                    r.NearEdge?.DistanceToPseudoDistance(ref r.MinDistance, ctx.P, r.NearParam);
                    g.NearEdge?.DistanceToPseudoDistance(ref g.MinDistance, ctx.P, g.NearParam);
                    b.NearEdge?.DistanceToPseudoDistance(ref b.MinDistance, ctx.P, b.NearParam);
                    medMinDistance = Arithmetic.Median(r.MinDistance.Distance, g.MinDistance.Distance,
                                                       b.MinDistance.Distance);
                    ContourSd[i].R   = r.MinDistance.Distance;
                    ContourSd[i].G   = g.MinDistance.Distance;
                    ContourSd[i].B   = b.MinDistance.Distance;
                    ContourSd[i].Med = medMinDistance;
                    ctx.UpdateDistance(Windings[i], medMinDistance);
                }

                sr.NearEdge?.DistanceToPseudoDistance(ref sr.MinDistance, ctx.P, sr.NearParam);
                sg.NearEdge?.DistanceToPseudoDistance(ref sg.MinDistance, ctx.P, sg.NearParam);
                sb.NearEdge?.DistanceToPseudoDistance(ref sb.MinDistance, ctx.P, sb.NearParam);

                var msd = ComputeSd(Infinite, ref ctx);

                if (Arithmetic.Median(sr.MinDistance.Distance, sg.MinDistance.Distance, sb.MinDistance.Distance) ==
                    msd.Med)
                {
                    msd.R = sr.MinDistance.Distance;
                    msd.G = sg.MinDistance.Distance;
                    msd.B = sb.MinDistance.Distance;
                }

                return(new FloatRgb
                {
                    R = (float)(msd.R / Range + .5),
                    G = (float)(msd.G / Range + .5),
                    B = (float)(msd.B / Range + .5)
                });
            }
示例#23
0
        private void FindEdgesOnLine(ref ImageReader reader, ref ImageReader diffReader, out List <EdgePoint> edgePoints, Point start, int xStep, int yStep)
        {
            edgePoints = new List <EdgePoint>();

            unsafe
            {
                // Determine the popularity of brightnesses (we'll grab the pixels brighter than a percentile)
                int   x = start.X, y = start.Y;
                int[] counts             = new int[256];
                int   numPixelsAlongLine = 0;

                Array.Clear(counts, 0, 256);

                while (x >= 0 && y >= 0 && x < diffReader.Width && y < diffReader.Height)
                {
                    ++counts[diffReader.PixelRows[y][x] & 0xFF];
                    ++numPixelsAlongLine;

                    x += xStep;
                    y += yStep;
                }

                // Considering the averages, determine the brightness threshold to qualify a pixel
                int expectedCount       = 90 * numPixelsAlongLine / 100;
                int brightnessThreshold = 0;

                for (int i = 0, currentCount = 0; i < 256; ++i)
                {
                    if (currentCount >= expectedCount)
                    {
                        brightnessThreshold = i;
                        break;
                    }

                    currentCount += counts[i];
                }

                // Step along again, this time marking pixels that exceed the brightness threshold
                bool      wasAboveThreshold = false;
                EdgePoint lastEdgePoint     = null;

                x = start.X;
                y = start.Y;

                while (x >= 0 && y >= 0 && x < diffReader.Width && y < diffReader.Height)
                {
                    // Register the pixel if it's just gone above the threshold
                    bool isAboveThreshold = ((diffReader.PixelRows[y][x] & 0xFF) > brightnessThreshold);

                    if (isAboveThreshold && !wasAboveThreshold)
                    {
                        lastEdgePoint = new EdgePoint(x, y, ref reader, ref lastEdgePoint);
                        edgePoints.Add(lastEdgePoint);
                    }

                    // Advance
                    wasAboveThreshold = isAboveThreshold;
                    x += xStep;
                    y += yStep;
                }
            }
        }
 /// <summary>
 /// Converts an edge point to its string representation.
 /// </summary>
 /// <param name="culture"></param>
 /// <param name="point"></param>
 /// <returns></returns>
 internal static string ConvertToString(CultureInfo culture, EdgePoint point)
 {
     object[] objArr = new object[3];
     objArr[0] = point.Point.X.ToString(culture);
     objArr[1] = point.Point.Y.ToString(culture);
     objArr[2] = point.PointType.ToString();
     return System.String.Format(culture, "({0} : {1} : {2})", objArr);
 }
示例#25
0
    IEnumerator DamageTimer()
    {
        int minutes = Mathf.FloorToInt(vsTimer / 60F);
        int seconds = Mathf.FloorToInt(vsTimer - minutes * 60);

        voidStormTimer.text = string.Format("{0:0}:{1:00}", minutes, seconds);

        if ((vsTimer <= 91) && (vsTimer > 30))
        {
            voidStormTimer.color = Color.yellow;
        }

        if ((vsTimer <= 31) && (vsTimer > 1))
        {
            voidStormTimer.color = Color.red;

            if (!voidStormActive)
            {
                voidStormActive = true;
                VoidStormPuzzle(State.NONE);
                for (int i = 0; i < 6; i++)
                {
                    vsBaseEffect[i].Play();
                }
            }
        }

        if (vsTimer <= 1)
        {
            float vsDamage;
            vsDamage = playerStat.Health.GetValue() * 0.25f;

            if (!voidStormAttack)
            {
                voidStormAttack = true;

                foreach (GameObject EdgePoint in edgePoints)
                {
                    EdgePoint.GetComponent <EdgePoint>().SetState(State.NONE);
                }

                vsLightningEffect.Play();
                playerStat.TakeDamage(vsDamage, 0);
            }

            yield return(new WaitForSeconds(1f));

            for (int i = 0; i < 6; i++)
            {
                vsBaseEffect[i].Stop();
            }

            vsLightningEffect.Stop();

            voidStormActive = false;

            vsTimer = 150f;
            voidStormTimer.color = Color.white;

            voidStormAttack = false;
        }

        vsCoroutine = null;
    }