BRL-CAD
scale_ehy.c
Go to the documentation of this file.
1 /* S C A L E _ E H Y . 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_ehy.c
21  *
22  * The scale_ehy command.
23  */
24 
25 #include "common.h"
26 
27 #include <string.h>
28 
29 #include "bu/cmd.h"
30 #include "rtgeom.h"
31 #include "raytrace.h"
32 
33 #include "./ged_private.h"
34 
35 int
36 _ged_scale_ehy(struct ged *gedp, struct rt_ehy_internal *ehy, const char *attribute, fastf_t sf, int rflag)
37 {
38  fastf_t newrad;
39 
40  RT_EHY_CK_MAGIC(ehy);
41 
42  switch (attribute[0]) {
43  case 'h':
44  case 'H':
45  if (!rflag)
46  sf /= MAGNITUDE(ehy->ehy_H);
47 
48  VSCALE(ehy->ehy_H, ehy->ehy_H, sf);
49  break;
50  case 'a':
51  case 'A':
52  if (rflag)
53  newrad = ehy->ehy_r1 * sf;
54  else
55  newrad = sf;
56 
57  if (newrad >= ehy->ehy_r2)
58  ehy->ehy_r1 = newrad;
59  break;
60  case 'b':
61  case 'B':
62  if (rflag)
63  newrad = ehy->ehy_r2 * sf;
64  else
65  newrad = sf;
66 
67  if (newrad <= ehy->ehy_r1)
68  ehy->ehy_r2 = newrad;
69  break;
70  case 'c':
71  case 'C':
72  if (rflag)
73  ehy->ehy_c *= sf;
74  else
75  ehy->ehy_c = sf;
76 
77  break;
78  default:
79  bu_vls_printf(gedp->ged_result_str, "bad ehy attribute - %s", attribute);
80  return GED_ERROR;
81  }
82 
83  return GED_OK;
84 }
85 
86 
87 /*
88  * Local Variables:
89  * tab-width: 8
90  * mode: C
91  * indent-tabs-mode: t
92  * c-file-style: "stroustrup"
93  * End:
94  * ex: shiftwidth=4 tabstop=8
95  */
#define GED_OK
Definition: ged.h:55
Definition: ged.h:338
Header file for the BRL-CAD common definitions.
#define GED_ERROR
Definition: ged.h:61
int _ged_scale_ehy(struct ged *gedp, struct rt_ehy_internal *ehy, const char *attribute, fastf_t sf, int rflag)
Definition: scale_ehy.c:36
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