00001 /* 00002 * quad.h 00003 * 00004 * Copyright (C) 2007 Thomas A. Vaughan 00005 * All rights reserved. 00006 * 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are met: 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * * Neither the name of the <organization> nor the 00016 * names of its contributors may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY 00020 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY 00023 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00026 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 * 00030 * 00031 * Quadratic beziers 00032 */ 00033 00034 #ifndef WAVEPACKET_BEZIER_QUAD_H__ 00035 #define WAVEPACKET_BEZIER_QUAD_H__ 00036 00037 // includes -------------------------------------------------------------------- 00038 #include "bezier.h" 00039 00040 00041 /// \ingroup bezier 00042 /*@{*/ 00043 00044 namespace bezier { 00045 00046 00047 /// quadratic bezier curve 00048 struct quad_bezier_t { 00049 void clear(void) throw() { 00050 p0 = p1 = p2 = point_t(0.0, 0.0); 00051 } 00052 00053 void setFromPointsAndSlope(IN const point_t& in_p0, 00054 IN const point_t& in_p1, 00055 IN const point_t& t0) throw() { 00056 p0 = in_p0; // initial point 00057 p2 = in_p1; // final point 00058 p1.x = p0.x + 0.5 * t0.x; // t0 = initial tangent 00059 p1.y = p0.y + 0.5 * t0.y; 00060 } 00061 00062 point_t getFinalTangent(void) const throw() { 00063 return point_t(2.0 * (p2.x - p1.x), 00064 2.0 * (p2.y - p1.y)); 00065 } 00066 00067 point_t getPointAt(IN float t) const throw() { 00068 ASSERT(t >= 0.0 && t <= 1.0, "Bad t: %f", t); 00069 float alpha = 1.0 - t; 00070 float beta = 2.0 * t * alpha; 00071 alpha *= alpha; 00072 float gamma = t * t; 00073 return point_t(alpha * p0.x + beta * p1.x + gamma * p2.x, 00074 alpha * p0.y + beta * p1.y + gamma * p2.y); 00075 } 00076 00077 void getBoundingRect(OUT rect_t& r) const throw(); 00078 00079 // data fields (control points) 00080 point_t p0; 00081 point_t p1; 00082 point_t p2; 00083 }; 00084 00085 00086 00087 }; // bezier namespace 00088 00089 #endif // WAVEPACKET_BEZIER_QUAD_H__ 00090