Back to index

lightning-sunbird  0.9+nobinonly
cairo-slope.c
Go to the documentation of this file.
00001 /* cairo - a vector graphics library with display and print output
00002  *
00003  * Copyright © 2002 University of Southern California
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it either under the terms of the GNU Lesser General Public
00007  * License version 2.1 as published by the Free Software Foundation
00008  * (the "LGPL") or, at your option, under the terms of the Mozilla
00009  * Public License Version 1.1 (the "MPL"). If you do not alter this
00010  * notice, a recipient may use your version of this file under either
00011  * the MPL or the LGPL.
00012  *
00013  * You should have received a copy of the LGPL along with this library
00014  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
00015  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00016  * You should have received a copy of the MPL along with this library
00017  * in the file COPYING-MPL-1.1
00018  *
00019  * The contents of this file are subject to the Mozilla Public License
00020  * Version 1.1 (the "License"); you may not use this file except in
00021  * compliance with the License. You may obtain a copy of the License at
00022  * http://www.mozilla.org/MPL/
00023  *
00024  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
00025  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
00026  * the specific language governing rights and limitations.
00027  *
00028  * The Original Code is the cairo graphics library.
00029  *
00030  * The Initial Developer of the Original Code is University of Southern
00031  * California.
00032  *
00033  * Contributor(s):
00034  *     Carl D. Worth <cworth@cworth.org>
00035  */
00036 
00037 #include "cairoint.h"
00038 
00039 void
00040 _cairo_slope_init (cairo_slope_t *slope, cairo_point_t *a, cairo_point_t *b)
00041 {
00042     slope->dx = b->x - a->x;
00043     slope->dy = b->y - a->y;
00044 }
00045 
00046 /* Compare two slopes. Slope angles begin at 0 in the direction of the
00047    positive X axis and increase in the direction of the positive Y
00048    axis.
00049 
00050    WARNING: This function only gives correct results if the angular
00051    difference between a and b is less than PI.
00052 
00053    <  0 => a less positive than b
00054    == 0 => a equal to be
00055    >  0 => a more positive than b
00056 */
00057 int
00058 _cairo_slope_compare (cairo_slope_t *a, cairo_slope_t *b)
00059 {
00060     cairo_fixed_48_16_t diff;
00061 
00062     diff = ((cairo_fixed_48_16_t) a->dy * (cairo_fixed_48_16_t) b->dx 
00063            - (cairo_fixed_48_16_t) b->dy * (cairo_fixed_48_16_t) a->dx);
00064 
00065     if (diff > 0)
00066        return 1;
00067     if (diff < 0)
00068        return -1;
00069 
00070     if (a->dx == 0 && a->dy == 0)
00071        return 1;
00072     if (b->dx == 0 && b->dy ==0)
00073        return -1;
00074 
00075     return 0;
00076 }
00077 
00078 /* XXX: It might be cleaner to move away from usage of
00079    _cairo_slope_clockwise/_cairo_slope_counter_clockwise in favor of
00080    directly using _cairo_slope_compare.
00081 */
00082 
00083 /* Is a clockwise of b?
00084  *
00085  * NOTE: The strict equality here is not significant in and of itself,
00086  * but there are functions up above that are sensitive to it,
00087  * (cf. _cairo_pen_find_active_cw_vertex_index).
00088  */
00089 int
00090 _cairo_slope_clockwise (cairo_slope_t *a, cairo_slope_t *b)
00091 {
00092     return _cairo_slope_compare (a, b) < 0;
00093 }
00094 
00095 int
00096 _cairo_slope_counter_clockwise (cairo_slope_t *a, cairo_slope_t *b)
00097 {
00098     return ! _cairo_slope_clockwise (a, b);
00099 }
00100 
00101 
00102 
00103