File: touchtypes.c

package info (click to toggle)
magic 7.5.220-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 17,860 kB
file content (203 lines) | stat: -rw-r--r-- 5,536 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/* touchingtypes.c --
 *
 *     ********************************************************************* 
 *     * Copyright (C) 1985, 1990 Regents of the University of California. * 
 *     * Permission to use, copy, modify, and distribute this              * 
 *     * software and its documentation for any purpose and without        * 
 *     * fee is hereby granted, provided that the above copyright          * 
 *     * notice appear in all copies.  The University of California        * 
 *     * makes no representations about the suitability of this            * 
 *     * software for any purpose.  It is provided "as is" without         * 
 *     * express or implied warranty.  Export of this software outside     * 
 *     * of the United States of America may require an export license.    * 
 *     *********************************************************************
 *		      Lawrence Livermore National Laboratory
 *		      All rights reserved.
 *
 * Function to return mask of all tiletypes touching a given point. 
 */

#ifndef lint
static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-7.5/utils/touchtypes.c,v 1.1.1.1 2006/04/10 22:03:14 tim Exp $";
#endif /* not lint */

#include <stdio.h>

#include "utils/magic.h"
#include "utils/geometry.h"
#include "utils/geofast.h"
#include "tiles/tile.h"
#include "utils/hash.h"
#include "database/database.h"

/* ----------------------- Strucs local to this file ------------------- */

typedef struct touchingfuncparms
{
    Point 		tfp_point;
    TileTypeBitMask	tfp_types;
} TouchingFuncParms;


/*
 * ----------------------------------------------------------------------------
 *
 * TouchingTypes --
 * 
 * Generate mask of all types touching or covering a given point. 
 *
 * Results:
 *	Mask of all types touching or covering a given point in cellUse or
 *      expanded subcell.  If an unexpanded subcell is 
 *      covering or touching point TT_SUBCELL is included in the result as
 *	well.
 *
 * Side effects:
 *	None.
 *
 * ----------------------------------------------------------------------------
 */
TileTypeBitMask 
TouchingTypes(cellUse, expansionMask, point)
    CellUse *cellUse;
    int expansionMask;
    Point *point;
{
    int touchingTypesFunc();
    int touchingSubcellsFunc();
    TouchingFuncParms parms;
	    
    /* Search unit radius rectangle around point for paint tiles
     * (in cellUse or subcells expanded in cmd window) containing or 
     * touching point
     */
    {
	SearchContext scx;

	scx.scx_area.r_ll = *point;
	scx.scx_area.r_ur = *point;
	scx.scx_area.r_ll.p_x -= 1;
	scx.scx_area.r_ll.p_y -= 1;
	scx.scx_area.r_ur.p_x += 1;
	scx.scx_area.r_ur.p_y += 1;

	scx.scx_trans = GeoIdentityTransform;
	scx.scx_use = cellUse;

	parms.tfp_point = *point;
	TTMaskZero(&(parms.tfp_types));

	DBTreeSrTiles(
		      &scx,
		      &DBAllButSpaceAndDRCBits,
		      expansionMask,
		      touchingTypesFunc,
		      (ClientData) &parms);
    }

    /* Now check for presence of unexpanded subcells */
    {
	SearchContext scx;

	scx.scx_area.r_ll = *point;
	scx.scx_area.r_ur = *point;
	scx.scx_area.r_ll.p_x -= 1;
	scx.scx_area.r_ll.p_y -= 1;
	scx.scx_area.r_ur.p_x += 1;
	scx.scx_area.r_ur.p_y += 1;

	scx.scx_trans = GeoIdentityTransform;
	scx.scx_use = cellUse;
    
	DBTreeSrCells(
		      &scx,
		      expansionMask,
		      touchingSubcellsFunc,
		      (ClientData) &parms);
    }

    return(parms.tfp_types);
}


/*
 * ---------------------------------------------------------------------
 *
 * touchingTypesFunc --
 *
 * Called by DBTreeSrTiles on behalf of touchingTypes above, to check if
 * tile touches point.
 *
 * Results:
 *      Returns 0 to continue search.
 *
 * Side effects:
 *	Sets tile type in mask if tile touches point.
 *
 * ---------------------------------------------------------------------
 */

int
touchingTypesFunc(tile, cxp)
    Tile *tile;
    TreeContext *cxp;
{
    SearchContext *scx = cxp->tc_scx;
    Rect r, rDest;
    TouchingFuncParms *parms = (TouchingFuncParms *) (cxp->tc_filter->tf_arg);

    /* Transform to result coordinates */
    TITORECT(tile, &r);
    GEOCLIP(&r, &scx->scx_area);
    GEOTRANSRECT(&scx->scx_trans, &r, &rDest);

    if(GEO_ENCLOSE(&(parms->tfp_point), &rDest))
        TTMaskSetType(&(parms->tfp_types),TiGetType(tile));

    /* return 0 to continue search */
    return(0);
}


/*
 * ---------------------------------------------------------------------
 *
 * touchingSubcellsFunc --
 *
 * Called by DBTreeSrCells on behalf of touchingTypes above, to check if
 * subcell touches point.
 *
 * Results:
 *      Returns 0 if subcell doesn't touch point (to continue search)
 *	Returns 1 on match (to terminate search)
 *
 * Side effects:
 *	Sets TT_SUBCELL in mask if subcell touches point.
 *
 * ---------------------------------------------------------------------
 */

int
touchingSubcellsFunc(scx, cdarg)
    SearchContext *scx;
    ClientData cdarg;
{
    Rect r, rDest;
    TouchingFuncParms *parms = (TouchingFuncParms *) cdarg;

    /* Transform bounding box to result coordinates */
    r = scx->scx_use->cu_def->cd_bbox;
    GEOTRANSRECT(&scx->scx_trans, &r, &rDest);

    if(GEO_ENCLOSE(&(parms->tfp_point), &rDest))
    {
	/* touching subcell found, mark in types mask, and terminate search */
        TTMaskSetType(&(parms->tfp_types),TT_SUBCELL);
	return 1;	/* 1 = abort search */
    }
    else
    {
        /* subcell doesn't touch point after all, continue search */
        return 0;	/* 0 = continue search */
    }
}