Class View2DProcessing

    • Field Detail

      • view

        protected View view
      • tickTextHorizontal

        protected float tickTextHorizontal
      • tickTextVertical

        protected float tickTextVertical
      • axisTextHorizontal

        protected float axisTextHorizontal
      • axisTextVertical

        protected float axisTextVertical
      • marginLeftPx

        protected float marginLeftPx
      • marginRightPx

        protected float marginRightPx
      • marginTopPx

        protected float marginTopPx
      • marginBottomPx

        protected float marginBottomPx
      • marginLeftModel

        protected float marginLeftModel
      • marginRightModel

        protected float marginRightModel
      • marginTopModel

        protected float marginTopModel
      • marginBottomModel

        protected float marginBottomModel
      • margin

        protected Area margin
      • modelToScreen

        protected Coord2d modelToScreen
    • Constructor Detail

      • View2DProcessing

        public View2DProcessing​(View view)
    • Method Detail

      • getModelToScreenRatio

        public Coord2d getModelToScreenRatio​(Area space,
                                             Area canvas,
                                             Area margins)
        A helper for processing 2D margins. This method process a model-to-screen ratio able to indicate which range of real world coordinates will be mapped to a single pixel, both on the width and height of the viewport. It is used to evaluate the camera settings to apply to a 2D projection to allow keeping a white space for drawing 2D margins. The intuition lead to consider that this ratio R should be :
         
         R.x = scene.bounds.xrange() / viewport.width 
         R.y = scene.bounds.yrange() / viewport.height
         
         
        This would allow to compute an extra space to add to world coordinates specified in pixel units. However this ratio does not allow considering margins in world space AND screen space consistently (which then leads to inconsistent layout). Our need then become to ensure this ratio remains the same in 2D (pixel space) and 3D (scene space). To explain the formulae, we assuming the following case of 1000px wide canvas showing a scene with a range of 20 along the X dimension. The largest rectangle represents the canvas, the smallest represents the scene. We show a left and right margin made of 100px each.
         
          100px       800px        100px
         |-----+------------------+-----|
         |                              |
         |     |------------------|     |
         |     |                  |     |
         |     |     xrange=20    |     |
         |     |------------------|     |
         |    x=-10              x=10   |
         |-----+------------------+-----|
         
         
        Let's start with our naive ratio formulae
         
         R.x = scene.xrange() / viewport.width = 20/1000 = 2/100
         
         
        Margins in scene space (3D) should then be
         
         margin3D.x = margin2D.x * R.x = 200 * 2/100 = 4
         
         
        Hence the range to consider to keep a white space around the 3D scene is x:[-12;12] instead of the initial x:[-10;10] We now want to ensure that the margin ratio in screen space remains the same than the one in scene space :
         
         scene.xrange() / sceneWithMargin.xrange() = screen.xrange() / screenWithMargin.xrange()
         
         in our example : 
         20 / 24 = 800 / 1000
         
         
        This constraint is represented by the following equation
         
         
                 scene.xrange               screen.xrange - margin2D.x     
         -------------------------------  = --------------------------
         R.x * margin2D.x + scene.xrange          screen.xrange
         
         
         
        Solving this equation to get R.x yield to
         
           screen.xrange * scene.xrange
         ( ---------------------------- - scene.xrange ) * (1/margin2D.x)
            screen.xrange - margin2D.x
         
         
        Reasoning is the same for the Y dimension. NB : the ratio will be 1 in the case margin is 0 or if canvas size is equal to margin size.
        Parameters:
        space -
        canvas -
        margins -
        Returns:
      • getMargin

        public Area getMargin()
        Return the overall margin that was processed at the latest call to #apply() according to the axis and view layout settings
      • getTickTextHorizontal

        public float getTickTextHorizontal()
        Return the tick label width in pixel that was processed at the latest call to #apply() according to the axis and view layout settings
      • getTickTextVertical

        public float getTickTextVertical()
        Return the tick label height in pixel that was processed at the latest call to #apply() according to the axis and view layout settings
      • getAxisTextHorizontal

        public float getAxisTextHorizontal()
        Return the axis label width in pixel that was processed at the latest call to #apply() according to the axis and view layout settings
      • getAxisTextVertical

        public float getAxisTextVertical()
        Return the axis label height in pixel that was processed at the latest call to #apply() according to the axis and view layout settings
      • getModelToScreen

        public Coord2d getModelToScreen()
        Return the model-to-screen ratio that that was processed at the latest call to #apply()