pcb 4.1.1
An interactive printed circuit board layout editor.

intersect.c File Reference

Rectangle intersection/union routines. More...

#include "global.h"
#include <assert.h>
#include "data.h"
#include "intersect.h"
#include "mymem.h"
Include dependency graph for intersect.c:

Go to the source code of this file.

Data Structures

struct  SegmentTreeNode
struct  SegmentTree
struct  LocationList

Functions

static int compareleft (const void *ptr1, const void *ptr2)
static int compareright (const void *ptr1, const void *ptr2)
static int comparepos (const void *ptr1, const void *ptr2)
static int nextpwrof2 (int i)
static LocationList createSortedYList (BoxListType *boxlist)
 Create a sorted list of unique y coords from a BoxList.
static SegmentTree createSegmentTree (Coord *yCoords, int N)
 Create an empty segment tree from the given sorted list of unique y coords.
void insertSegment (SegmentTree *st, int n, Coord Y1, Coord Y2)
void deleteSegment (SegmentTree *st, int n, Coord Y1, Coord Y2)
double ComputeIntersectionArea (BoxListType *boxlist)
 Compute the area of the intersection of the given rectangles.
double ComputeUnionArea (BoxListType *boxlist)
 Compute the area of the union of the given rectangles.

Detailed Description

Rectangle intersection/union routines.

Author:
this file, intersect.c, was written and is Copyright (c) 2001 C. Scott Ananian.

Copyright.


PCB, interactive printed circuit board design Copyright (C) 1994,1995,1996 Thomas Nau Copyright (C) 1998,1999,2000,2001 harry eaton

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Contact addresses for paper mail and Email: harry eaton, 6697 Buttonhole Ct, Columbia, MD 21044 USA haceaton@aplcomm.jhuapl.edu

Definition in file intersect.c.


Function Documentation

static int compareleft ( const void *  ptr1,
const void *  ptr2 
) [static]

Definition at line 291 of file intersect.c.

References BoxType::X1.

Referenced by ComputeUnionArea().

static int comparepos ( const void *  ptr1,
const void *  ptr2 
) [static]

Definition at line 307 of file intersect.c.

Referenced by createSortedYList().

static int compareright ( const void *  ptr1,
const void *  ptr2 
) [static]

Definition at line 299 of file intersect.c.

References BoxType::X2.

Referenced by ComputeUnionArea().

double ComputeIntersectionArea ( BoxListType boxlist)

Compute the area of the intersection of the given rectangles.

That is the area covered by more than one rectangle (counted twice if the area is covered by three rectangles, three times if covered by four rectangles, etc.).

Note:
Runs in O(N ln N) time.

Definition at line 203 of file intersect.c.

References BoxListType::Box, BoxListType::BoxN, ComputeUnionArea(), BoxType::X1, BoxType::X2, BoxType::Y1, and BoxType::Y2.

Referenced by ComputeCost().

Here is the call graph for this function:

double ComputeUnionArea ( BoxListType boxlist)

Compute the area of the union of the given rectangles.

Note:
Runs in O(N ln N) time.

Definition at line 221 of file intersect.c.

References SegmentTreeNode::area, BoxListType::Box, BoxListType::BoxN, compareleft(), compareright(), createSegmentTree(), createSortedYList(), deleteSegment(), insertSegment(), lastX, SegmentTree::nodes, LocationList::p, LocationList::size, BoxType::X1, BoxType::X2, BoxType::Y1, and BoxType::Y2.

Referenced by ComputeIntersectionArea().

Here is the call graph for this function:

static SegmentTree createSegmentTree ( Coord yCoords,
int  N 
) [static]

Create an empty segment tree from the given sorted list of unique y coords.

Definition at line 118 of file intersect.c.

References SegmentTreeNode::left, nextpwrof2(), SegmentTree::nodes, SegmentTreeNode::right, and SegmentTree::size.

Referenced by ComputeUnionArea().

Here is the call graph for this function:

static LocationList createSortedYList ( BoxListType boxlist) [static]

Create a sorted list of unique y coords from a BoxList.

Definition at line 90 of file intersect.c.

References BoxListType::Box, BoxListType::BoxN, comparepos(), n, LocationList::p, LocationList::size, BoxType::Y1, and BoxType::Y2.

Referenced by ComputeUnionArea().

Here is the call graph for this function:

void deleteSegment ( SegmentTree st,
int  n,
Coord  Y1,
Coord  Y2 
)
void insertSegment ( SegmentTree st,
int  n,
Coord  Y1,
Coord  Y2 
)
static int nextpwrof2 ( int  i) [static]

Definition at line 313 of file intersect.c.

Referenced by createSegmentTree().