Commit 3ea58610 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

point on line is computed properly

parent ff8452e2
......@@ -514,9 +514,9 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
return getPointOnSegment(segment, 0.5);
}
private Point getPointOnSegment(CurveSegment segment, double coef) {
double centerX = (segment.getStart().getX() + segment.getEnd().getX()) * coef;
double centerY = (segment.getStart().getY() + segment.getEnd().getY()) * coef;
Point getPointOnSegment(CurveSegment segment, double coef) {
double centerX = segment.getStart().getX() + (segment.getEnd().getX() - segment.getStart().getX()) * coef;
double centerY = segment.getStart().getY() + (segment.getEnd().getY() - segment.getStart().getY()) * coef;
Point centerPoint = new Point(getSbmlModel().getLevel(), getSbmlModel().getVersion());
centerPoint.setX(centerX);
centerPoint.setY(centerY);
......
......@@ -6,9 +6,14 @@ import static org.junit.Assert.assertTrue;
import java.io.FileNotFoundException;
import org.apache.logging.log4j.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import org.sbml.jsbml.ext.layout.CurveSegment;
import org.sbml.jsbml.ext.layout.LineSegment;
import org.sbml.jsbml.ext.layout.Point;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.InvalidInputDataExecption;
import lcsb.mapviewer.converter.model.sbml.SbmlParser;
......@@ -299,4 +304,22 @@ public class SbmlReactionParserTest extends SbmlTestFunctions {
}
}
@Test
public void testGetPointOnSegment() throws Exception {
try {
SbmlReactionParser parser = new SbmlReactionParser(new org.sbml.jsbml.Model(), null, null, null);
CurveSegment segment = new LineSegment(3, 2);
segment.setStart(new Point(12, 2, 0, 3, 2));
segment.setEnd(new Point(2, 8, 0, 3, 2));
Point p = parser.getPointOnSegment(segment, 0.4);
assertEquals(8, p.getX(), Configuration.EPSILON);
assertEquals(4.4, p.getY(), Configuration.EPSILON);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
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