BRL-CAD
scale_tor.c
Go to the documentation of this file.
1 /* S C A L E _ T O R . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2008-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @file libged/scale_tor.c
21  *
22  * The scale_tor command.
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <string.h>
29 
30 #include "bu/cmd.h"
31 #include "rtgeom.h"
32 #include "raytrace.h"
33 
34 #include "./ged_private.h"
35 
36 
37 int
38 _ged_scale_tor(struct ged *gedp, struct rt_tor_internal *tor, const char *attribute, fastf_t sf, int rflag)
39 {
40  fastf_t newrad;
41 
42  RT_TOR_CK_MAGIC(tor);
43 
44  switch (attribute[0]) {
45  case 'a':
46  case 'A':
47  if (rflag)
48  newrad = tor->r_a * sf;
49  else
50  newrad = sf;
51 
52  if (newrad < SMALL)
53  newrad = 4*SMALL;
54  if (tor->r_h <= newrad)
55  tor->r_a = newrad;
56  break;
57  case 'h':
58  case 'H':
59  if (rflag)
60  newrad = tor->r_h * sf;
61  else
62  newrad = sf;
63 
64  if (newrad < SMALL)
65  newrad = 4*SMALL;
66  if (newrad <= tor->r_a)
67  tor->r_h = newrad;
68  break;
69  default:
70  bu_vls_printf(gedp->ged_result_str, "bad tor attribute - %s", attribute);
71  return GED_ERROR;
72  }
73 
74  return GED_OK;
75 }
76 
77 
78 /*
79  * Local Variables:
80  * tab-width: 8
81  * mode: C
82  * indent-tabs-mode: t
83  * c-file-style: "stroustrup"
84  * End:
85  * ex: shiftwidth=4 tabstop=8
86  */
#define GED_OK
Definition: ged.h:55
#define SMALL
Definition: defines.h:351
Definition: ged.h:338
Header file for the BRL-CAD common definitions.
#define GED_ERROR
Definition: ged.h:61
struct bu_vls * ged_result_str
Definition: ged.h:357
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
double fastf_t
Definition: defines.h:300
int _ged_scale_tor(struct ged *gedp, struct rt_tor_internal *tor, const char *attribute, fastf_t sf, int rflag)
Definition: scale_tor.c:38