//Return a LineBatch contain the lines that make up a filled circle of specified colour. public static LineBatch FilledCircle(Vec2 position, int radius, Brush colour) { var lineBatch = new LineBatch(); lineBatch.SetColour(colour); lineBatch.LineThickness = 1; var increment = 360 / 45 / 4; var a = 0f; while (a < 360) { var heading = (a + increment) * (Math.PI / 180); var newLightLine = new LightLine { X1 = position.X, Y1 = position.Y, X2 = Math.Cos(heading) * radius + position.X, Y2 = Math.Sin(heading) * radius + position.Y }; lineBatch.Add(newLightLine); a += increment; } return(lineBatch); }
public void BuildLightElements() { lightElementsBuilded = true; lightPointRoot = transform.Find("LightPoints"); lightPoints = new LightPoint[lightPointRoot.childCount]; for (int i = 0; i < lightPointRoot.childCount; i++) { lightPoints[i] = lightPointRoot.GetChild(i).GetComponent <LightPoint>(); } lightLineRoot = new GameObject("LightLines").transform; lightLineRoot.SetParent(transform, false); if (invisibleLinks) { for (int i = 1; i < lightPointRoot.childCount; i++) { lightLinks.Add(LightLine.BuildLink(lightLineRoot, gameObject.name, lightPointRoot.GetChild(i - 1).GetComponent <LightPoint>(), lightPointRoot.GetChild(i).GetComponent <LightPoint>())); } } else { for (int i = 1; i < lightPointRoot.childCount; i++) { lightLinks.Add(LightLine.BuildLine(lightLineRoot, gameObject.name, lightPointRoot.GetChild(i - 1).GetComponent <LightPoint>(), lightPointRoot.GetChild(i).GetComponent <LightPoint>())); } } }
//Used externally to plot data on the graph object. public void PlotData(int index, Point point) { //Add new lineBatch if index is greater than the current list length. if (_plots.Count == index) { _plots.Add(new GraphPlot(_plots.Count)); } //Initialise new line to be added to the dataLineBatch. var line = new LightLine(); if (_plots[index].BatchList.Count == 0) { //If this is the first line in the dataLineBatch. line.X1 = (point.X - graphProperties.XStart) / graphProperties.IncrementX * graphProperties.XInterval; line.Y1 = (-point.Y + graphProperties.YStart + graphProperties.YRange) / graphProperties.IncrementY * graphProperties.YIncrement; line.X2 = (point.X - graphProperties.XStart) / graphProperties.IncrementX * graphProperties.XInterval; line.Y2 = (-point.Y + graphProperties.YStart + graphProperties.YRange) / graphProperties.IncrementY * graphProperties.YIncrement; } else { line.X1 = (point.X - graphProperties.XStart) / graphProperties.IncrementX * graphProperties.XInterval; line.Y1 = (-point.Y + graphProperties.YStart + graphProperties.YRange) / graphProperties.IncrementY * graphProperties.YIncrement; line.X2 = ((LightLine)_plots[index].BatchList[_plots[index].BatchList.Count - 1]).X1; line.Y2 = ((LightLine)_plots[index].BatchList[_plots[index].BatchList.Count - 1]).Y1; } _plots[index].Add(line); //Zoom out if the graph gets too large to display. if (line.Y2 > graphProperties.CanvasHeight || line.Y2 < 0 || line.Y1 > graphProperties.CanvasHeight || line.Y1 < 0) { Zoom(ZoomMode.ZoomOut); Translate(line.X2 - line.X1 * 2, 0); } //All dataline batches for a given graph are cleared if one of the dataline batches exceeds length of 500. foreach (var plot in _plots) { if (plot.BatchList.Count > 500) { plot.Clear(); ResetCentre(); } } //Method will terminate here if the plotting has not reached the edge of the canvas. if (!(line.X1 >= graphProperties.CanvasWidth)) { return; } //Else the canvas viewport is translated by a full canvas width. Translate(line.X2 - line.X1 * 2, 0); }
//Draws the pendulum bobs. public override void Draw(State state) { //Sets width and height to canvas height and width propeties depending on //if the canvas is initialised. var width = Canvas.ActualWidth > 0 ? Canvas.ActualWidth : Canvas.Width; var height = Canvas.ActualHeight > 0 ? Canvas.ActualHeight : Canvas.Height; //Calaculate bob position. BobPosition.X = Length * Math.Sin(state.Displacement); BobPosition.Y = Length * Math.Cos(state.Displacement); PivotPosition = new Vec2 { X = width / 2, Y = height / 2 }; Batches.Add(DrawingMethods.FilledCircle(PivotPosition, 4, Brushes.Black)); //Calculate bob position relative to the canvas coordinates. BobPosCanvas.X = PivotPosition.X + BobPosition.X * PixelsPerMeter; BobPosCanvas.Y = PivotPosition.Y + BobPosition.Y * PixelsPerMeter; //Create line objects for pendulum arm. var arm = new LightLine { X1 = PivotPosition.X, Y1 = PivotPosition.Y, X2 = BobPosCanvas.X - BobRadius * Math.Sin(state.Displacement), Y2 = BobPosCanvas.Y - BobRadius * Math.Cos(state.Displacement) }; var armLineBatch = new LineBatch { LineThickness = 2 }; armLineBatch.Add(arm); Batches.Add(armLineBatch); //Draw origin circles depending on whether interaction is taking place. Batches.Add(IsInteracting ? DrawingMethods.FilledCircle(BobPosCanvas, (int)BobRadius, Brushes.Red) : DrawingMethods.FilledCircle(BobPosCanvas, (int)BobRadius, Brushes.Blue)); //Render the batches. foreach (var batch in Batches) { batch.Render(Canvas); batch.Clear(); } Batches.Clear(); }
public void RegisterLink(RoomLink link) { links.Add(link); if (roomnet.useLightPaths) { if (lightNode == null) { BuildLightNode(); } LightLink lightLink = LightLine.BuildLine(transform, link.gameObject.name, lightNode, link.GetLightPoint(this)); linkLightLinks.Add(link, lightLink); link.lightLinks.Add(lightLink); } }
//Return a line batch that contains lines that make up a box of specifed width, height, line thickness and colour. public static LineBatch Border(double width, double height, double lineThickness, Brush colour) { var border = new LineBatch(); border.SetColour(Brushes.Black); border.LineThickness = lineThickness; border.SetColour(colour); var newLightLine = new LightLine { X1 = 0, Y1 = 0, X2 = width, Y2 = 0 }; var newLightLine2 = new LightLine { X1 = 0, Y1 = 0, X2 = 0, Y2 = height }; var newLightLine3 = new LightLine { X1 = width, Y1 = 0, X2 = width, Y2 = height }; var newLightLine4 = new LightLine { X1 = 0, Y1 = height, X2 = width, Y2 = height }; border.Add(newLightLine); border.Add(newLightLine2); border.Add(newLightLine3); border.Add(newLightLine4); return(border); }
public void PlotData(Point point) { var line = new LightLine(); if (_dataLineChunk.ChunkList.Count == 0) { line.X1 = (point.X - _xStart) / _incrementX * _xInterval; line.Y1 = (-point.Y + _yStart + _yRange) / _incrementY * _yInterval; line.X2 = (point.X - _xStart) / _incrementX * _xInterval; line.Y2 = (-point.Y + _yStart + _yRange) / _incrementY * _yInterval; } else { line.X1 = (point.X - _xStart) / _incrementX * _xInterval; line.Y1 = (-point.Y + _yStart + _yRange) / _incrementY * _yInterval; line.X2 = ((LightLine)_dataLineChunk.ChunkList[_dataLineChunk.ChunkList.Count - 1]).X1; line.Y2 = ((LightLine)_dataLineChunk.ChunkList[_dataLineChunk.ChunkList.Count - 1]).Y1; } _dataLineChunk.Add(line); if (line.Y2 > _height || line.Y2 < 0 || line.Y1 > _height || line.Y1 < 0) { Zoom(1); } if (!(line.X1 >= _width)) { return; } Translate(line.X2 - line.X1 * 2, 0); if (_dataLineChunk.ChunkList.Count > 1000) { _dataLineChunk.Clear(); } if (line.Y1 >= 0 && line.Y1 <= _height && line.Y2 >= 0 && line.Y2 <= _height) { Zoom(-1); } }
private void Awake() { if (!App.isInitialized) { isGoalDebugMode = _isGoalDebugMode; debugLightNum = _debugLightNum; GameObject app = Instantiate(appPrefab) as GameObject; app.AddComponent(typeof(App)); DontDestroyOnLoad(app); App.isInitialized = true; } moveDataArray = LoadData(); motion = FindObjectOfType <Motion>(); lightLine = FindObjectOfType <LightLine>(); opParameter = animationParameter.ParameterList; AppUtil.InitTween(); }
//Draws the background gridLightLines on the canvas. private void GridLightLines() { var lineChunk = new LineChunk(); lineChunk.SetColour(Brushes.LightGray); //Draw faint grid LightLines: for (double i = 0; i <= _xRange + _incrementX; i += _incrementX) { if (!((-_startOffSetX + i) / _incrementX * _xInterval >= 0) || !((-_startOffSetX + i) / _incrementX * _xInterval <= _width)) { continue; } var newLightLine = new LightLine { X1 = (-_startOffSetX + i) / _incrementX * _xInterval, Y1 = 0, X2 = (-_startOffSetX + i) / _incrementX * _xInterval, Y2 = _height }; lineChunk.Add(newLightLine); } for (var i = _yRange; i >= -_incrementY; i -= _incrementY) { if (!((_startOffSetY + i) / _incrementY * _yInterval >= 0) || !((_startOffSetY + i) / _incrementY * _yInterval <= _height)) { continue; } var newLightLine = new LightLine { X1 = 0, Y1 = (_startOffSetY + i) / _incrementY * _yInterval, X2 = _width, Y2 = (_startOffSetY + i) / _incrementY * _yInterval }; lineChunk.Add(newLightLine); } _chunks.Add(lineChunk); }
// Update is called once per frame void Update() { focal = 0.15f * Model.transform.localScale.x; //在拖动实现之后通过委托事件来实现,现在通过Update实现/ if (Model.activeSelf) { //Button.SetActive(true); float u = (Glass.transform.position - RF.transform.position).magnitude; // 物距 scale = focal / (u - focal); VF.transform.position = Glass.transform.position + (Glass.transform.position - RF.transform.position).normalized * u * scale; VF.transform.localScale = RF.transform.localScale * scale; if (VF.activeSelf) { HorizontalLine.GetComponent <DrawLines>().DrawHorizontalLine(); LightLine.GetComponent <DrawLines>().DrawLight(); } } else { Button.SetActive(false); } }
//Return a LineBatch contain the lines that make up a circle of a specified colour. public static LineBatch Circle(Vec2 position, int radius, Brush colour) { var lineBatch = new LineBatch(); lineBatch.SetColour(colour); int increment = 360 / 45 / 4; for (var a = 0; a < 360; a += increment) { var heading1 = a * (Math.PI / 180); var heading2 = (a + increment) * (Math.PI / 180); var newLightLine = new LightLine { X1 = Math.Cos(heading1) * radius + position.X, Y1 = Math.Sin(heading1) * radius + position.Y, X2 = Math.Cos(heading2) * radius + position.X, Y2 = Math.Sin(heading2) * radius + position.Y }; lineBatch.Add(newLightLine); } return(lineBatch); }
//Draws grid for the graph to be drawn on. private void Grid() { //Draw faint grid LightLines: for (double i = 0; i <= graphProperties.XRange + graphProperties.IncrementX; i += graphProperties.IncrementX) { if (!((-graphProperties.StartOffSetX + i) / graphProperties.IncrementX * graphProperties.XInterval >= 0) || !((-graphProperties.StartOffSetX + i) / graphProperties.IncrementX * graphProperties.XInterval <= graphProperties.CanvasWidth)) { continue; } var newLightLine = new LightLine { X1 = (-graphProperties.StartOffSetX + i) / graphProperties.IncrementX * graphProperties.XInterval, Y1 = 0, X2 = (-graphProperties.StartOffSetX + i) / graphProperties.IncrementX * graphProperties.XInterval, Y2 = graphProperties.CanvasHeight }; this.Add(newLightLine); } for (var i = graphProperties.YRange; i >= -graphProperties.IncrementY; i -= graphProperties.IncrementY) { if (!((graphProperties.StartOffSetY + i) / graphProperties.IncrementY * graphProperties.YIncrement >= 0) || !((graphProperties.StartOffSetY + i) / graphProperties.IncrementY * graphProperties.YIncrement <= graphProperties.CanvasHeight)) { continue; } var newLightLine = new LightLine { X1 = 0, Y1 = (graphProperties.StartOffSetY + i) / graphProperties.IncrementY * graphProperties.YIncrement, X2 = graphProperties.CanvasWidth, Y2 = (graphProperties.StartOffSetY + i) / graphProperties.IncrementY * graphProperties.YIncrement }; this.Add(newLightLine); } }
public void ShowLineAndVF() { VF.SetActive(true); HorizontalLine.SetActive(true); LightLine.SetActive(true); }
//Add line to BatchList. public void Add(LightLine line) { BatchList.Add(line); }
//Draws the pendulum bobs. public override void Draw(State state) { var springLength = (Length + state.Displacement) * PixelsPerMeter - ConnectorLength * 2; var coilSpan = springLength / NumberOfCoils; var multiplier = -1; //Sets width and height to canvas height and width propeties depending on //if the canvas is initialised. var width = Canvas.ActualWidth > 0 ? Canvas.ActualWidth : Canvas.Width; var height = Canvas.ActualHeight > 0 ? Canvas.ActualHeight : Canvas.Height; BobPosition.Y = Length + state.Displacement; PivotPosition = new Vec2 { X = width / 2, Y = 10 }; Batches.Add(DrawingMethods.FilledCircle(PivotPosition, 4, Brushes.Black)); //Calaculate bob position. BobPosCanvas.X = PivotPosition.X; BobPosCanvas.Y = PivotPosition.Y + BobPosition.Y * PixelsPerMeter + BobRadius; #region DrawSpring var springlineBatch = new LineBatch(); var springPivotLine = new LightLine() { X1 = PivotPosition.X, Y1 = PivotPosition.Y, X2 = PivotPosition.X, Y2 = PivotPosition.Y + ConnectorLength }; springlineBatch.Add(springPivotLine); var theta = Math.Asin(coilSpan / 2 / CoilDiameter); var x = (CoilDiameter * Math.Cos(theta) / 2); var startLine = new LightLine() { X1 = PivotPosition.X, Y1 = PivotPosition.Y + ConnectorLength, X2 = PivotPosition.X + x, Y2 = PivotPosition.Y + ConnectorLength + coilSpan / 2 }; springlineBatch.Add(startLine); var tempLine = startLine; for (int i = 0; i < (NumberOfCoils - 1) * 2; i++) { var coilLine = new LightLine() { X1 = tempLine.X2, Y1 = tempLine.Y2, X2 = tempLine.X2 + 2 * x * multiplier, Y2 = tempLine.Y2 + coilSpan / 2, }; springlineBatch.Add(coilLine); tempLine = coilLine; multiplier *= -1; } var endLine = new LightLine() { X1 = tempLine.X2, Y1 = tempLine.Y2, X2 = tempLine.X2 + x * multiplier, Y2 = tempLine.Y2 + coilSpan / 2 }; springlineBatch.Add(endLine); var springBobLine = new LightLine() { X1 = endLine.X2, Y1 = endLine.Y2, X2 = endLine.X2, Y2 = endLine.Y2 + ConnectorLength }; springlineBatch.Add(springBobLine); #endregion springlineBatch.LineThickness = 2; Batches.Add(springlineBatch); //Draw origin circles depending on whether interaction is taking place. Batches.Add(IsInteracting ? DrawingMethods.FilledCircle(BobPosCanvas, (int)BobRadius, Brushes.Red) : DrawingMethods.FilledCircle(BobPosCanvas, (int)BobRadius, Brushes.Blue)); //Render the batches. foreach (var batch in Batches) { batch.Render(Canvas); batch.Clear(); } Batches.Clear(); }
//Draws X and y axes. private void Axes() { //The faint grid is drawn first to minimize overlapping of canvas objects. var lineChunk = new LineChunk(); lineChunk.SetColour(Brushes.Black); //Draw increment LightLines and axes for each interval: //If the yStart and yEnd Values are both less than zero the X axis is drawn at the top of the canvas. for (var i = -_startOffSetX; i <= _xRange + _incrementX; i += _incrementX) { if (!(i / _incrementX * _xInterval >= 0) || !(i / _incrementX * _xInterval <= _width)) { continue; } var incrementLightLine = new LightLine { X1 = i / _incrementX * _xInterval, Y1 = _origin.Y + 4, X2 = i / _incrementX * _xInterval, Y2 = _origin.Y - 4 }; lineChunk.Add(incrementLightLine); } var axesLightLine = new LightLine { X1 = 0, Y1 = _origin.Y, X2 = _width, Y2 = _origin.Y }; lineChunk.Add(axesLightLine); //If the xStart and xEnd Values are both less than zero the y axis is drawn at the right of the canvas. for (var i = _yRange + _startOffSetY; i >= -_incrementY; i -= _incrementY) { if (!(i / _incrementY * _yInterval >= 0) || !(i / _incrementY * _yInterval <= _height)) { continue; } var incrementLightLine = new LightLine { X1 = _origin.X + 4, Y1 = i / _incrementY * _yInterval, X2 = _origin.X - 4, Y2 = i / _incrementY * _yInterval }; lineChunk.Add(incrementLightLine); } var axesLightLineY = new LightLine { X1 = _origin.X, Y1 = 0, X2 = _origin.X, Y2 = _height }; lineChunk.Add(axesLightLineY); _chunks.Add(lineChunk); //If the origin is present to be drawn on the canvas a ellipse will be drawn to mark its location. if (_xStart <= 0 && _xEnd >= 0 && _yStart <= 0 && _yEnd >= 0) { _chunks.Add(DrawingMethods.Circle(_origin, 10)); } }
//Add Axes and increment lines to the main line batch. private void Axes() { //X-Axis for (var i = -graphProperties.StartOffSetX; i <= graphProperties.XRange + graphProperties.IncrementX; i += graphProperties.IncrementX) { if (!(i / graphProperties.IncrementX * graphProperties.XInterval >= 0) || !(i / graphProperties.IncrementX * graphProperties.XInterval <= graphProperties.CanvasWidth)) { continue; } //Setup fo increment lines on the axis. var incrementLightLine = new LightLine { X1 = i / graphProperties.IncrementX * graphProperties.XInterval, Y1 = graphProperties.Origin.Y + 4, X2 = i / graphProperties.IncrementX * graphProperties.XInterval, Y2 = graphProperties.Origin.Y - 4 }; this.Add(incrementLightLine); } var axesLightLine = new LightLine { X1 = 0, Y1 = graphProperties.Origin.Y, X2 = graphProperties.CanvasWidth, Y2 = graphProperties.Origin.Y }; this.Add(axesLightLine); //Y-Axis for (var i = graphProperties.YRange + graphProperties.StartOffSetY; i >= -graphProperties.IncrementY; i -= graphProperties.IncrementY) { if (!(i / graphProperties.IncrementY * graphProperties.YIncrement >= 0) || !(i / graphProperties.IncrementY * graphProperties.YIncrement <= graphProperties.CanvasHeight)) { continue; } //Setup fo increment lines on the axis. var incrementLightLine = new LightLine { X1 = graphProperties.Origin.X + 4, Y1 = i / graphProperties.IncrementY * graphProperties.YIncrement, X2 = graphProperties.Origin.X - 4, Y2 = i / graphProperties.IncrementY * graphProperties.YIncrement }; this.Add(incrementLightLine); } var axesLightLineY = new LightLine { X1 = graphProperties.Origin.X, Y1 = 0, X2 = graphProperties.Origin.X, Y2 = graphProperties.CanvasHeight }; this.Add(axesLightLineY); //If the origin is present to be drawn on the canvas a ellipse will be drawn to mark its location. if (graphProperties.XStart <= 0 && graphProperties.XEnd >= 0 && graphProperties.YStart <= 0 && graphProperties.YEnd >= 0) { //Add origin circle to main batch list. this.Add(DrawingMethods.Circle(graphProperties.Origin, 10).Content()); } }
//Draws the pendulum bobs. public void Draw() { //Sets width and height to canvas height and width propeties depending on //if the canvas is initialised. var width = _canvas.ActualWidth > 0 ? _canvas.ActualWidth : _canvas.Width; var height = _canvas.ActualHeight > 0 ? _canvas.ActualHeight : _canvas.Height; //Calaculate bob position. _bobPosition[0].X = Length[0] * Math.Sin(CurrentState[0].Displacement); _bobPosition[0].Y = Length[0] * Math.Cos(CurrentState[0].Displacement); _bobPosition[1].X = Length[1] * Math.Sin(CurrentState[1].Displacement); _bobPosition[1].Y = Length[1] * Math.Cos(CurrentState[1].Displacement); _pivotPosition = new Vec2 { X = width / 2, Y = height / 2 }; _batches.Add(DrawingMethods.FilledCircle(_pivotPosition, 4, Brushes.Black)); //Calculate bob position relative to the canvas coordinates. _bobPositionCanvas[0].X = _pivotPosition.X + _bobPosition[0].X * PixelsPerMeter; _bobPositionCanvas[0].Y = _pivotPosition.Y + _bobPosition[0].Y * PixelsPerMeter; _bobPositionCanvas[1].X = _bobPositionCanvas[0].X + _bobPosition[1].X * PixelsPerMeter; _bobPositionCanvas[1].Y = _bobPositionCanvas[0].Y + _bobPosition[1].Y * PixelsPerMeter; //Create line objects for both pendulum arms. var arm1 = new LightLine { X1 = _pivotPosition.X, Y1 = _pivotPosition.Y, X2 = _bobPositionCanvas[0].X - BobRadius * Math.Sin(CurrentState[0].Displacement), Y2 = _bobPositionCanvas[0].Y - BobRadius * Math.Cos(CurrentState[0].Displacement) }; var arm2 = new LightLine { X1 = _bobPositionCanvas[0].X, Y1 = _bobPositionCanvas[0].Y, X2 = _bobPositionCanvas[1].X - BobRadius * Math.Sin(CurrentState[1].Displacement), Y2 = _bobPositionCanvas[1].Y - BobRadius * Math.Cos(CurrentState[1].Displacement) }; var armLineBatch = new LineBatch(); armLineBatch.LineThickness = 2; armLineBatch.Add(arm1); armLineBatch.Add(arm2); _batches.Add(armLineBatch); //Draw origin circles depending on whether interaction is taking place. _batches.Add(IsInteractingTop ? DrawingMethods.FilledCircle(_bobPositionCanvas[0], (int)BobRadius, Brushes.Red) : DrawingMethods.FilledCircle(_bobPositionCanvas[0], (int)BobRadius, Brushes.Blue)); _batches.Add(IsInteractingBottom ? DrawingMethods.FilledCircle(_bobPositionCanvas[1], (int)BobRadius, Brushes.Red) : DrawingMethods.FilledCircle(_bobPositionCanvas[1], (int)BobRadius, Brushes.Blue)); //If DrawTrails is equal to true draw pendulum trails. if (DrawTrails) { var trailLine = new LightLine { X1 = (int)_bobPositionCanvas[1].X, Y1 = (int)_bobPositionCanvas[1].Y, X2 = (int)_bobPositionCanvas[1].X, Y2 = (int)_bobPositionCanvas[1].Y }; //Clean up. if (_trailLinesQueue.IsFull()) { _trailLinesQueue.DeQueue(); } _trailLinesQueue.EnQueue(trailLine); _trail.Add(_trailLinesQueue.GetItems()); _batches.Add(_trail); } //Render the batches. foreach (var batch in _batches) { batch.Render(_canvas); batch.Clear(); } _batches.Clear(); }
public static LightLine Validate(LightLine unvalidateLine, FrameworkElement drawingCanvas) { var temporaryLine = new LightLine(); temporaryLine.Stroke = unvalidateLine.Stroke; temporaryLine.X1 = unvalidateLine.X1; temporaryLine.Y1 = unvalidateLine.Y1; temporaryLine.X2 = unvalidateLine.X2; temporaryLine.Y2 = unvalidateLine.Y2; if (drawingCanvas.ActualHeight == 0) { return(new LightLine()); } var canvasHeight = drawingCanvas.ActualHeight; var canvasWidth = drawingCanvas.ActualWidth; if (canvasHeight == 0) { canvasHeight = drawingCanvas.Height; } if (canvasWidth == 0) { canvasWidth = drawingCanvas.Width; } if (unvalidateLine.Y2 >= 0 && unvalidateLine.Y2 <= canvasHeight && unvalidateLine.Y1 >= 0 && unvalidateLine.Y1 <= canvasHeight && unvalidateLine.X1 >= 0 && unvalidateLine.X1 <= canvasWidth && unvalidateLine.X2 >= 0 && unvalidateLine.X2 <= canvasWidth) { return(temporaryLine); //If all of the line’s coordinates lie within the canvas the line is valid, hence returned. } var drawLine = true; var m = Gradient(unvalidateLine.X1, unvalidateLine.Y1, unvalidateLine.X2, unvalidateLine.Y2); var point1 = GetLineCanvasIntercept(unvalidateLine.X1, unvalidateLine.Y1, m, canvasWidth, canvasHeight); var point2 = GetLineCanvasIntercept(unvalidateLine.X2, unvalidateLine.Y2, m, canvasWidth, canvasHeight); temporaryLine.X1 = point1.X; temporaryLine.Y1 = point1.Y; temporaryLine.X2 = point2.X; temporaryLine.Y2 = point2.Y; if ((unvalidateLine.X1 > canvasWidth && unvalidateLine.Y1 >= 0 && unvalidateLine.Y1 <= canvasHeight && unvalidateLine.X2 > canvasWidth && unvalidateLine.Y2 >= 0 && unvalidateLine.Y2 <= canvasHeight) || (unvalidateLine.X1 < 0 && unvalidateLine.Y1 >= 0 && unvalidateLine.Y1 <= canvasHeight && unvalidateLine.X2 < 0 && unvalidateLine.Y2 >= 0 && unvalidateLine.Y2 <= canvasHeight) || (unvalidateLine.Y1 < 0 && unvalidateLine.X1 >= 0 && unvalidateLine.X1 <= canvasWidth && unvalidateLine.Y2 < 0 && unvalidateLine.X2 >= 0 && unvalidateLine.X2 <= canvasWidth) || (unvalidateLine.Y1 > canvasHeight && unvalidateLine.X1 >= 0 && unvalidateLine.X1 <= canvasWidth && unvalidateLine.Y2 > canvasHeight && unvalidateLine.X2 >= 0 && unvalidateLine.X2 <= canvasWidth) || unvalidateLine.X1 < 0 && unvalidateLine.X2 < 0 || unvalidateLine.Y1 < 0 && unvalidateLine.Y2 < 0 || unvalidateLine.X1 > canvasWidth && unvalidateLine.X2 > canvasWidth || unvalidateLine.Y1 > canvasHeight && unvalidateLine.Y2 > canvasHeight) { drawLine = false; } if (temporaryLine.Y2 < 0 || temporaryLine.Y2 > canvasHeight || temporaryLine.Y1 < 0 || temporaryLine.Y1 > canvasHeight || temporaryLine.X1 < 0 || temporaryLine.X1 > canvasWidth || temporaryLine.X2 < 0 || temporaryLine.X2 > canvasWidth || drawLine == false) { return(null); } return(temporaryLine); }
public void HideLineAndVF() { VF.SetActive(false); HorizontalLine.SetActive(false); LightLine.SetActive(false); }