/**
   * Creates a elliptical arc, as a LineString.
   *
   * @return an elliptical arc
   */
  public LineString createArc(double startAng, double endAng) {
    Envelope env = dim.getEnvelope();
    double xRadius = env.getWidth() / 2.0;
    double yRadius = env.getHeight() / 2.0;

    double centreX = env.getMinX() + xRadius;
    double centreY = env.getMinY() + yRadius;

    double angSize = (endAng - startAng);
    if (angSize <= 0.0 || angSize > 2 * Math.PI) angSize = 2 * Math.PI;
    double angInc = angSize / nPts;

    Coordinate[] pts = new Coordinate[nPts];
    int iPt = 0;
    for (int i = 0; i < nPts; i++) {
      double ang = startAng + i * angInc;
      double x = xRadius * Math.cos(ang) + centreX;
      double y = yRadius * Math.sin(ang) + centreY;
      Coordinate pt = new Coordinate(x, y);
      geomFact.getPrecisionModel().makePrecise(pt);
      pts[iPt++] = pt;
    }
    LineString line = geomFact.createLineString(pts);
    return line;
  }
 /**
  * Get the desired dimensions and scale for the bitmap to be placed in the location corresponding
  * to id. Caller must allocate the Dimensions object.
  *
  * @param key
  * @param outDim a {@link ImageCanvas.Dimensions} object to write results into
  */
 @Override
 public void getDesiredDimensions(Object key, Dimensions outDim) {
   Utils.traceBeginSection("get desired dimensions");
   int w = 0, h = 0;
   float scale = 0;
   final Integer pos = mDivisionMap.get(transformKeyToDivisionId(key));
   if (pos != null && pos >= 0) {
     final int size = mDivisionMap.size();
     switch (size) {
       case 0:
         break;
       case 1:
         w = mWidth;
         h = mHeight;
         scale = Dimensions.SCALE_ONE;
         break;
       case 2:
         w = mWidth / 2;
         h = mHeight;
         scale = Dimensions.SCALE_HALF;
         break;
       case 3:
         switch (pos) {
           case 0:
             w = mWidth / 2;
             h = mHeight;
             scale = Dimensions.SCALE_HALF;
             break;
           default:
             w = mWidth / 2;
             h = mHeight / 2;
             scale = Dimensions.SCALE_QUARTER;
         }
         break;
       case 4:
         w = mWidth / 2;
         h = mHeight / 2;
         scale = Dimensions.SCALE_QUARTER;
         break;
     }
   }
   outDim.width = w;
   outDim.height = h;
   outDim.scale = scale;
   Utils.traceEndSection();
 }
Example #3
0
 @Override
 public void run() throws Exception {
   Path inputFile =
       Paths.get(AdventOfCode.VAR_PATH, DAY_PATH, INPUT_FILE)
           .toRealPath(LinkOption.NOFOLLOW_LINKS);
   try (BufferedReader reader = Files.newBufferedReader(inputFile)) {
     String line;
     int wrapper = 0, ribbon = 0;
     while ((line = reader.readLine()) != null) {
       Dimensions dims = parseLine(line);
       wrapper += dims.getWrapper();
       ribbon += dims.getRibbon();
     }
     System.out.println("Wrapper: " + wrapper);
     System.out.println("Ribbon: " + ribbon);
   } catch (IOException x) {
     System.err.format("IOException: %s%n", x);
   }
 }
 @Override
 public String toString() {
   return locationUrl
       + ", "
       + displayLocation
       + ", "
       + uiTheme
       + ","
       + dimensions.toString()
       + ","
       + version.toString();
 }
  /**
   * Creates a rectangular {@link Polygon}.
   *
   * @return a rectangular Polygon
   */
  public Polygon createRectangle() {
    int i;
    int ipt = 0;
    int nSide = nPts / 4;
    if (nSide < 1) nSide = 1;
    double XsegLen = dim.getEnvelope().getWidth() / nSide;
    double YsegLen = dim.getEnvelope().getHeight() / nSide;

    Coordinate[] pts = new Coordinate[4 * nSide + 1];
    Envelope env = dim.getEnvelope();

    double maxx = env.getMinX() + nSide * XsegLen;
    double maxy = env.getMinY() + nSide * XsegLen;

    for (i = 0; i < nSide; i++) {
      double x = env.getMinX() + i * XsegLen;
      double y = env.getMinY();
      pts[ipt++] = new Coordinate(x, y);
    }
    for (i = 0; i < nSide; i++) {
      double x = env.getMaxX();
      double y = env.getMinY() + i * YsegLen;
      pts[ipt++] = new Coordinate(x, y);
    }
    for (i = 0; i < nSide; i++) {
      double x = env.getMaxX() - i * XsegLen;
      double y = env.getMaxY();
      pts[ipt++] = new Coordinate(x, y);
    }
    for (i = 0; i < nSide; i++) {
      double x = env.getMinX();
      double y = env.getMaxY() - i * YsegLen;
      pts[ipt++] = new Coordinate(x, y);
    }
    pts[ipt++] = new Coordinate(pts[0]);

    LinearRing ring = geomFact.createLinearRing(pts);
    Polygon poly = geomFact.createPolygon(ring, null);
    return poly;
  }
 private Dimensions validateDimensions(Dimensions dimensions, String name)
     throws CloudWatchException {
   Collection<Dimension> dimensionsCollection = null;
   if (dimensions != null) {
     dimensionsCollection = dimensions.getMember();
   }
   if (dimensions == null) {
     return dimensions;
   }
   if (dimensionsCollection.size() > 10) {
     throw new InvalidParameterValueException(
         "The collection " + name + " must not have a size greater than 10.");
   }
   int ctr = 1;
   for (Dimension dimension : dimensionsCollection) {
     validateStringLength(dimension.getName(), name + ".member." + (ctr) + ".Name", 1, 255, true);
     validateStringLength(
         dimension.getValue(), name + ".member." + (ctr) + ".Value", 1, 255, true);
     ctr++;
   }
   return dimensions;
 }
  /**
   * Creates a circular {@link Polygon}.
   *
   * @return a circle
   */
  public Polygon createCircle() {

    Envelope env = dim.getEnvelope();
    double xRadius = env.getWidth() / 2.0;
    double yRadius = env.getHeight() / 2.0;

    double centreX = env.getMinX() + xRadius;
    double centreY = env.getMinY() + yRadius;

    Coordinate[] pts = new Coordinate[nPts + 1];
    int iPt = 0;
    for (int i = 0; i < nPts; i++) {
      double ang = i * (2 * Math.PI / nPts);
      double x = xRadius * Math.cos(ang) + centreX;
      double y = yRadius * Math.sin(ang) + centreY;
      Coordinate pt = new Coordinate(x, y);
      pts[iPt++] = pt;
    }
    pts[iPt] = pts[0];

    LinearRing ring = geomFact.createLinearRing(pts);
    Polygon poly = geomFact.createPolygon(ring, null);
    return poly;
  }
Example #8
0
 @Override // from Object
 public String toString() {
   return Dimensions.dimenToString(width(), height()) + Points.pointToString(x(), y());
 }
 /**
  * Sets the location of the shape by specifying the centre of the shape's bounding box
  *
  * @param centre the centre coordinate of the shape
  */
 public void setCentre(Coordinate centre) {
   dim.setCentre(centre);
 }
 /**
  * Sets the location of the shape by specifying the base coordinate (which in most cases is the
  * lower left point of the envelope containing the shape).
  *
  * @param base the base coordinate of the shape
  */
 public void setBase(Coordinate base) {
   dim.setBase(base);
 }
 /**
  * Sets the height of the shape.
  *
  * @param height the height of the shape
  */
 public void setHeight(double height) {
   dim.setHeight(height);
 }
 /**
  * Sets the width of the shape.
  *
  * @param width the width of the shape
  */
 public void setWidth(double width) {
   dim.setWidth(width);
 }
 /**
  * Sets the size of the extent of the shape in both x and y directions.
  *
  * @param size the size of the shape's extent
  */
 public void setSize(double size) {
   dim.setSize(size);
 }
 public static Dimensions createDimensions(double width, double height) {
   Dimensions dim = new Dimensions();
   dim.setWidth(width);
   dim.setHeight(height);
   return dim;
 }
Example #15
0
 /**
  * Depict a set of molecules, they will be depicted in a grid. The grid size (nrow x ncol) is
  * determined automatically based on the number molecules.
  *
  * @param mols molecules
  * @return depiction
  * @throws CDKException a depiction could not be generated
  * @see #depict(Iterable, int, int)
  */
 public Depiction depict(Iterable<IAtomContainer> mols) throws CDKException {
   int nMols = FluentIterable.from(mols).size();
   Dimension grid = Dimensions.determineGrid(nMols);
   return depict(mols, grid.height, grid.width);
 }