1 /*
   2  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #ifndef ParallelogramUtils_h_Included
  27 #define ParallelogramUtils_h_Included
  28 
  29 #ifdef __cplusplus
  30 extern "C" {
  31 #endif
  32 
  33 #define PGRAM_MIN_MAX(bmin, bmax, v0, dv1, dv2, AA) \
  34     do { \
  35         double vmin, vmax; \
  36         if (dv1 < 0) { \
  37             vmin = v0+dv1; \
  38             vmax = v0; \
  39         } else { \
  40             vmin = v0; \
  41             vmax = v0+dv1; \
  42         } \
  43         if (dv2 < 0) { \
  44             vmin += dv2; \
  45         } else { \
  46             vmax += dv2; \
  47         } \
  48         if (AA) { \
  49             bmin = (jint) floor(vmin); \
  50             bmax = (jint) ceil(vmax); \
  51         } else { \
  52             bmin = (jint) floor(vmin + 0.5); \
  53             bmax = (jint) floor(vmax + 0.5); \
  54         } \
  55     } while(0)
  56 
  57 #define PGRAM_INIT_X(starty, x, y, slope) \
  58     (DblToLong((x) + (slope) * ((starty)+0.5 - (y))) + LongOneHalf - 1)
  59 
  60 /*
  61  * Sort parallelogram by y values, ensure that each delta vector
  62  * has a non-negative y delta.
  63  */
  64 #define SORT_PGRAM(x0, y0, dx1, dy1, dx2, dy2, OTHER_SWAP_CODE) \
  65     do { \
  66         if (dy1 < 0) { \
  67             x0 += dx1;  y0 += dy1; \
  68             dx1 = -dx1; dy1 = -dy1; \
  69         } \
  70         if (dy2 < 0) { \
  71             x0 += dx2;  y0 += dy2; \
  72             dx2 = -dx2; dy2 = -dy2; \
  73         } \
  74         /* Sort delta vectors so dxy1 is left of dxy2. */ \
  75         if (dx1 * dy2 > dx2 * dy1) { \
  76             double v; \
  77             v = dx1; dx1 = dx2; dx2 = v; \
  78             v = dy1; dy1 = dy2; dy2 = v; \
  79             OTHER_SWAP_CODE \
  80         } \
  81     } while(0)
  82 
  83 #endif /* ParallelogramUtils_h_Included */