BRL-CAD
scale_hyp.c
Go to the documentation of this file.
1 /* S C A L E _ H Y P . 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_hyp.c
21  *
22  * The scale_hyp 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_hyp(struct ged *gedp, struct rt_hyp_internal *hyp, const char *attribute, fastf_t sf, int rflag)
39 {
40  fastf_t f;
41  point_t old_top;
42 
43  RT_HYP_CK_MAGIC(hyp);
44 
45  switch (attribute[0]) {
46  case 'h':
47  case 'H':
48  if (!rflag)
49  sf /= MAGNITUDE(hyp->hyp_Hi);
50 
51  switch (attribute[1]) {
52  case '\0':
53  VSCALE(hyp->hyp_Hi, hyp->hyp_Hi, sf);
54  break;
55  case 'v':
56  case 'V':
57  /* Scale H move V */
58  VADD2(old_top, hyp->hyp_Vi, hyp->hyp_Hi);
59  VSCALE(hyp->hyp_Hi, hyp->hyp_Hi, sf);
60  VSUB2(hyp->hyp_Vi, old_top, hyp->hyp_Hi);
61 
62  break;
63  default:
64  bu_vls_printf(gedp->ged_result_str, "bad hyp attribute - %s", attribute);
65  return GED_ERROR;
66  }
67  break;
68  case 'a':
69  case 'A':
70  if (!rflag)
71  sf /= MAGNITUDE(hyp->hyp_A);
72 
73  VSCALE(hyp->hyp_A, hyp->hyp_A, sf);
74  break;
75  case 'b':
76  case 'B':
77  if (rflag)
78  hyp->hyp_b *= sf;
79  else
80  hyp->hyp_b = sf;
81 
82  break;
83  case 'c':
84  case 'C':
85  if (rflag)
86  f = hyp->hyp_bnr * sf;
87  else
88  f = sf;
89 
90  if (f <= 1.0)
91  hyp->hyp_bnr = f;
92 
93  break;
94  default:
95  bu_vls_printf(gedp->ged_result_str, "bad hyp attribute - %s", attribute);
96  return GED_ERROR;
97  }
98 
99  return GED_OK;
100 }
101 
102 
103 /*
104  * Local Variables:
105  * tab-width: 8
106  * mode: C
107  * indent-tabs-mode: t
108  * c-file-style: "stroustrup"
109  * End:
110  * ex: shiftwidth=4 tabstop=8
111  */
#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_hyp(struct ged *gedp, struct rt_hyp_internal *hyp, const char *attribute, fastf_t sf, int rflag)
Definition: scale_hyp.c:38
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