Java Geometry Algorithm quantisePoint(Point2D.Double dpos, Point gpos)

Here you can find the source of quantisePoint(Point2D.Double dpos, Point gpos)

Description

Maps a floating point graphics position to an integer graphics position, that is a 2-dimensional grid cell index.

License

LGPL

Parameter

Parameter Description
dpos input definite floating point graphics position
gpos output graphics position object

Declaration

public static void quantisePoint(Point2D.Double dpos, Point gpos) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.awt.Point;

import java.awt.geom.Point2D;

public class Main {
    /**// w  w w.  ja  va  2s. co  m
     * Maps a floating point graphics position to an integer graphics
     * position, that is a 2-dimensional grid cell index.
     * It does this by calling {@link #ifloor} on both coordinates.
     * The input coordinates must not be NaN.
     *
     * @param   dpos   input definite floating point graphics position
     * @param   gpos   output graphics position object
     */
    public static void quantisePoint(Point2D.Double dpos, Point gpos) {
        gpos.x = ifloor(dpos.x);
        gpos.y = ifloor(dpos.y);
    }

    /**
     * Determines the integer not larger than a given non-NaN
     * floating point value.
     * 
     * @param  x  definite floating point value
     * @return  floor of input
     * @see   java.lang.Math#floor
     */
    public static int ifloor(double x) {
        int y = (int) x;
        return x >= 0 || x == y || y == Integer.MIN_VALUE ? y : y - 1;
    }
}

Related

  1. project(Point2D sourceLocation, double angle, double length)
  2. project(Point2D.Double sourceLocation, double angle, double length)
  3. projectionFactor(Point pt, Point start, Point stop)
  4. projectPoint(float x, float y, Line2D ray, float distance)
  5. projectPointOntoLine(Point2D pt, Line2D ln)
  6. relTo(final Point2D from, final Point2D to, final Point2D rel)
  7. resample(Vector points, int n, Vector newPoints)
  8. setPathAnchor(Shape s, Point2D pt)
  9. setPathControlPoint(Shape s, int i, Point2D pt)