Package net.sf.latexdraw.glib.models.interfaces.shape

Examples of net.sf.latexdraw.glib.models.interfaces.shape.IBezierCurve


  }


  @Test
  public void test6Coordinates() throws ParseException {
    IBezierCurve bc =  (IBezierCurve)parser.parsePSTCode("\\"+getCommandName()+"(1,2)(3,4)(5,6)(7,8)(9,10)(11,12)").get().getShapeAt(0); //$NON-NLS-1$ //$NON-NLS-2$
    assertEquals(3, bc.getNbPoints());
    assertEquals(0., bc.getPtAt(0).getX(), 0.0001);
    assertEquals(0., bc.getPtAt(0).getY(), 0.0001);
    assertEquals(5.*IShape.PPC, bc.getPtAt(1).getX(), 0.0001);
    assertEquals(-6.*IShape.PPC, bc.getPtAt(1).getY(), 0.0001);
    assertEquals(11.*IShape.PPC, bc.getPtAt(2).getX(), 0.0001);
    assertEquals(-12.*IShape.PPC, bc.getPtAt(2).getY(), 0.0001);
    assertEquals(-1.*IShape.PPC, bc.getSecondCtrlPtAt(0).getX(), 0.0001);
    assertEquals(2.*IShape.PPC, bc.getSecondCtrlPtAt(0).getY(), 0.0001);
    assertEquals(7.*IShape.PPC, bc.getSecondCtrlPtAt(1).getX(), 0.0001);
    assertEquals(-8.*IShape.PPC, bc.getSecondCtrlPtAt(1).getY(), 0.0001);
    assertEquals(3.*IShape.PPC, bc.getFirstCtrlPtAt(1).getX(), 0.0001);
    assertEquals(-4.*IShape.PPC, bc.getFirstCtrlPtAt(1).getY(), 0.0001);
    assertEquals(9.*IShape.PPC, bc.getFirstCtrlPtAt(2).getX(), 0.0001);
    assertEquals(-10.*IShape.PPC, bc.getFirstCtrlPtAt(2).getY(), 0.0001);
    assertTrue(PSTParser.errorLogs().isEmpty());
  }
View Full Code Here


  }


  @Test
  public void test7Coordinates() throws ParseException {
    IBezierCurve bc =  (IBezierCurve)parser.parsePSTCode("\\"+getCommandName()+"(5,10)(1,2)(3,4)(5,6)(7,8)(9,10)(11,12)").get().getShapeAt(0); //$NON-NLS-1$ //$NON-NLS-2$
    assertEquals(3, bc.getNbPoints());
    assertEquals(5.*IShape.PPC, bc.getPtAt(0).getX(), 0.0001);
    assertEquals(-10.*IShape.PPC, bc.getPtAt(0).getY(), 0.0001);
    assertEquals(5.*IShape.PPC, bc.getPtAt(1).getX(), 0.0001);
    assertEquals(-6.*IShape.PPC, bc.getPtAt(1).getY(), 0.0001);
    assertEquals(11.*IShape.PPC, bc.getPtAt(2).getX(), 0.0001);
    assertEquals(-12.*IShape.PPC, bc.getPtAt(2).getY(), 0.0001);
    assertEquals(9.*IShape.PPC, bc.getSecondCtrlPtAt(0).getX(), 0.0001);
    assertEquals(-18.*IShape.PPC, bc.getSecondCtrlPtAt(0).getY(), 0.0001);
    assertEquals(7.*IShape.PPC, bc.getSecondCtrlPtAt(1).getX(), 0.0001);
    assertEquals(-8.*IShape.PPC, bc.getSecondCtrlPtAt(1).getY(), 0.0001);
    assertEquals(3.*IShape.PPC, bc.getFirstCtrlPtAt(1).getX(), 0.0001);
    assertEquals(-4.*IShape.PPC, bc.getFirstCtrlPtAt(1).getY(), 0.0001);
    assertEquals(9.*IShape.PPC, bc.getFirstCtrlPtAt(2).getX(), 0.0001);
    assertEquals(-10.*IShape.PPC, bc.getFirstCtrlPtAt(2).getY(), 0.0001);
    assertTrue(PSTParser.errorLogs().isEmpty());
  }
View Full Code Here

  }


  @Test
  public void test3Coordinates() throws ParseException {
    IBezierCurve bc =  (IBezierCurve)parser.parsePSTCode("\\"+getCommandName()+"(1,2)(3,4)(5,6)").get().getShapeAt(0); //$NON-NLS-1$ //$NON-NLS-2$
    assertEquals(2, bc.getNbPoints());
    assertEquals(0., bc.getPtAt(0).getX(), 0.0001);
    assertEquals(0., bc.getPtAt(0).getY(), 0.0001);
    assertEquals(5.*IShape.PPC, bc.getPtAt(1).getX(), 0.0001);
    assertEquals(-6.*IShape.PPC, bc.getPtAt(1).getY(), 0.0001);
    assertEquals(-1.*IShape.PPC, bc.getSecondCtrlPtAt(0).getX(), 0.0001);
    assertEquals(2.*IShape.PPC, bc.getSecondCtrlPtAt(0).getY(), 0.0001);
    assertEquals(3.*IShape.PPC, bc.getFirstCtrlPtAt(1).getX(), 0.0001);
    assertEquals(-4.*IShape.PPC, bc.getFirstCtrlPtAt(1).getY(), 0.0001);
    assertTrue(PSTParser.errorLogs().isEmpty());
  }
View Full Code Here



  @Test
  public void test4Coordinates() throws ParseException {
    IBezierCurve bc =  (IBezierCurve)parser.parsePSTCode("\\"+getCommandName()+"(5,10)(1,2)(3,4)(5,6)").get().getShapeAt(0); //$NON-NLS-1$ //$NON-NLS-2$
    assertEquals(2, bc.getNbPoints());
    assertEquals(5.*IShape.PPC, bc.getPtAt(0).getX(), 0.0001);
    assertEquals(-10.*IShape.PPC, bc.getPtAt(0).getY(), 0.0001);
    assertEquals(5.*IShape.PPC, bc.getPtAt(1).getX(), 0.0001);
    assertEquals(-6.*IShape.PPC, bc.getPtAt(1).getY(), 0.0001);
    assertEquals(9.*IShape.PPC, bc.getSecondCtrlPtAt(0).getX(), 0.0001);
    assertEquals(-18.*IShape.PPC, bc.getSecondCtrlPtAt(0).getY(), 0.0001);
    assertEquals(3.*IShape.PPC, bc.getFirstCtrlPtAt(1).getX(), 0.0001);
    assertEquals(-4.*IShape.PPC, bc.getFirstCtrlPtAt(1).getY(), 0.0001);
    assertTrue(PSTParser.errorLogs().isEmpty());
  }
View Full Code Here

  private void updateCurve(final double posX, final double posY, final double minX, final double maxX, final double step) {
    // The algorithm follows this definition:
    //https://stackoverflow.com/questions/15864441/how-to-make-a-line-curve-through-points
    final double scale = 0.33;
    final IBezierCurve bc = ShapeFactory.createBezierCurve();
    if(curveView!=null) curveView.flush();
    curveView = new LBezierCurveView(bc);
    fillPoints(bc, posX, posY, minX, maxX, step);
    if(shape.getPlotStyle()==IPlotProp.PlotStyle.CCURVE)
      bc.setIsClosed(true);
    else bc.setIsClosed(false);
    bc.copy(shape);
    int i=0;
    final int last = bc.getPoints().size()-1;

    for(IPoint pt : bc.getPoints()) {
      final IPoint p1 = pt;
      if(i==0) {
        final IPoint p2 = bc.getPtAt(i+1);
        final IPoint tangent = p2.substract(p1);
        final IPoint q1 =  p1.add(tangent.zoom(scale));
        bc.setXFirstCtrlPt(q1.getX(), i);
        bc.setYFirstCtrlPt(q1.getY(), i);
      }else if(i==last) {
        final IPoint p0 = bc.getPtAt(i-1);
        final IPoint tangent = p1.substract(p0);
        final IPoint q0 =  p1.substract(tangent.zoom(scale));
        bc.setXFirstCtrlPt(q0.getX(), i);
        bc.setYFirstCtrlPt(q0.getY(), i);
      }else {
        final IPoint p0 = bc.getPtAt(i-1);
        final IPoint p2 = bc.getPtAt(i+1);
        final IPoint tangent = p2.substract(p0).normalise();
        final IPoint q0 = p1.substract(tangent.zoom(scale*p1.substract(p0).magnitude()));
//        val q1 = p1.substract(tangent.zoom(scale*p2.substract(p1).magnitude))
        bc.setXFirstCtrlPt(q0.getX(), i);
        bc.setYFirstCtrlPt(q0.getY(), i);
//        shape.setXSecondCtrlPt(q1.getX, i)
//        shape.setYSecondCtrlPt(q1.getY, i)
      }
      i++;
    }
    bc.updateSecondControlPoints();
    curveView.update();
  }
View Full Code Here

TOP

Related Classes of net.sf.latexdraw.glib.models.interfaces.shape.IBezierCurve

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.