Created
June 22, 2017 17:49
-
-
Save fxzhukov/2049a86f5bd56a49e892c83bfe15b8f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Test if lines equal | |
| * @param s1 - first segment [{x, y}, {x,y}] | |
| * @param s2 - second segment [{x, y}, {x,y}] | |
| */ | |
| linesEqual(s1, s2) { | |
| let s1Eq = [(s1[0].y - s1[1].y), (s1[1].x - s1[0].x), ((s1[0].x * s1[1].y) - (s1[1].x * s1[0].y))]; | |
| let s2Eq = [(s2[0].y - s2[1].y), (s2[1].x - s2[0].x), ((s2[0].x * s2[1].y) - (s2[1].x * s2[0].y))]; | |
| let returnVal = 'joint'; | |
| for (let i = 1; i < s1Eq.length; i++) { | |
| if ( (s1Eq[i] == s2Eq[i]) || ( (i == 2) && (s1Eq[0] == 0 || s1Eq[1] ==0))) { | |
| continue; | |
| } | |
| else { | |
| if ((s1Eq[i] / s2Eq[i] != 1 ) && (s1Eq[i] / s2Eq[i] != -1 )) { | |
| returnVal = false; | |
| } | |
| } | |
| } | |
| return returnVal; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment