1
/******************************************************************************
2
* $Id: mapgeomutil.cpp 11592 2011-04-18 10:15:18Z tbonfort $
5
* Purpose: Rendering utility functions
6
* Author: Thomas Bonfort and the MapServer team.
8
******************************************************************************
9
* Copyright (c) 1996-2011 Regents of the University of Minnesota.
11
* Permission is hereby granted, free of charge, to any person obtaining a
12
* copy of this software and associated documentation files (the "Software"),
13
* to deal in the Software without restriction, including without limitation
14
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
15
* and/or sell copies of the Software, and to permit persons to whom the
16
* Software is furnished to do so, subject to the following conditions:
18
* The above copyright notice and this permission notice shall be included in
19
* all copies of this Software or works derived from this Software.
21
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
* DEALINGS IN THE SOFTWARE.
28
*****************************************************************************/
30
#include "mapserver.h"
32
#include "renderers/agg/include/agg_arc.h"
33
#include "renderers/agg/include/agg_basics.h"
37
shapeObj *msRasterizeArc(double x0, double y0, double radius, double startAngle, double endAngle, int isSlice) {
38
static int allocated_size=100;
39
shapeObj *shape = (shapeObj*)calloc(1,sizeof(shapeObj));
40
MS_CHECK_ALLOC(shape, sizeof(shapeObj), NULL);
41
mapserver::arc arc ( x0, y0,radius,radius, startAngle*MS_DEG_TO_RAD, endAngle*MS_DEG_TO_RAD,true );
42
arc.approximation_scale ( 1 );
46
lineObj *line = (lineObj*)calloc(1,sizeof(lineObj));
48
msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", "msRasterizeArc()" ,
49
__FILE__, __LINE__, sizeof(lineObj));
55
line->point = (pointObj*)calloc(allocated_size,sizeof(pointObj));
57
msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", "msRasterizeArc()" ,
58
__FILE__, __LINE__, allocated_size*sizeof(pointObj));
68
//first segment from center to first point of arc
70
line->point[0].x = x0;
71
line->point[0].y = y0;
74
while(arc.vertex(&x,&y) != mapserver::path_cmd_stop) {
75
if(line->numpoints == allocated_size) {
77
line->point = (pointObj*)realloc(line->point, allocated_size * sizeof(pointObj));
79
msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", "msRasterizeArc()" ,
80
__FILE__, __LINE__, allocated_size * sizeof(pointObj));
86
line->point[line->numpoints].x = x;
87
line->point[line->numpoints].y = y;
91
//make sure the shape is closed if we're doing a full circle
92
if(!isSlice && !(endAngle-startAngle)%360) {
93
if(line->point[line->numpoints-1].x != line->point[0].x ||
94
line->point[line->numpoints-1].y != line->point[0].y) {
95
if(line->numpoints == allocated_size) {
97
line->point = (pointObj*)realloc(line->point, allocated_size * sizeof(pointObj));
99
msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", "msRasterizeArc()" ,
100
__FILE__, __LINE__, allocated_size * sizeof(pointObj));
106
line->point[line->numpoints].x = line->point[0].x;
107
line->point[line->numpoints].y = line->point[0].y;
113
if(line->numpoints == allocated_size) {
115
line->point = (pointObj*)realloc(line->point, allocated_size * sizeof(pointObj));
117
msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", "msRasterizeArc()" ,
118
__FILE__, __LINE__, allocated_size * sizeof(pointObj));
124
line->point[line->numpoints].x = x0;
125
line->point[line->numpoints].y = y0;