/** * Compute the {@link Graduations} used to the ruler drawing in auto-ticks mode.. * * @return the used decimal format. */ private DecimalFormat computeUserGraduation() { /* The maximum distance corresponding to the actually displayed sprites. */ double maxSpritesDistance = 0.0; Graduations currentGraduations = rulerModel.getGraduations(); List<Double> ticks = currentGraduations.getNewValues(); DecimalFormat format = currentGraduations.getFormat(); for (double value : ticks) { Texture sprite = computeSprite(value, format); if (sprite != null) { Vector3d windowPosition = canvasProjection.project(rulerModel.getPosition(value)); Vector3d delta = projectCenterToEdge(sprite, windowTicksDelta); spritesList.add( new PositionedSprite(sprite, windowPosition.plus(windowTicksDelta.plus(delta)))); Vector3d farDelta = windowTicksDelta.plus(delta.times(2.0)); maxSpritesDistance = Math.max(maxSpritesDistance, farDelta.getNorm()); } } this.graduations = currentGraduations; this.maximalSpritesDistance = maxSpritesDistance; return format; }
/** * Compute the {@link Graduations} used to the ruler drawing in auto-ticks mode.. * * @return the used decimal format. */ private DecimalFormat computeAutoGraduation() { /* The maximum distance corresponding to the actually displayed sprites. */ double maxSpritesDistance = 0.0; Graduations currentGraduations = rulerModel.getGraduations(); Graduations ticksGraduation = currentGraduations; DecimalFormat format = currentGraduations.getFormat(); boolean canGetMore = true; List<PositionedSprite> newSpritesList = new LinkedList<PositionedSprite>(); while (currentGraduations != null) { /* The maximum distance to any of the sprites' farthest sides at a given iteration. */ double currentMaximalSpritesDistance = 0; newSpritesList.clear(); List<Double> ticks = currentGraduations.getNewValues(); for (double value : ticks) { Texture sprite = computeSprite(value, format); Vector3d windowPosition = canvasProjection.project(rulerModel.getPosition(value)); Dimension textureSize = computeSpriteDimension(value); Vector3d delta = projectCenterToEdge(textureSize, windowTicksDelta); PositionedSprite newSprite = new PositionedSprite( sprite, textureSize, windowPosition.plus(windowTicksDelta.plus(delta))); newSpritesList.add(newSprite); Vector3d farDelta = windowTicksDelta.plus(delta.times(2.0)); currentMaximalSpritesDistance = Math.max(currentMaximalSpritesDistance, farDelta.getNorm()); } if (collide(newSpritesList, rulerModel.getMargin()) || collide(spritesList, newSpritesList, rulerModel.getMargin())) { currentGraduations = currentGraduations.getAlternative(); canGetMore = false; } else { maxSpritesDistance = Math.max(maxSpritesDistance, currentMaximalSpritesDistance); spritesList.addAll(newSpritesList); ticksGraduation = currentGraduations; if (canGetMore) { currentGraduations = currentGraduations.getMore(); } else { currentGraduations = null; } } } this.graduations = ticksGraduation; this.maximalSpritesDistance = maxSpritesDistance; return format; }