comparison nonfree/gpc/gpc_clip.cc @ 0:6b33357c7561 octave-forge

Initial revision
author pkienzle
date Wed, 10 Oct 2001 19:54:49 +0000
parents
children 731e0bfdb40c
comparison
equal deleted inserted replaced
-1:000000000000 0:6b33357c7561
1 /*
2
3 Copyright (C) 2001 Rafael Laboissiere
4
5 This file is part of octave-gpc.
6
7 octave-gpc is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
10 later version.
11
12 octave-gpc is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with octave-gpc; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
21 */
22
23 #include "octave-gpc.h"
24
25 // This is the user function for polygon operations
26 DEFUN_DLD (gpc_clip, args, ,
27 " SYNOPSIS:\n"
28 " result = gpc_clip (subject, clip, [operation]])\n"
29 "\n"
30 " DESCRIPTION:\n"
31 " Make an clipping operation between the SUBJECT and CLIP\n"
32 " arguments, which must be gpc_polygon objects. The OPERATION\n"
33 " argument must be one of \"DIFF\", \"INT\", \"XOR\", or\n"
34 " \"UNION\" (the default value is \"INT\").\n"
35 "\n"
36 " RESULT is the resulting gpc_polygon object.\n"
37 "\n"
38 " SEE ALSO:\n"
39 " The General Polygon Clipper Library documentation.\n"
40 " gpc_create, gpc_get, gpc_read, gpc_write,\n"
41 " gpc_is_polygon, gpc_plot.\n" )
42 {
43 octave_value retval;
44 gpc_op operation = GPC_INT;
45 gpc_polygon *subject, *clip, result;
46
47 // Sanity check of the arguments
48 int nargin = args.length ();
49
50 if (nargin < 2 || nargin > 3)
51 print_usage ("gpc_clip");
52 else
53 {
54 if ( nargin == 3 )
55 {
56 string op = args (2).string_value ();
57 if ( error_state )
58 {
59 error ("gpc_clip: operation argument should be a "
60 "string");
61 return retval;
62 }
63 else
64 {
65 if ( op == "DIFF" )
66 operation = GPC_DIFF;
67 else
68 if ( op == "INT" )
69 operation = GPC_INT;
70 else
71 if ( op == "XOR" )
72 operation = GPC_XOR;
73 else
74 if ( op == "UNION" )
75 operation = GPC_UNION;
76 else
77 {
78 error ("gpc_clip: operation argument must be "
79 "one of \"DIFF\", \"INT\", \"XOR\", or "
80 "\"UNION\"");
81 return retval;
82 }
83 }
84 }
85
86 if ( args(0).type_id () == octave_gpc_polygon::static_type_id () )
87 subject = get_gpc_pt (args(0));
88 else
89 {
90 error ("gpc_clip: subject argument must be of type "
91 "gpc_polygon");
92 return retval;
93 }
94
95 if ( args (1).type_id () == octave_gpc_polygon::static_type_id () )
96 clip = get_gpc_pt (args(1));
97 else
98 {
99 error ("gpc_clip: clip argument must be of type "
100 "gpc_polygon");
101 return retval;
102 }
103
104 gpc_polygon_clip (operation, subject, clip, &result);
105 Octave_map m;
106 gpc_to_map (&result, &m);
107 retval = octave_value (new octave_gpc_polygon (m));
108
109 // The result polygon must be freed by the C library function as
110 // it was created by gpc_polygon_clip.
111 gpc_free_polygon (&result);
112 }
113 return retval;
114 }
115
116 /*
117 ;;; Local Variables: ***
118 ;;; mode: C++ ***
119 ;;; End: ***
120 */