MCPcopy Create free account
hub / github.com/SimHacker/micropolis / TkLineToArea

Function TkLineToArea

micropolis-activity/src/tk/tktrig.c:156–273  ·  view source on GitHub ↗
(end1Ptr, end2Ptr, rectPtr)

Source from the content-addressed store, hash-verified

154 *
155 *--------------------------------------------------------------
156 */
157
158int
159TkLineToArea(end1Ptr, end2Ptr, rectPtr)
160 double end1Ptr[2]; /* X and y coordinates for one endpoint
161 * of line. */
162 double end2Ptr[2]; /* X and y coordinates for other endpoint
163 * of line. */
164 double rectPtr[4]; /* Points to coords for rectangle, in the
165 * order x1, y1, x2, y2. X1 must be no
166 * larger than x2, and y1 no larger than y2. */
167{
168 int inside1, inside2;
169
170 /*
171 * First check the two points individually to see whether they
172 * are inside the rectangle or not.
173 */
174
175 inside1 = (end1Ptr[0] >= rectPtr[0]) && (end1Ptr[0] <= rectPtr[2])
176 && (end1Ptr[1] >= rectPtr[1]) && (end1Ptr[1] <= rectPtr[3]);
177 inside2 = (end2Ptr[0] >= rectPtr[0]) && (end2Ptr[0] <= rectPtr[2])
178 && (end2Ptr[1] >= rectPtr[1]) && (end2Ptr[1] <= rectPtr[3]);
179 if (inside1 != inside2) {
180 return 0;
181 }
182 if (inside1 & inside2) {
183 return 1;
184 }
185
186 /*
187 * Both points are outside the rectangle, but still need to check
188 * for intersections between the line and the rectangle. Horizontal
189 * and vertical lines are particularly easy, so handle them
190 * separately.
191 */
192
193 if (end1Ptr[0] == end2Ptr[0]) {
194 /*
195 * Vertical line.
196 */
197
198 if (((end1Ptr[1] >= rectPtr[1]) ^ (end2Ptr[1] >= rectPtr[1]))
199 && (end1Ptr[0] >= rectPtr[0])
200 && (end1Ptr[0] <= rectPtr[2])) {
201 return 0;
202 }
203 } else if (end1Ptr[1] == end2Ptr[1]) {
204 /*
205 * Horizontal line.
206 */
207
208 if (((end1Ptr[0] >= rectPtr[0]) ^ (end2Ptr[0] >= rectPtr[0]))
209 && (end1Ptr[1] >= rectPtr[1])
210 && (end1Ptr[1] <= rectPtr[3])) {
211 return 0;
212 }
213 } else {

Callers 2

ArcToAreaFunction · 0.85
TkPolygonToAreaFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected