Commit 248ae960 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

search by coordinates resolves ties with z-index

parent 5cc7ecf1
Pipeline #10173 passed with stage
in 9 minutes and 15 seconds
......@@ -492,11 +492,6 @@ public class SearchService implements ISearchService {
*/
private double distance;
/**
* Size of the object.
*/
private double size;
/**
* Constructor for reaction objects.
*
......@@ -508,7 +503,6 @@ public class SearchService implements ISearchService {
DistanceToObject(Reaction reaction, Point2D point) {
reference = reaction;
distance = reaction.getDistanceFromPoint(point);
size = 0;
}
/**
......@@ -522,8 +516,6 @@ public class SearchService implements ISearchService {
DistanceToObject(Element alias, Point2D point) {
reference = alias;
distance = alias.getDistanceFromPoint(point);
size = alias.getSize();
}
@Override
......@@ -533,9 +525,9 @@ public class SearchService implements ISearchService {
} else if (arg0.getDistance() > getDistance()) {
return -1;
} else {
if (arg0.getSize() < getSize()) {
if (arg0.getReference().getZ() > getReference().getZ()) {
return 1;
} else if (arg0.getSize() > getSize()) {
} else if (arg0.getReference().getZ() < getReference().getZ()) {
return -1;
} else {
return 0;
......@@ -559,13 +551,6 @@ public class SearchService implements ISearchService {
return distance;
}
/**
* @return the size
* @see #size
*/
public double getSize() {
return size;
}
}
/**
......
......@@ -327,36 +327,26 @@ public class SearchServiceTest extends ServiceTestFunctions {
}
@Test
public void testSearchClosest2() throws Exception {
public void testSearchClosestByZIndex() throws Exception {
try {
Model model = new ModelFullIndexed(null);
GenericProtein protein1 = createProtein();
protein1.setZ(0);
model.addElement(protein1);
GenericProtein protein2 = new GenericProtein("s2");
protein2.setWidth(10);
protein2.setHeight(10);
protein2.setX(5);
protein2.setY(5);
GenericProtein protein2 = createProtein();
protein2.setZ(1);
model.addElement(protein2);
GenericProtein protein3 = new GenericProtein("s3");
protein3.setWidth(30);
protein3.setHeight(30);
protein3.setX(0);
protein3.setY(0);
GenericProtein protein3 = createProtein();
protein3.setZ(-1);
model.addElement(protein3);
List<BioEntity> elements = searchService.getClosestElements(model, new Point2D.Double(10, 10), 5, false,
List<BioEntity> elements = searchService.getClosestElements(model, protein2.getCenter(), 5, false,
new ArrayList<>());
assertNotNull(elements);
assertEquals(3, elements.size());
BioEntity element0 = elements.get(0);
assertEquals("s2", element0.getName());
BioEntity element1 = elements.get(1);
assertEquals(protein1.getName(), element1.getName());
BioEntity element2 = elements.get(2);
assertEquals("s3", element2.getName());
assertEquals(protein2, elements.get(0));
assertEquals(protein1, elements.get(1));
assertEquals(protein3, elements.get(2));
} catch (Exception e) {
e.printStackTrace();
......@@ -370,6 +360,7 @@ public class SearchServiceTest extends ServiceTestFunctions {
protein1.setHeight(20);
protein1.setX(5);
protein1.setY(5);
protein1.setZ(0);
return protein1;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment