public bool isCrossedBy(Freeline other) { /* AB = this * CD = other * * AB = sqrt ( (Xb - Xa)² + (Yb - Ya)² ) => AB.distance * CD.distance * * AB * BC => this.segment.distance * this.segment.b.getDistanceFrom(other.segment.a); * AB * BD => this.segment.distance * this.segment.b.getDistanceFrom(other.segment.b); * * CD * DA => other.segment.distance * other.segment.b.getDistanceFrom(this.segment.a); * CD * DB => other.segment.distance * other.segment.b.getDistanceFrom(this.segment.b); * if (AB × BC) * (AB × BD) < 0 and * (CD × DA) * (CD × DB) < 0: * return True * * Debug.Log ("AB * BC = " + abbc); Debug.Log ("AB * BD = " + abbd); Debug.Log ("CD * DA = " + cdda); Debug.Log ("CD * DB = " + cddb); */ Segment bc, bd, da, db; double abbc, abbd, cdda, cddb; bc = new Segment(this.segment.b, other.segment.a); bd = new Segment(this.segment.b, other.segment.b); da = new Segment(other.segment.b, this.segment.a); db = new Segment(other.segment.b, this.segment.b); abbc = this.segment.vecto (bc); abbd = this.segment.vecto (bd); cdda = other.segment.vecto (da); cddb = other.segment.vecto (db); return (abbc * abbd < 0 && cdda * cddb < 0); }
public bool CreateNewFreeline(Intersection one, Intersection two) { Freeline newFreeline = new Freeline (one, two); if (this.freelines.Exists (x => x.Equals (newFreeline))) return (false); if (GamePreferences.INSTANCE.ThreeDouble) { foreach (Freeline freeline in BoardManager.INSTANCE.freelines) { if (!excluded.Exists(x => x.Equals(freeline)) && freeline.isCrossedBy(newFreeline)) return (true); } } this.freelines.Add (newFreeline); Debug.Log ("Freeline ajouté [" + this.freelines.Count + "]"); return false; }
public bool Equals(Freeline freeline) { return ((this.segment.a.Equals (freeline.segment.a) && this.segment.b.Equals (freeline.segment.b)) || (this.segment.a.Equals(freeline.segment.b) && this.segment.b.Equals(freeline.segment.a))); }