public CircleCollider2D corner; // Start corner protected virtual void Init() { gameObject.tag = "Line"; lineRender = GetComponent <LineRenderer>(); boxCollider = GetComponent <BoxCollider2D>(); // Initialize lineRenderer if (lineRender == null) { gameObject.AddComponent <LineRenderer>(); } lineRender.positionCount = 2; lineRender.SetPosition(0, Vector3.zero); lineRender.SetPosition(1, Vector3.zero); lineRender.useWorldSpace = false; // Initialize boxCollider if (boxCollider == null) { gameObject.AddComponent <BoxCollider2D>(); } boxCollider.size = new Vector2(lineRender.startWidth, lineRender.endWidth); boxCollider.offset = Vector2.zero; direction = LineDirection.UNKNOWNED; }
/// <summary> /// Creates a new instance of the line class that is either horizontal or vertical /// </summary> /// <param name="start">The start location of the line, on the axis parallel to the line direction</param> /// <param name="end">The end location of the line, on the axis parallel to the line direction</param> /// <param name="staticPosition">The location of the line on the axis perpendicular to the line direction</param> /// <param name="direction">The direction in which the line is oriented</param> public Line(int start, int end, int staticPosition, LineDirection direction) { if (direction == LineDirection.Horizontal) { if (start < end) { startPoint = new Point(start, staticPosition); endPoint = new Point(end, staticPosition); } else { startPoint = new Point(end, staticPosition); endPoint = new Point(start, staticPosition); } } else { if (start < end) { startPoint = new Point(staticPosition, start); endPoint = new Point(staticPosition, end); } else { startPoint = new Point(staticPosition, end); endPoint = new Point(staticPosition, start); } } }
public void PutPlayerToLine(LineDirection line) { int direction = (int)line; _currentLane = direction + 1; _characterCollider.transform.localPosition = _targetPosition = new Vector3((direction) * _trackManager.laneOffset, 0f, 0f); }
public void DrawLine(LineDirection direction, float offset) { try { float heigth = GetTextSize("1").Height; if (direction == LineDirection.Horizontal) { g.DrawLine( new Pen(Brushes.Line, PenWidth), new PointF(0, heigth + offset), new PointF(DrawArea.Width, heigth + offset) ); } else if (direction == LineDirection.Vertical) { this.offsetV = offset; g.DrawLine( new Pen(Brushes.Line, PenWidth), new PointF(offset, 0), new PointF(offset, DrawArea.Height) ); } else { throw new ArgumentException(); } } catch (Exception e) { throw e; } }
public static bool IsDirectionOpposite(LineDirection d1, LineDirection d2) { return(d1 == LineDirection.North && d2 == LineDirection.South || d1 == LineDirection.South && d2 == LineDirection.North || d1 == LineDirection.East && d2 == LineDirection.West || d1 == LineDirection.West && d2 == LineDirection.East); }
private static char GetLineChar(LineDirection direction, SegmentType segmentType) { switch (segmentType) { case SegmentType.Line: switch (direction) { case LineDirection.East: case LineDirection.West: return('-'); case LineDirection.North: case LineDirection.South: return('|'); default: throw new ArgumentOutOfRangeException(); } case SegmentType.Slope: return('+'); default: throw new ArgumentOutOfRangeException(); } }
public Line(int _x, int _y, int _lenght, LineDirection _direction, char _symb) { pList = new List <Point>(); if (_direction == LineDirection.Horizontal) { for (int x = _x; x < _lenght; x++) { Point p = new Point(x, _y, _symb); pList.Add(p); } } else if (_direction == LineDirection.Vertical) { for (int y = _y; y < _lenght; y++) { Point p = new Point(_x, y, _symb); pList.Add(p); } } //x = _x; //y = _y; //lenght = _lenght; //direction = _direction; //symb = _symb; }
public static Bounds Sum(this Bounds original, LineDirection direction, IEnumerable <Bounds> occupied) { if (direction == LineDirection.Horizontal) { return(new Bounds(x: original.X, y: original.Y, width: occupied.Aggregate(0, (lhs, rhs) => lhs + rhs.Width), height: occupied.Max(item => item.Height))); } return(new Bounds(x: original.X, y: original.Y, width: occupied.Max(item => item.Width), height: occupied.Aggregate(0, (lhs, rhs) => lhs + rhs.Height))); }
public static Bounds Remaining(this Bounds original, LineDirection direction, Bounds occupied) { if (direction == LineDirection.Horizontal) { return(new Bounds(x: original.X + occupied.Width, y: original.Y, width: original.Width - occupied.Width, height: original.Height)); } return(new Bounds(x: original.X, y: original.Y + occupied.Height, width: original.Width, height: original.Height - occupied.Height)); }
public GameLine(int xindex, int yindex, LineDirection direction, Transform parent) { Vector3 actualStart = GridData.IndexToVector(xindex, yindex);// + new Vector3(GridData.NodeSpacing / 2.0f, 0); int deg = dirToDegrees[direction]; Quaternion rotation = Quaternion.Euler(new Vector3(0, 0, deg)); this.lineObject = MonoBehaviour.Instantiate(prefab, actualStart, rotation) as GameObject; this.lineObject.transform.SetParent(parent); }
/// <summary> /// Calling the base class to initate [disembarkersAtStation] /// Should not be needed to call. /// </summary> //void start() //{ // base.Start(); //} /// <summary> /// To reuse the vehicle. /// Override so that the gameobject position is not set to the currentStation at reset. /// </summary> /// <param name="direction"></param> public override void ResetVehicle(LineDirection direction) { this.direction = direction; currentStation = line.GetFirstStop(direction); nextStation = currentStation; capacity = line.GetVehicleCapacity(); InitLists(); ResetTimer(); }
private void SetLineDirection(LineDirection direction) { IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost)); using (DesignerTransaction designerTransaction = host.CreateTransaction("Changing Line Direction")) { Line.SetLineDirection(direction, true); designerTransaction.Commit(); } }
/// <summary> /// To reuse the vehicle. /// Override by SumoBusController so that the gameobject position is not set to the currentStation at reset. /// </summary> /// <param name="direction"></param> public virtual void ResetVehicle(LineDirection direction) { this.direction = direction; currentStation = line.GetFirstStop(direction); nextStation = currentStation; transform.position = currentStation.transform.position; capacity = line.GetVehicleCapacity(); InitLists(); ResetTimer(); }
void GetDirection() { if (Math.Abs(line.X1 - line.X2) > Math.Abs(line.Y1 - line.Y2)) { this._LineDirection = LineDirection.Horizontal; } else { this._LineDirection = LineDirection.Vertical; } }
public StationController GetLastStop(LineDirection direction) { if (direction == LineDirection.OutBound) { return(stations.Last()); } else { return(stations.First()); } }
public PartEntityLine AddLineEntity(LineDirection direction, Vector2 start, float length, EntityType type = EntityType.Normal) { PartEntityLine entity = new PartEntityLine() { Start = start, End = Utils.CalcEnd(start, length, direction), EntityType = type }; Entities.Add(entity); return(entity); }
//find lines public static void Lines(Bitmap img, LineDirection lineDirection) { string imgName = GetImageInfo.Imginfo(Imageinfo.FileName); string defPath = GetImageInfo.MyPath("Segmentation\\Lines"); Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb); int[,] lineRes = new int[img.Height, img.Width]; string outName = String.Empty; var imArray = MoreHelpers.BlackandWhiteProcessHelper(img); if (imArray.GetLength(0) > 1 && imArray.GetLength(1) > 1) { //choose filter and use it switch (lineDirection) { case LineDirection.horizontal: double[,] horisontalFilter = { { -1, -1, -1 }, { 2, 2, 2 }, { -1, -1, -1 } }; lineRes = FindLineHelper(imArray, horisontalFilter); outName = defPath + imgName + "_HorisontalLine.png"; break; case LineDirection.vertical: double[,] verticalFilter = { { -1, 2, -1 }, { -1, 2, -1 }, { -1, 2, -1 } }; lineRes = FindLineHelper(imArray, verticalFilter); outName = defPath + imgName + "_VerticalLine.png"; break; case LineDirection.plus45: double[,] plus45Filter = { { -1, -1, 2 }, { -1, 2, -1 }, { 2, -1, -1 } }; lineRes = FindLineHelper(imArray, plus45Filter); outName = defPath + imgName + "_Plus45Line.png"; break; case LineDirection.minus45: double[,] minus45Filter = { { 2, -1, -1 }, { -1, 2, -1 }, { -1, -1, 2 } }; lineRes = FindLineHelper(imArray, minus45Filter); outName = defPath + imgName + "_Minus45Line.png"; break; } image = Helpers.SetPixels(image, lineRes, lineRes, lineRes); image = PixelFormatWorks.Bpp24Gray2Gray8bppBitMap(image); Helpers.SaveOptions(image, outName, ".png"); } }
public StationController GetPreviousStop(StationController station, LineDirection direction) { int prevIndex = GetIndex(station) - (int)direction; if (prevIndex >= 0 && prevIndex < stations.Count) { return(stations[prevIndex]); } else { return(null); } }
public void ChangeLane(LineDirection line) { int direction = (int)line; int targetLane = _currentLane + direction; if (targetLane < 0 || targetLane > 2) { return; } _currentLane = targetLane; _targetPosition = new Vector3((_currentLane - 1) * _trackManager.laneOffset, 0f, 0f); }
public StationController GetNextStop(StationController station, LineDirection direction) { int nextIndex = GetIndex(station) + (int)direction; if (nextIndex >= 0 && nextIndex < stations.Count) { return(stations[nextIndex]); } else { return(null); } }
public LineSegment(int id, SlopedLineVectorized l, Coord from, Coord to, SegmentType type, LineDirection direction) { if (type == SegmentType.Slope && from != to) { throw new ArgumentException("Slopes can only be size 1"); } Id = id; Origin = l; From = from; To = to; Type = type; Direction = direction; }
// Detect direction of line protected void DetectDirection() { if (start.x == end.x) { this.direction = (start.y > end.y) ? LineDirection.DOWN : LineDirection.UP; } else if (start.y == end.y) { this.direction = (start.x > end.x) ? LineDirection.LEFT : LineDirection.RIGHT; } else { this.direction = LineDirection.UNKNOWNED; } }
/// <summary> /// Set the Line's Start and End points /// TODO [Sadhana] : make this method private after MgLine will not use Points /// </summary> public static Point[] GetLinePoints(Rectangle Rectangle, int LineWidth, LineDirection lineDirection) { int X = Rectangle.X; int Y = Rectangle.Y; int Width = Rectangle.Width; int Height = Rectangle.Height; Point StartPoint = Point.Empty; Point EndPoint = Point.Empty; int offset = 0; if (LineWidth > 1) { offset = (int)Math.Ceiling((double)LineWidth / 2); } switch (lineDirection) { case LineDirection.Horizontal: // Centered Vertically StartPoint = new Point(X + offset, Y + (Height / 2)); EndPoint = new Point(X + (Width - offset), Y + (Height / 2)); break; case LineDirection.Vertical: // Centered Horizontally StartPoint = new Point(X + (Width / 2), Y + offset); EndPoint = new Point(X + (Width / 2), Y + (Height - offset)); break; case LineDirection.NESW: // '/' shape line offset += 1; StartPoint = new Point(X + (Width - offset), Y + offset); EndPoint = new Point(X + offset, Y + (Height - offset)); break; case LineDirection.NWSE: // '\' shape offset += 1; StartPoint = new Point(X + offset, Y + offset); EndPoint = new Point(X + (Width - offset), Y + (Height - offset)); break; default: Debug.Assert(false, "This line direction is not supported "); break; } return(new Point[] { StartPoint, EndPoint }); }
public LoopSeg(TBPLineSegment seg, TBPoint startP) { segment = seg; if (startP == seg.StartPoint) { direction = LineDirection.positive; } else if (startP == seg.EndPoint) { direction = LineDirection.negtive; } else { throw new System.Exception("BoundarySeg.cs 39"); } }
public int GetVaildCornerID(int blockID, LineDirection dir) { int cornerID = GetCornerID(blockID, dir); if ((targetPair.ContainsKey(cornerID) && targetPair[cornerID] != targetPair[currentTargetBlock]) || IsLinedBlock(cornerID)) //拐角为端点,去掉 { cornerID = GetCornerID2(blockID, dir); if ((targetPair.ContainsKey(cornerID) && targetPair[cornerID] != targetPair[currentTargetBlock]) || IsLinedBlock(cornerID)) { return(-1); } } if (cornerID < 0 || cornerID > sideNum * sideNum - 1) { return(-1); } return(cornerID); }
private Quaternion GetHalfLineRotation(LineDirection inLine) { switch (inLine) { case LineDirection.Down: return(BlockImageRotation.rotation0); case LineDirection.Up: return(BlockImageRotation.rotation180); case LineDirection.Left: return(BlockImageRotation.rotation270); case LineDirection.Right: return(BlockImageRotation.rotation90); } return(BlockImageRotation.rotation0); }
private int GetCornerID2(int blockID, LineDirection direction) { switch (direction) { case LineDirection.RightUp: return(blockID + 1); case LineDirection.RightDown: return(blockID + 1); case LineDirection.LeftUp: return(blockID - 1); case LineDirection.LeftDown: return(blockID - 1); } return(-1); }
private void DrawLinePatternSettingsGUI() { // Minimum and Maximum Color Values EditorGUI.BeginChangeCheck(); float min = CurrentPattern.MinimumValue; float max = CurrentPattern.MaximumValue; EditorGUILayout.MinMaxSlider(ContentText.lineRangeProperty, ref min, ref max, 0.0f, 1.0f); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(CurrentPattern, ContentText.inspectorUndo); CurrentPattern.MinimumValue = min; CurrentPattern.MaximumValue = max; EditorUtility.SetDirty(CurrentPattern); } // Color Variance SerializedProperty colorVarianceProperty = serializedObject.FindProperty("ColorVariance"); EditorGUILayout.Slider(colorVarianceProperty, 0.0f, 0.5f, ContentText.varianceProperty); // Element Size EditorGUI.BeginChangeCheck(); int elementSize = EditorGUILayout.IntSlider(ContentText.lineWidthProperty, (int)CurrentPattern.ElementSize, 1, 8); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(CurrentPattern, ContentText.inspectorUndo); CurrentPattern.ElementSize = (float)Mathf.ClosestPowerOfTwo(elementSize); EditorUtility.SetDirty(CurrentPattern); } // Line Direction EditorGUI.BeginChangeCheck(); LineDirection direction = (LineDirection)EditorGUILayout.EnumPopup(ContentText.lineDirectiomProperty, CurrentPattern.Direction); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(CurrentPattern, ContentText.inspectorUndo); CurrentPattern.Direction = direction; EditorUtility.SetDirty(CurrentPattern); } }
private void UpdateAllBlock() { foreach (KeyValuePair <int, BaseBlock> pair in blockDictionary) { pair.Value.ClearBlock(); } foreach (KeyValuePair <int, List <int> > pair in paths) { List <int> path = pair.Value; int last = -1; LineDirection preDir = LineDirection.None; for (int i = 0; i < path.Count; i++) { if (i == 0) { last = path[i]; continue; } LineDirection dir = GetDirection(last, path[i]); BaseBlock block = GetBlock(last); block.SetBlock(preDir, ReverseDirection(dir), targetImage[pair.Key]); preDir = dir; if (i == (path.Count - 1)) { int id = path[i]; if (id == targetPair[pair.Key]) { block = GetBlock(id); block.SetBlock(preDir, LineDirection.None, targetImage[pair.Key]); //Debug.Log("block:" + block.id + " preDir:" + preDir); } else { block = GetBlock(id); block.SetBlock(preDir, LineDirection.Middle, targetImage[pair.Key]); //Debug.Log("block:" + block.id + " preDir:" + preDir); } } last = path[i]; } } }
public static string MakeKeyString(int lineId, LineDirection direction) { string str; switch (direction) { case LineDirection.InBound: str = "-"; break; case LineDirection.OutBound: str = "+"; break; default: str = "?"; break; } return(str + lineId.ToString()); }
public static LineDirection GetOppositeDirection(LineDirection direction) { switch (direction) { case LineDirection.North: return(LineDirection.South); case LineDirection.South: return(LineDirection.North); case LineDirection.East: return(LineDirection.West); case LineDirection.West: return(LineDirection.East); default: throw new ArgumentOutOfRangeException(nameof(direction), direction, null); } }
/// <summary> /// Draws the line. /// </summary> /// <param name='direction'> /// Direction. /// </param> /// <param name='color'> /// Color. /// </param> public void DrawLine(LineDirection direction, LineColor color) { DrawLine(direction, color, -1f); }
/// <summary> /// Draws the line. /// </summary> /// <param name='direction'> /// Direction. /// </param> /// <param name='color'> /// Color. /// </param> /// <param name='length'> /// Length. /// </param> public void DrawLine(LineDirection direction, LineColor color, float length) { m_GUIColor = GUI.color; switch (color) { case LineColor.Dark: GUI.color = darkTextColor; break; case LineColor.Medium: GUI.color = mediumTextColor; break; case LineColor.Light: GUI.color = lightTextColor; break; case LineColor.Highlighted: GUI.color = highlightTextColor; break; } switch (direction) { case LineDirection.Horizontal: if (length > 0f) { GUILayout.Box("", line, GUILayout.Height(lineWeight), GUILayout.Width(length)); } else { GUILayout.Box("", line, GUILayout.Height(lineWeight)); } break; case LineDirection.Vertical: if (length > 0f) { GUILayout.Box("", line, GUILayout.Width(lineWeight), GUILayout.Height(length)); } else { GUILayout.Box("", line, GUILayout.Width(lineWeight)); } break; } GUI.color = m_GUIColor; }
public static DistanceResult LineToLine(Measurement first, Measurement second, HTuple angle, LineDirection direction) { //get value var line1 = first.GetViewModel(); var line2 = second.GetViewModel(); //check if (line1 == null || line2 == null) return null; if (line1.Row1 == null && line1.Row1.TupleLength() == 0 && line2.Row1 == null && line2.Row1.TupleLength() == 0) return null; //act HTuple distanceMin, distanceMax; HOperatorSet.DistanceSs(line1.Row1, line1.Col1, line1.Row2, line1.Col2, line2.Row1, line2.Col1, line2.Row2, line2.Col2 , out distanceMin, out distanceMax); return new DistanceResult() { FirstRowBegin = new HTuple(line1.Row1), FirstColBegin = new HTuple(line1.Col1), FirstRowEnd = new HTuple(line1.Row2), FirstColEnd = new HTuple(line1.Col2), SecondRowBegin = new HTuple(line2.Row1), SecondColBegin = new HTuple(line2.Col1), SecondRowEnd = new HTuple(line2.Row2), SecondColEnd = new HTuple(line2.Col2), Direction = direction, Distance = new HTuple(distanceMin), Angle = angle, }; }
public void SetOutputShape(IShapeBase outputShape) { this.OutputShape = outputShape; if (this.InputShape == null) { this.LastLinePen.StartCap = LineCap.Round; this.LastLinePen.CustomEndCap = new AdjustableArrowCap(5, 5); this.CurrentLineDirection = LineDirection.OutputToInput; this.StartPoint = outputShape.OutputPinCenter(); this.OutputShape.Out_ShapeDragged += (IShapeDraggedMessage shapeDraggedMessage) => { this.StartPoint = shapeDraggedMessage.OutputPinCenter; }; } else { this.EndPoint = outputShape.OutputPinCenter(); this.OutputShape.Out_ShapeDragged += (IShapeDraggedMessage shapeDraggedMessage) => { this.EndPoint = shapeDraggedMessage.OutputPinCenter; }; } this.CheckStatus(); }
public static DistanceResult PointToPoint(Measurement first, Measurement second, HTuple angle, LineDirection direction) { DistanceResult result = null; var p1 = first.GetViewModel(); var p2 = second.GetViewModel(); if (p1 == null || p2 == null) return null; if (p1.Row1 != null && p1.Row1.TupleLength() > 0 && p2.Row1 != null && p2.Row1.TupleLength() > 0) { HTuple distanceMin; HOperatorSet.DistancePp(p1.Row1, p1.Col1, p2.Row1, p2.Col1, out distanceMin); result = new DistanceResult() { Distance = distanceMin, Direction = direction, Angle = angle, FirstRowBegin = p1.Row1, FirstColBegin = p1.Col1, FirstRowEnd = p2.Row1, FirstColEnd = p2.Col1, }; } return result; }