public static bool LinesIntercept(ArrayLine line1, ArrayLine line2) { /* * Line line1L = new Line (); * Line line2L = new Line (); * * //lineScript.id = lineID; * //lineID += 1; * Point point1 = new Point (); * Point point2 = new Point (); * point1.coords = line1.point1.ToVector2 (); * point2.coords = line1.point2.ToVector2 (); * line1L.point1 = point1; * line1L.point2 = point2; * * Point point3 = new Point (); * Point point4 = new Point (); * point3.coords = line2.point1.ToVector2 (); * point4.coords = line2.point2.ToVector2 (); * line2L.point1 = point3; * line2L.point2 = point4; */ //Debug.Log (LinesIntercept (line1L, line2L)); return(LinesInterceptProcessing(line1.point1.x, line1.point1.y, line1.point2.x, line1.point2.y, line2.point1.x, line2.point1.y, line2.point2.x, line2.point2.y)); //return LinesIntercept (line1L, line2L); }
public void ReadRow() { var line = new ArrayLine <int>(_data, ArrayLine.Direction.Row, index: 1); Assert.AreEqual(6, line.Length); Assert.AreEqual(7, line[0]); Assert.AreEqual(12, line[5]); }
public void ReadColumn() { var line = new ArrayLine <int>(_data, ArrayLine.Direction.Column, index: 1); Assert.AreEqual(3, line.Length); Assert.AreEqual(2, line[0]); Assert.AreEqual(14, line[2]); }
public void RotateRow() { var line = new ArrayLine <int>(_data, ArrayLine.Direction.Row, index: 1); line.RotateValues(1); Assert.AreEqual(12, line[0]); Assert.AreEqual(11, line[5]); }
public void RotateManyColumn() { var line = new ArrayLine <int>(_data, ArrayLine.Direction.Column, index: 1); line.RotateValues(2); Assert.AreEqual(8, line[0]); Assert.AreEqual(2, line[2]); }
public List <ArrayLine> SetLinesByPoints(List <ArrayPoint> points, bool isCircle = false) { List <ArrayLine> finalLines = new List <ArrayLine> (); List <ArrayPoint> notNullPoints = points.FindAll(p => !p.isNullPoint); notNullPoints = notNullPoints.OrderBy(p => p.coord.x).ToList <ArrayPoint> (); float minimumX = notNullPoints[0].coord.x; float maximumX = notNullPoints[notNullPoints.Count - 1].coord.x; notNullPoints = notNullPoints.OrderBy(p => p.coord.y).ToList <ArrayPoint> (); float minimumY = notNullPoints[0].coord.y; float maximumY = notNullPoints[notNullPoints.Count - 1].coord.y; Vector2 centerPoint = new Vector2(minimumX + ((maximumX - minimumX) / 2), minimumY + ((maximumY - minimumY) / 2)); List <ArrayPointInfo> pointAngles = new List <ArrayPointInfo> (); foreach (ArrayPoint point in notNullPoints) { ArrayPointInfo info = new ArrayPointInfo(); info.coord = point.coord; info.pointID = point.ID; info.angle = GetPointAngle(point.coord.ToVector2(), centerPoint); pointAngles.Add(info); } pointAngles = pointAngles.OrderBy(p => p.angle).ThenBy(p => Vector2.Distance(centerPoint, p.coord.ToVector2()) * -1).ToList <ArrayPointInfo>(); for (int i = 0; i < pointAngles.Count; i++) { if (i != pointAngles.Count - 1) { ArrayLine newLine = new ArrayLine(); newLine.point1 = pointAngles [i].coord; newLine.point2 = pointAngles [i + 1].coord; newLine.point1ID = pointAngles [i].pointID; newLine.point2ID = pointAngles [i + 1].pointID; finalLines.Add(newLine); } } if (isCircle) { ArrayLine newLine = new ArrayLine(); newLine.point1 = pointAngles [0].coord; newLine.point2 = pointAngles [pointAngles.Count - 1].coord; newLine.point1ID = pointAngles [0].pointID; newLine.point2ID = pointAngles [pointAngles.Count - 1].pointID; finalLines.Add(newLine); } return(finalLines); }
public override void OnInspectorGUI() { DrawDefaultInspector(); ArrayLine myScript = (ArrayLine)target; if (GUILayout.Button("Reset")) { myScript.SpawnChildren(); myScript.Reposition(); } }
public bool LineInterceptOtherLine(ArrayLine line) { bool value = false; foreach (ArrayLine oldLine in lines) { if (GameMath.LinesIntercept(oldLine.GetLine(), line.GetLine())) { value = true; } } return(value); }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.I)) { NewLevel(); } if (Input.GetKeyDown(KeyCode.X)) { ClearScene(); ArrayLine line1 = new ArrayLine(); ArrayLine line2 = new ArrayLine(); SerializableVector2 line1Point1 = new SerializableVector2(); line1Point1.x = 1; line1Point1.y = 1; SerializableVector2 line1Point2 = new SerializableVector2(); line1Point2.x = 4; line1Point2.y = 1; line1.point1 = line1Point1; line1.point1ID = 1; line1.point2 = line1Point2; line1.point2ID = 2; /*SerializableVector2 line2Point1 = new SerializableVector2 (); * line2Point1.x = 2; * line2Point1.y = 2; * SerializableVector2 line2Point2 = new SerializableVector2 (); * line2Point2.x = 3; * line2Point2.y = 1; * line2.point1 = line2Point1; * line2.point2 = line2Point2;*/ ArrayPoint arrayPoint1 = new ArrayPoint(); arrayPoint1.coord = line1Point1; arrayPoint1.isNullPoint = false; arrayPoint1.ID = 1; ArrayPoint arrayPoint2 = new ArrayPoint(); arrayPoint2.coord = line1Point2; arrayPoint2.isNullPoint = false; arrayPoint2.ID = 2; Level newLevel = new Level(); newLevel.width = 10; newLevel.height = 20; newLevel.points.Add(arrayPoint1); newLevel.points.Add(arrayPoint2); newLevel.lines.Add(line1); //newLevel.lines.Add (line2); level = newLevel; DrawLevel(); //Debug.Log( LevelGenerator.IsValidLevel (newLevel)); SkinController.skinController.SetTheme(gameSessionInfo.currentTheme); //line1.point1 } if (Input.GetKeyDown(KeyCode.V)) { int levelPointsCount = 0; float maxPoints = 125f; float maximumNumber = 250f; float plusCoeff = 9f; float numberMin = 5f; float number = (float)lol; float numberCoeff = maximumNumber + numberMin - number; float coeff = ((plusCoeff * numberCoeff) / maximumNumber); //Debug.Log (coeff); levelPointsCount = (int)(System.Math.Round((float)((float)maxPoints * ((float)coeff + (float)number)) / (float)maximumNumber)); Debug.Log(lol.ToString() + " " + levelPointsCount); lol += 1; //Debug.Log((0.000001f * 300)/5); } }