@Override public int hashCode() { int hash = 17; hash = hash * 23 + _major.hashCode(); hash = hash * 23 + _minor.hashCode(); return hash; }
@Test public final void testNewLineSegment() { LineSegment actualSeg = this.testInstance.newLineSegment(NEW_SEG_LEN); assertEquals("Expected length", NEW_SEG_LEN, actualSeg.length(), 0.001); assertEquals( "Expected lineseg origin X", EXPECTED_NEW_LINE_SEG.getOrigin().getX(), actualSeg.getOrigin().getX(), 0.001); assertEquals( "Expected lineseg origin Y", EXPECTED_NEW_LINE_SEG.getOrigin().getY(), actualSeg.getOrigin().getY(), 0.001); assertEquals( "Expected lineseg term X", EXPECTED_NEW_LINE_SEG.getTerminus().getX(), actualSeg.getTerminus().getX(), 0.001); assertEquals( "Expected lineseg term Y", EXPECTED_NEW_LINE_SEG.getTerminus().getY(), actualSeg.getTerminus().getY(), 0.001); }
public void testProjectionFactor() { // zero-length line LineSegment seg = new LineSegment(10, 0, 10, 0); assertTrue(Double.isNaN(seg.projectionFactor(new Coordinate(11, 0)))); LineSegment seg2 = new LineSegment(10, 0, 20, 0); assertTrue(seg2.projectionFactor(new Coordinate(11, 0)) == 0.1); }
public static void main(String args[]) { Scanner s = new Scanner(System.in); Point x = new Point(); Triangle t = new Triangle(); LineSegment l = new LineSegment(); /*System.out.println("Enter Tester Point Values:"); x.setFromUser(); System.out.println("Enter Tester Triangle Values:"); t.setFromUser(); System.out.println("Enter Tester Line Values:"); l.setFromUser(); */ boolean exit = false; while (!exit) { System.out.println("Check for point or line is in a triangle or want to exit (1/2/3)"); int choice = s.nextInt(); if (choice == 1) { x.setFromUser(); System.out.println("Check if is inside line or triangle or exit(1/2/3)"); int secondchoice = s.nextInt(); if (secondchoice == 1) { l.setFromUser(); System.out.println(l.isInside(x)); } else if (secondchoice == 2) { t.setFromUser(); System.out.println(t.isInside(x)); } else if (secondchoice == 3) { exit = true; } } else if (choice == 2) { l.setFromUser(); System.out.println("Check if is inside triangle or exit(1/2)"); int secondchoice = s.nextInt(); if (secondchoice == 1) { t.setFromUser(); System.out.println(t.isInside(x)); } else if (secondchoice == 2) { exit = true; } } else if (choice == 3) { exit = true; } } }
void checkOffset( double x0, double y0, double x1, double y1, double segFrac, double offset, double expectedX, double expectedY) { LineSegment seg = new LineSegment(x0, y0, x1, y1); Coordinate p = seg.pointAlongOffset(segFrac, offset); assertTrue(equalsTolerance(new Coordinate(expectedX, expectedY), p, 0.000001)); }
@Test public void testLineSegments() { PointSequenceBuilder builder = new FixedSizePointSequenceBuilder(3, DimensionalFlag.XYZM); builder.add(new double[] {1, 1, 1, 1}); builder.add(new double[] {2, 2, 2, 2}); builder.add(new double[] {3, 3, 3, 3}); PointSequence sequence = builder.toPointSequence(); int cnt = 0; double startX = 1.0d; for (LineSegment ls : new LineSegments(sequence)) { assertEquals(startX, ls.getStartPoint().getX(), Math.ulp(1.0d)); startX = ls.getEndPoint().getX(); cnt++; } assertEquals(2, cnt); }
private void paintLines(Graphics2D g) { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint( RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); for (LineSegment l : turtle.getTrail()) { if (l != null) { g.setColor(l.getColor()); g.setStroke(new BasicStroke(l.getWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); g.draw(new Line2D.Double(l.getStart().x, l.getStart().y, l.getEnd().x, l.getEnd().y)); } } }
package model.physicsMIT;
public static void main(String args[]) { // create the document SBMLDocument document = new SBMLDocument(2, 1); // ensure the layout api is enabled document.enablePackage(LayoutExtension.getXmlnsL2(), "layout", true); // create the Model Model model = document.createModel("TestModel"); // create the Compartment Compartment compartment = model.createCompartment(); compartment.setId("Compartment_1"); // create the Species Species species1 = model.createSpecies(); species1.setId("Species_1"); species1.setCompartment(compartment.getId()); Species species2 = model.createSpecies(); species2.setId("Species_2"); species2.setCompartment(compartment.getId()); // create the Reactions Reaction reaction1 = model.createReaction(); reaction1.setId("Reaction_1"); SpeciesReference reference1 = reaction1.createReactant(); reference1.setSpecies(species1.getId()); reference1.setId("SpeciesReference_1"); reaction1.setReversible(false); SpeciesReference reference2 = reaction1.createProduct(); reference2.setSpecies(species2.getId()); reference2.setId("SpeciesReference_2"); Reaction reaction2 = model.createReaction(); reaction2.setId("Reaction_2"); reaction2.setReversible(false); SpeciesReference reference3 = reaction2.createReactant(); reference3.setSpecies(species2.getId()); reference3.setId("SpeciesReference_3"); SpeciesReference reference4 = reaction2.createProduct(); reference4.setSpecies(species1.getId()); reference4.setId("SpeciesReference_4"); // create the Layout LayoutModelPlugin mplugin = (LayoutModelPlugin) (model.getPlugin("layout")); Layout layout = mplugin.createLayout(); layout.setId("Layout_1"); layout.setDimensions(createDimensions(400, 220)); // create the CompartmentGlyph CompartmentGlyph compartmentGlyph = layout.createCompartmentGlyph(); compartmentGlyph.setId("CompartmentGlyph_1"); compartmentGlyph.setCompartmentId(compartment.getId()); compartmentGlyph.setBoundingBox(createBoundingBox("bb1", 5, 5, 390, 210)); // create the SpeciesGlyphs SpeciesGlyph speciesGlyph1 = layout.createSpeciesGlyph(); speciesGlyph1.setId("SpeciesGlyph_1"); speciesGlyph1.setSpeciesId(species1.getId()); speciesGlyph1.setBoundingBox(createBoundingBox("bb2", 80, 26, 240, 24)); TextGlyph textGlyph1 = layout.createTextGlyph(); textGlyph1.setId("TextGlyph_01"); textGlyph1.setBoundingBox(createBoundingBox("bbA", 92, 26, 228, 24)); textGlyph1.setOriginOfTextId(speciesGlyph1.getId()); textGlyph1.setGraphicalObjectId(speciesGlyph1.getId()); SpeciesGlyph speciesGlyph2 = layout.createSpeciesGlyph(); speciesGlyph2.setId("SpeciesGlyph_2"); speciesGlyph2.setSpeciesId(species2.getId()); speciesGlyph2.setBoundingBox(createBoundingBox("bb3", 80, 170, 240, 24)); TextGlyph textGlyph2 = layout.createTextGlyph(); textGlyph2.setId("TextGlyph_02"); textGlyph2.setBoundingBox(createBoundingBox("bbB", 92, 170, 228, 24)); textGlyph2.setOriginOfTextId(speciesGlyph2.getId()); textGlyph2.setGraphicalObjectId(speciesGlyph2.getId()); // create the ReactionGlyphs ReactionGlyph reactionGlyph1 = layout.createReactionGlyph(); reactionGlyph1.setId("ReactionGlyph_1"); reactionGlyph1.setReactionId(reaction1.getId()); Curve reactionCurve1 = reactionGlyph1.getCurve(); LineSegment ls = reactionCurve1.createLineSegment(); ls.setStart(createPoint(165, 105)); ls.setEnd(createPoint(165, 115)); ReactionGlyph reactionGlyph2 = layout.createReactionGlyph(); reactionGlyph2.setId("ReactionGlyph_1"); reactionGlyph2.setReactionId(reaction2.getId()); Curve reactionCurve2 = reactionGlyph2.getCurve(); ls = reactionCurve2.createLineSegment(); ls.setStart(createPoint(235, 105)); ls.setEnd(createPoint(235, 115)); // add the SpeciesReferenceGlyphs SpeciesReferenceGlyph speciesReferenceGlyph1 = reactionGlyph1.createSpeciesReferenceGlyph(); speciesReferenceGlyph1.setId("SpeciesReferenceGlyph_1"); speciesReferenceGlyph1.setSpeciesGlyphId(speciesGlyph1.getId()); speciesReferenceGlyph1.setSpeciesReferenceId(reference1.getId()); speciesReferenceGlyph1.setRole(libsbmlConstants.SPECIES_ROLE_SUBSTRATE); Curve speciesReferenceCurve1 = speciesReferenceGlyph1.getCurve(); CubicBezier cb = speciesReferenceCurve1.createCubicBezier(); cb.setStart(createPoint(165.0, 105.0)); cb.setBasePoint1(createPoint(165.0, 90.0)); cb.setBasePoint2(createPoint(165.0, 90.0)); cb.setEnd(createPoint(195.0, 60.0)); SpeciesReferenceGlyph speciesReferenceGlyph2 = reactionGlyph1.createSpeciesReferenceGlyph(); speciesReferenceGlyph2.setId("SpeciesReferenceGlyph_2"); speciesReferenceGlyph2.setSpeciesGlyphId(speciesGlyph2.getId()); speciesReferenceGlyph2.setSpeciesReferenceId(reference2.getId()); speciesReferenceGlyph2.setRole(libsbmlConstants.SPECIES_ROLE_PRODUCT); Curve speciesReferenceCurve2 = speciesReferenceGlyph2.getCurve(); cb = speciesReferenceCurve2.createCubicBezier(); cb.setStart(createPoint(165.0, 115.0)); cb.setBasePoint1(createPoint(165.0, 130.0)); cb.setBasePoint2(createPoint(165.0, 130.0)); cb.setEnd(createPoint(195.0, 160.0)); SpeciesReferenceGlyph speciesReferenceGlyph3 = reactionGlyph2.createSpeciesReferenceGlyph(); speciesReferenceGlyph3.setId("SpeciesReferenceGlyph_3"); speciesReferenceGlyph3.setSpeciesGlyphId(speciesGlyph2.getId()); speciesReferenceGlyph3.setSpeciesReferenceId(reference3.getId()); speciesReferenceGlyph3.setRole(libsbmlConstants.SPECIES_ROLE_SUBSTRATE); Curve speciesReferenceCurve3 = speciesReferenceGlyph3.getCurve(); cb = speciesReferenceCurve3.createCubicBezier(); cb.setStart(createPoint(235.0, 115.0)); cb.setBasePoint1(createPoint(235.0, 130.0)); cb.setBasePoint2(createPoint(235.0, 130.0)); cb.setEnd(createPoint(205.0, 160.0)); SpeciesReferenceGlyph speciesReferenceGlyph4 = reactionGlyph2.createSpeciesReferenceGlyph(); speciesReferenceGlyph4.setId("SpeciesReferenceGlyph_4"); speciesReferenceGlyph4.setSpeciesGlyphId(speciesGlyph1.getId()); speciesReferenceGlyph4.setSpeciesReferenceId(reference4.getId()); speciesReferenceGlyph4.setRole(libsbmlConstants.SPECIES_ROLE_PRODUCT); Curve speciesReferenceCurve4 = speciesReferenceGlyph4.getCurve(); cb = speciesReferenceCurve4.createCubicBezier(); cb.setStart(createPoint(235.0, 105.0)); cb.setBasePoint1(createPoint(235.0, 90.0)); cb.setBasePoint2(createPoint(235.0, 90.0)); cb.setEnd(createPoint(205.0, 60.0)); libsbml.writeSBML(document, "TestModel1-java.xml"); System.gc(); }
void checkOrientationIndex( LineSegment seg, double s0x, double s0y, double s1x, double s1y, int expectedOrient) { LineSegment seg2 = new LineSegment(s0x, s0y, s1x, s1y); int orient = seg.orientationIndex(seg2); assertTrue(orient == expectedOrient); }
void checkOrientationIndex(LineSegment seg, double px, double py, int expectedOrient) { Coordinate p = new Coordinate(px, py); int orient = seg.orientationIndex(p); assertTrue(orient == expectedOrient); }
public void getMajorStartCoordinates(LineSegment _major) { System.out.printf("MajorStart: %d, %d", _major.get_start().get_x(), _major.get_start().get_y()); System.out.println(); }
public void getMinorEndPointY(LineSegment _minor) { System.out.printf("MinorEnd: %d, %d", _minor.get_end().get_x(), _minor.get_end().get_y()); System.out.println(); }
public void getMajorEndPointCoordinates(LineSegment _major) { System.out.printf("MajorEnd: %d, %d", _major.get_end().get_x(), _major.get_end().get_y()); System.out.println(); }
public static void main(String[] args) { // read the N points from a file args = new String[1]; args[0] = "test/rs1423.txt"; In in = new In(args[0]); int N = in.readInt(); Point[] points = new Point[N]; for (int i = 0; i < N; i++) { int x = in.readInt(); int y = in.readInt(); points[i] = new Point(x, y); } // draw the points StdDraw.show(0); StdDraw.setXscale(0, 32768); StdDraw.setYscale(0, 32768); for (Point p : points) { p.draw(); } StdDraw.show(); // print and draw the line segments FastCollinearPoints collinear = new FastCollinearPoints(points); for (LineSegment segment : collinear.segments()) { StdOut.println(segment); segment.draw(); } }
public static void main(String[] args) { // read the n points from a file In in = new In(args[0]); int n = in.readInt(); Point[] points = new Point[n]; for (int i = 0; i < n; i++) { int x = in.readInt(); int y = in.readInt(); points[i] = new Point(x, y); } // draw the points StdDraw.enableDoubleBuffering(); StdDraw.setXscale(0, 32768); StdDraw.setYscale(0, 32768); for (Point p : points) { p.draw(); } StdDraw.show(); // print and draw the line segments FastCollinearPoints collinear = new FastCollinearPoints(points); for (LineSegment segment : collinear.segments()) { StdOut.println(segment); segment.draw(); } StdDraw.show(); }
public static void main(String[] args) { String input = "C:/Users/gkoontz/workspace/algoAssignments/src/collinear/equidistant.txt"; // read the N points from a file // In in = new In(args[0]); In in = new In(input); int N = in.readInt(); Point[] points = new Point[N]; for (int i = 0; i < N; i++) { int x = in.readInt(); int y = in.readInt(); points[i] = new Point(x, y); } // draw the points StdDraw.show(0); StdDraw.setXscale(0, 32768); StdDraw.setYscale(0, 32768); for (Point p : points) { p.draw(); } StdDraw.show(); // print and draw the line segments // BruteCollinearPoints collinear = new BruteCollinearPoints(points); FastCollinearPoints collinear = new FastCollinearPoints(points); for (LineSegment segment : collinear.segments()) { StdOut.println(segment); segment.draw(); } }