Пример #1
0
  public static Polygon createArrow() {
    Polygon polygon =
        new Polygon(new double[] {7.5, 0, 15, 15, 10, 15, 10, 30, 5, 30, 5, 15, 0, 15});
    polygon.setFill(Color.web("#ff0900"));

    return polygon;
  }
Пример #2
0
  public HomeButton() {
    super();
    final Polygon homePoly = new Polygon(0, 0, 0, 20, 20, 20, 30, 10, 20, 0);
    homePoly.getStyleClass().add("buttonBkg");
    final Polygon homeImage =
        new Polygon(6, 0, 0, 4, 3, 4, 3, 8, 9, 8, 9, 4, 12, 4, 11, 3, 11, 0, 9, 0, 9, 2);
    homeImage.getStyleClass().add("buttonPic");
    homeImage.setStyle("-fx-translate-x: -3;");
    getChildren().addAll(homePoly, homeImage);

    setOnMouseEntered(
        new EventHandler<MouseEvent>() {
          public void handle(MouseEvent arg0) {
            homePoly.getStyleClass().clear();
            homePoly.getStyleClass().add("buttonBkgHighlight");
            homeImage.getStyleClass().clear();
            homeImage.getStyleClass().add("buttonPicHighlight");
          }
        });

    setOnMouseExited(
        new EventHandler<MouseEvent>() {
          public void handle(MouseEvent arg0) {
            homePoly.getStyleClass().clear();
            homePoly.getStyleClass().add("buttonBkg");
            homeImage.getStyleClass().clear();
            homeImage.getStyleClass().add("buttonPic");
          }
        });
  }
Пример #3
0
  // REMOVE ME
  public static Node createIconContent() {
    final Rectangle r1 = new Rectangle(50, 50, 14, 14);
    r1.setArcHeight(4);
    r1.setArcWidth(4);
    r1.setFill(Color.web("#ed4b00"));

    Polygon polygon = createArrow();
    polygon.setLayoutX(68);
    polygon.setLayoutY(25);
    polygon.setRotate(45);

    Rectangle r3 = new Rectangle(25, 25, 64, 64);
    r3.setArcHeight(15);
    r3.setArcWidth(15);
    r3.setFill(Color.web("#f49b00"));
    javafx.scene.Group g = new javafx.scene.Group(r3, r1, polygon);
    return new javafx.scene.Group(g);
  }
Пример #4
0
  public ScaleSample() {
    super(180, 180);
    // simple rectangle
    Rectangle rect1 = new Rectangle(0, 25, 25, 25);
    rect1.setArcHeight(15);
    rect1.setArcWidth(15);
    rect1.setFill(Color.WHITE);
    rect1.setStroke(Color.DODGERBLUE);
    rect1.setStrokeWidth(3);

    Polygon arrow = createArrow();
    arrow.setLayoutX(46);
    arrow.setLayoutY(22);
    arrow.setRotate(90);

    // simple rectangle with scale 2 in X axis and 0.5 in Y
    Rectangle rect2 = new Rectangle(95, 25, 25, 25);
    rect2.setArcHeight(15);
    rect2.setArcWidth(15);
    rect2.setFill(Color.WHITE);
    rect2.setStroke(Color.DODGERBLUE);
    rect2.setStrokeWidth(3);
    rect2.setScaleX(2);
    rect2.setScaleY(0.5);
    // rectangle with adjustable scale
    Rectangle rect3 = new Rectangle(40, 130, 25, 25);
    rect3.setArcHeight(15);
    rect3.setArcWidth(15);
    rect3.setFill(Color.WHITE);
    rect3.setStroke(Color.DODGERBLUE);
    rect3.setStrokeWidth(3);
    rect3.setScaleX(6);
    rect3.setScaleY(0.5);
    rect3.setTranslateX(rect3.getTranslateX() + 30);
    // getChildren().addAll(rect1, rect2, rect3);
    getChildren().addAll(rect1, arrow, rect2, rect3);

    // REMOVE ME
    setControls(
        new SimplePropertySheet.PropDesc("Scale X", rect3.scaleXProperty(), 0.1d, 16d),
        new SimplePropertySheet.PropDesc("Scale Y", rect3.scaleYProperty(), 0.1d, 4d));
    // END REMOVE ME
  }
Пример #5
0
  @Override
  protected void initialize() {
    super.initialize();

    // Points
    EList<Point> points = polygon.getPoints();
    ArrayList<Double> list = new ArrayList<>(points.size());
    for (Point point : points) {
      list.add(new Double(point.getX()));
      list.add(new Double(point.getY()));
    }
    fxPolygon.getPoints().addAll(list);
  }
Пример #6
0
  @Override
  public void start(Stage stage) throws Exception {
    Point[] sample =
        new Point[] {
          new Point(20, 10), new Point(50, 50),
          new Point(10, 20), new Point(100, 30),
          new Point(100, 200), new Point(30, 30),
        };

    ArrayList<Point> result = convexHull(sample);
    System.out.println("Left with: " + result.toString());

    // for animated spawning of dots
    Circle[] sampleDots = new Circle[sample.length];
    for (int i = 0; i < sampleDots.length; i++) {
      sampleDots[i] = new Circle(sample[i].x, sample[i].y, 3);
      sampleDots[i].setFill(Color.RED);
      sampleDots[i].opacityProperty().set(0);
      if (result.contains(sample[i])) sampleDots[i].setFill(Color.DARKCYAN);
      bp.getChildren().add(sampleDots[i]);
      sampleDots[i].toFront();
    }

    // polygon of result
    Polygon p = new Polygon();
    p.setFill(Color.TRANSPARENT);
    p.setStroke(Color.BLACK);
    p.setStrokeWidth(3);
    for (Point pt : result) {
      p.getPoints().addAll(Double.valueOf(pt.x), Double.valueOf(pt.y));
    }
    bp.getChildren().add(p);

    // scene & stage related
    Scene scene = new Scene(bp, 250, 250);
    stage.setScene(scene);
    stage.setResizable(false);
    stage.setTitle("Sample Convex Hull");
    stage.show();

    // animated spawning of dots
    p.toBack();
    Timeline tl = new Timeline();
    for (int i = 0; i < sampleDots.length; i++) {
      tl.getKeyFrames()
          .add(
              new KeyFrame(
                  Duration.seconds(1), new KeyValue(sampleDots[i].opacityProperty(), 1.0)));
    }
    tl.setCycleCount(1);
    tl.play();
  }
Пример #7
0
  @Override
  public void start(Stage stage) {

    /*
    The following snippet of code creates two triangles. Both use MITER line join by
    default. The first triangle uses 2.0 as the miter limit. The second triangle uses the default miter limit, which
    is 10.0. The stroke width is 10px. The first triangle tries to join the corners by extending two lines up to 20px,
    which is computed by multiplying the 10px stroke width by the miter limit of 2.0. The corners cannot be
    joined using the MITER join within 20px, so a BEVEL join is used.
    */
    SVGPath t1 = new SVGPath();
    t1.setContent("M50, 0L0, 50 L100, 50 Z");
    t1.setStrokeWidth(10);
    t1.setFill(null);
    t1.setStroke(Color.BLACK);
    t1.setStrokeMiterLimit(2.0);

    SVGPath t2 = new SVGPath();
    t2.setContent("M50, 0L0, 50 L100, 50 Z");
    t2.setStrokeWidth(10);
    t2.setFill(null);
    t2.setStroke(Color.BLACK);

    /*
    A MITER line join joins two path elements by extending their outer edges. If the path elements meet at
    a smaller angle, the length of the join may become very big. You can limit the length of the join using the
    strokeMiterLimit property. It specifies the ratio of the miter length and the stroke width. The miter length
    is the distance between the most inside point and the most outside point of the join. If the two path elements
    cannot meet by extending their outer edges within this limit, a BEVEL join is used instead. The default value
    is 10.0. That is, by default, the miter length may be up to ten times the stroke width.

    By default, the stroke draws a solid outline. You can also have a dashed outline. You need to provide
    a dashing pattern and a dash offset. The dashing pattern is an array of double that is stored in an
    ObservableList<Double>. You can get the reference of the list using the getStrokeDashArray() method of
    the Shape class. The elements of the list specify a pattern of dashes and gaps. The first element is the dash
    length, the second gap, the third dash length, the fourth gap, and so on. The dashing pattern is repeated to
    draw the outline. The strokeDashOffset property specifies the offset in the dashing pattern where the
    stroke begins.
    */
    Polygon p1 = new Polygon(0, 0, 100, 0, 100, 50, 0, 50, 0, 0);
    p1.setFill(null);
    p1.setStroke(Color.BLACK);
    p1.getStrokeDashArray().addAll(15.0, 5.0, 5.0, 5.0);

    Polygon p2 = new Polygon(0, 0, 100, 0, 100, 50, 0, 50, 0, 0);
    p2.setFill(null);
    p2.setStroke(Color.BLACK);
    p2.getStrokeDashArray().addAll(15.0, 5.0, 5.0, 5.0);
    p2.setStrokeDashOffset(20.0);

    HBox root = new HBox(t1, t2, p1, p2);
    root.setAlignment(Pos.CENTER);
    root.setSpacing(10);
    root.setStyle(
        "-fx-padding: 10;"
            + "-fx-border-style: solid inside;"
            + "-fx-border-width: 2;"
            + "-fx-border-insets: 5;"
            + "-fx-border-radius: 5;"
            + "-fx-border-color: blue;");

    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.setTitle("Using Different Stroke Types for Shapes");
    stage.show();
  }
Пример #8
0
  public void findIntersections2(PKBean refPKBean, Double refSigma, Double minSigma)
      throws InvalidBoundsException {
    Double startX = null;
    Double endX = null;
    XYPair positiveStartPair = null;
    XYPair negativeStartPair = null;
    XYPair positiveEndPair = null;
    XYPair negativeEndPair = null;
    boolean insideMinSigma = false;
    boolean signChanged = false;
    List<XYPair> positiveRefCurve = refPKBean.getCurveForSigma(refSigma);
    List<XYPair> negativeRefCurve = refPKBean.getCurveForSigma(-refSigma);
    if (positiveRefCurve.size() > 0)
      for (int i = 1; i < positiveRefCurve.size(); i++) {
        XYPair positivePt = positiveRefCurve.get(i);
        XYPair negativePt = negativeRefCurve.get(i);

        XYPair positivePtPrev = positiveRefCurve.get(i - 1);
        XYPair negativePtPrev = negativeRefCurve.get(i - 1);

        double positiveMaxSigma = getMaxSigma(positivePt);
        double negativeMaxSigma = getMaxSigma(negativePt);

        double positiveMaxSigmaPrev = getMaxSigma(positivePtPrev);
        double negativeMaxSigmaPrev = getMaxSigma(negativePtPrev);
        if ((positiveMaxSigmaPrev <= 0 && positiveMaxSigma >= 0
            || positiveMaxSigmaPrev >= 0 && positiveMaxSigma <= 0
            || negativeMaxSigmaPrev <= 0 && negativeMaxSigma >= 0
            || negativeMaxSigmaPrev >= 0 && negativeMaxSigma <= 0)) {
          signChanged = true;
          /* sign of sigma changes but no point is within minsigma*/
          if (startX == null) {
            startX = Math.min(positivePtPrev.getX(), negativePtPrev.getX());
            positiveStartPair = positivePtPrev;
            negativeStartPair = negativePtPrev;
          }

          endX = Math.min(positivePt.getX(), negativePt.getX());
          positiveEndPair = positivePt;
          negativeEndPair = negativePt;

          Bounds bounds = new Bounds(startX, endX, inp.getNumPts(), false);
          PKBean subRefPKBean =
              new PKBean(leastErrorPKName, refPKBean.getValue(), refPKBean.getError(), bounds);

          System.err.println(
              "sign changed:"
                  + positiveMaxSigma
                  + " "
                  + +positiveMaxSigmaPrev
                  + " "
                  + positiveMaxSigma
                  + " "
                  + negativeMaxSigmaPrev
                  + " minSigma: "
                  + minSigma);
          findIntersections(subRefPKBean, refSigma, minSigma);
          startX = null;
        }

        System.err.println(
            "positiveMaxSigma: "
                + positiveMaxSigma
                + " negativeMaxSigma: "
                + negativeMaxSigma
                + " minSigma: "
                + minSigma);
        if ((Math.abs(positiveMaxSigma) < minSigma || Math.abs(negativeMaxSigma) < minSigma)) {
          insideMinSigma = true;
          if (startX == null) {
            startX = Math.min(positivePtPrev.getX(), negativePtPrev.getX());
            positiveStartPair = positivePtPrev;
            negativeStartPair = negativePtPrev;
            System.err.println(
                "Selected start"
                    + " positiveMaxSigma: "
                    + positiveMaxSigmaPrev
                    + " negativeMaxSigma: "
                    + negativeMaxSigmaPrev
                    + " minSigma: "
                    + minSigma);
          }

        } else {
          if (startX != null && insideMinSigma) {
            insideMinSigma = false;
            endX = Math.min(positivePt.getX(), negativePt.getX());
            System.err.println(
                "Selected end"
                    + " positiveMaxSigma: "
                    + positiveMaxSigma
                    + " negativeMaxSigma: "
                    + negativeMaxSigma
                    + " minSigma: "
                    + minSigma);
            positiveEndPair = positivePt;
            negativeEndPair = negativePt;
            if (minSigma > 1) {
              System.err.println(
                  "minSigma:" + minSigma + " " + Math.abs((startX - endX) / inp.numPts));
              if (Math.abs((startX - endX) / inp.numPts) > epsilon) {
                Bounds bounds = new Bounds(startX, endX, inp.getNumPts(), false);
                PKBean subRefPKBean =
                    new PKBean(
                        leastErrorPKName, refPKBean.getValue(), refPKBean.getError(), bounds);

                findIntersections(subRefPKBean, refSigma, minSigma - 1);
                startX = null;
              } else {
                Bounds bounds =
                    new Bounds(
                        startX,
                        endX,
                        Math.round((float) (Math.abs((startX - endX)) / epsilon)),
                        false);
                PKBean subRefPKBean =
                    new PKBean(
                        leastErrorPKName, refPKBean.getValue(), refPKBean.getError(), bounds);
                findIntersections(subRefPKBean, refSigma, 1.0);
                startX = null;
              }
            } else {
              if (Math.abs((startX - endX) / inp.numPts) > epsilon) {
                Bounds bounds = new Bounds(startX, endX, inp.getNumPts(), false);
                PKBean subRefPKBean =
                    new PKBean(
                        leastErrorPKName, refPKBean.getValue(), refPKBean.getError(), bounds);
                findIntersections(subRefPKBean, refSigma, 1.0);
                startX = null;

              } else {
                Polygon polygon = new Polygon();
                polygon
                    .getPoints()
                    .addAll(
                        new Double[] {
                          positiveStartPair.getX(), positiveStartPair.getY(),
                          positiveEndPair.getX(), positiveEndPair.getY(),
                          negativeStartPair.getX(), negativeStartPair.getY(),
                          negativeEndPair.getX(), negativeEndPair.getY()
                        });
                intersectionList.add(polygon);
              }
            }
          }
        }
      }
  }
Пример #9
0
  public void findIntersections(PKBean refPKBean, Double refSigma, Double minSigma)
      throws InvalidBoundsException {
    Double startX = null;
    Double endX = null;

    List<XYPair> posRef = refPKBean.getCurveForSigma(refSigma);
    List<XYPair> negRef = refPKBean.getCurveForSigma(-refSigma);

    List<Double> posMaxSig = new ArrayList<Double>();
    List<Double> negMaxSig = new ArrayList<Double>();

    for (int i = 0; i < posRef.size(); i++) {
      posMaxSig.add(getMaxSigma(posRef.get(i)));
      negMaxSig.add(getMaxSigma(negRef.get(i)));
    }

    if (posRef.size() > 0 && negRef.size() > 0 && posRef.size() == negRef.size()) {
      for (int i = 1; i < posRef.size() - 1; i++) {
        XYPair posNow = posRef.get(i);
        XYPair negNow = negRef.get(i);

        double posMaxSigNow = posMaxSig.get(i);
        double negMaxSigNow = negMaxSig.get(i);

        XYPair posNext = posRef.get(i + 1);
        XYPair negNext = negRef.get(i + 1);

        double posMaxSigNext = posMaxSig.get(i + 1);
        double negMaxSigNext = negMaxSig.get(i + 1);

        XYPair posPrev = posRef.get(i - 1);
        XYPair negPrev = negRef.get(i - 1);

        double posMaxSigPrev = posMaxSig.get(i - 1);
        double negMaxSigPrev = negMaxSig.get(i - 1);

        // find if the difference changes sign meaning the intersecting curve is changing course.
        // System.err.println(posPrev + " "+ posNow+ " "+posNext + " "+posMaxSigPrev + "
        // "+posMaxSigNow + " "+posMaxSigNext + " "
        // +Math.signum(posMaxSigPrev-posMaxSigNow)+ " "+Math.signum(posMaxSigNow-posMaxSigNext));
        if ((Math.signum(posMaxSigPrev - posMaxSigNow) != Math.signum(posMaxSigNow - posMaxSigNext))
            || (Math.signum(negMaxSigPrev - negMaxSigNow)
                != Math.signum(negMaxSigNow - negMaxSigNext))) {

          startX = Math.min(posPrev.getX(), negPrev.getX());
          endX = Math.min(posNext.getX(), negNext.getX());
          // System.err.println("Turns! "+posMaxSigPrev + " "+posMaxSigNow + " "+posMaxSigNext + "
          // "+startX+" "+endX + " " +Math.abs((startX-endX)/inp.numPts));

          if (Math.abs((startX - endX) / inp.numPts) > epsilon) {
            Bounds bounds = new Bounds(startX, endX, inp.getNumPts(), false);
            PKBean subRefPKBean =
                new PKBean(leastErrorPKName, refPKBean.getValue(), refPKBean.getError(), bounds);
            findIntersections(subRefPKBean, refSigma, minSigma);
            // System.err.println("came out"+ startX+ " " + endX);
          } else {
            if (posMaxSigNow < 1 || negMaxSigNow < 1) {
              Polygon polygon = new Polygon();
              polygon
                  .getPoints()
                  .addAll(
                      new Double[] {
                        posPrev.getX(), posPrev.getY(),
                        posNext.getX(), posNext.getY(),
                        negPrev.getX(), negPrev.getY(),
                        negNext.getX(), negNext.getY()
                      });
              // System.err.println("Polygon" + polygon.getPoints());
              intersectionList.add(polygon);
            } else {
              System.err.println(posMaxSigNow + " " + negMaxSigNow);
            }
          }
        }
        /* find if the individual sigma changes sign*/
        //				else if( (Math.signum(posMaxSigPrev)==Math.signum(posMaxSigNow)) ||
        // (Math.signum(negMaxSigPrev)==Math.signum(negMaxSigNow)) ){
        //
        //				}

      }
    }
  }