starting LinesFactoryTest
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
from skspatial.objects import Line
|
||||
from SymptomsCausedByVaccines.MultiLineFitting.MultiLineFitter import MultiLineFitter
|
||||
|
||||
|
||||
class LinesFactory:
|
||||
|
||||
@staticmethod
|
||||
def createLines(points):
|
||||
lines = [Line.from_points(pointA, pointB) for (pointA, pointB) in LinesFactory._getPairs(points)]
|
||||
return LinesFactory._getUniqueLines(lines)
|
||||
|
||||
@staticmethod
|
||||
def _getPairs(points):
|
||||
return ((points[i], points[j]) for (i, j) in MultiLineFitter._getPairs(len(points)))
|
||||
|
||||
@staticmethod
|
||||
def _getUniqueLines(lines):
|
||||
uniqueLines = []
|
||||
for i in range(len(lines)):
|
||||
line = lines[i]
|
||||
if not LinesFactory._isLineCloseToAnyOtherLine(line, lines[i + 1:]):
|
||||
uniqueLines.append(line)
|
||||
return uniqueLines
|
||||
|
||||
@staticmethod
|
||||
def _isLineCloseToAnyOtherLine(line, otherLines):
|
||||
for otherLine in otherLines:
|
||||
if line.is_close(otherLine):
|
||||
return True
|
||||
return False
|
||||
@@ -0,0 +1,30 @@
|
||||
import unittest
|
||||
from skspatial.objects import Line
|
||||
from SymptomsCausedByVaccines.MultiLineFitting.LinesFactory import LinesFactory
|
||||
|
||||
|
||||
class LinesFactoryTest(unittest.TestCase):
|
||||
|
||||
def test_createLines(self):
|
||||
# Given
|
||||
points = [(1, 0), (2, 0), (3, 0)]
|
||||
|
||||
# When
|
||||
lines = LinesFactory.createLines(points)
|
||||
|
||||
# Then
|
||||
self.assertEqual(len(lines), 1)
|
||||
self.assertTrue(lines[0].is_close(Line(point = [0, 0], direction = [1, 0])))
|
||||
|
||||
def test_createLines2(self):
|
||||
# Given
|
||||
points = [(0, 0), (1, 0), (0, 1)]
|
||||
|
||||
# When
|
||||
lines = LinesFactory.createLines(points)
|
||||
|
||||
# Then
|
||||
self.assertEqual(len(lines), 3)
|
||||
self.assertTrue(lines[0].is_close(Line(point = [0, 0], direction = [1, 0])))
|
||||
self.assertTrue(lines[1].is_close(Line(point = [0, 0], direction = [0, 1])))
|
||||
self.assertTrue(lines[2].is_close(Line(point = [0, 1], direction = [1, -1])))
|
||||
@@ -1,5 +1,4 @@
|
||||
import numpy as np
|
||||
from skspatial.objects import Line
|
||||
|
||||
# implementation of "Robust Multiple Structures Estimation with J-linkage" adapted from https://github.com/fkluger/vp-linkage
|
||||
class MultiLineFitter:
|
||||
|
||||
Reference in New Issue
Block a user