BRL-CAD
scale_ell.c
Go to the documentation of this file.
1 /* S C A L E _ E L L . 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_ell.c
21  *
22  * The scale_ell 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_ell(struct ged *gedp, struct rt_ell_internal *ell, const char *attribute, fastf_t sf, int rflag)
37 {
38  fastf_t ma, mb;
39 
40  RT_ELL_CK_MAGIC(ell);
41 
42  switch (attribute[0]) {
43  case 'a':
44  case 'A':
45  if (!rflag)
46  sf /= MAGNITUDE(ell->a);
47 
48  switch (attribute[1]) {
49  case '\0':
50  VSCALE(ell->a, ell->a, sf);
51  break;
52  case 'b':
53  case 'B':
54  if ((attribute[2] == 'c' || attribute[2] == 'C') &&
55  attribute[3] == '\0') {
56  /* set A, B, and C lengths the same */
57  VSCALE(ell->a, ell->a, sf);
58  ma = MAGNITUDE(ell->a);
59  mb = MAGNITUDE(ell->b);
60  VSCALE(ell->b, ell->b, ma/mb);
61  mb = MAGNITUDE(ell->c);
62  VSCALE(ell->c, ell->c, ma/mb);
63  } else {
64  bu_vls_printf(gedp->ged_result_str, "bad ell attribute - %s", attribute);
65  return GED_ERROR;
66  }
67 
68  break;
69  default:
70  bu_vls_printf(gedp->ged_result_str, "bad ell attribute - %s", attribute);
71  return GED_ERROR;
72  }
73 
74  break;
75  case 'b':
76  case 'B':
77  if (!rflag)
78  sf /= MAGNITUDE(ell->b);
79 
80  VSCALE(ell->b, ell->b, sf);
81  break;
82  case 'c':
83  case 'C':
84  if (!rflag)
85  sf /= MAGNITUDE(ell->c);
86 
87  VSCALE(ell->c, ell->c, sf);
88  break;
89  default:
90  bu_vls_printf(gedp->ged_result_str, "bad ell attribute - %s", attribute);
91  return GED_ERROR;
92  }
93 
94  return GED_OK;
95 }
96 
97 
98 /*
99  * Local Variables:
100  * tab-width: 8
101  * mode: C
102  * indent-tabs-mode: t
103  * c-file-style: "stroustrup"
104  * End:
105  * ex: shiftwidth=4 tabstop=8
106  */
#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_ell(struct ged *gedp, struct rt_ell_internal *ell, const char *attribute, fastf_t sf, int rflag)
Definition: scale_ell.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