Category : Files from Magazines
Archive   : MICROCAD.ZIP
Filename : SHAPELST.CPP

 
Output of file : SHAPELST.CPP contained in archive : MICROCAD.ZIP
// Figure 12 for "A Little CAD with C++"
// Copyright 1988 Bruce Eckel
// Permission required to distribute source

// file: shapelst.cpp
#include "shapelst.hpp"

cadshape * shapelist::next() {
cadshape * r = current->shp;
if ( r != (cadshape *)0 )
current = current->next;
return r;
}

void shapelist::remove(cadshape * s) {
shapelist_element * pp = head, * qq;
if ( pp->shp == s) { // check head
head = pp->next;
delete pp;
} else
while ( pp->next->shp != 0 ) {
// (the next element isn't the last)
if ( pp->next->shp == s) {
// unlink the matching element:
qq = pp->next;
pp->next = pp->next->next;
delete qq;
return;
}
pp++;
}
}

// Find the nearest shape to co-ordinates (x,y) :
cadshape *
shapelist::nearest(unsigned x, unsigned y) {
cadshape * kk;
cadshape * cshape;
unsigned long distance;

reset(); // start at beginning of list
cshape = next(); // test the first element
distance = cshape->range(x,y);
while ((kk = next()) != 0) {
if ( kk->range(x,y) < distance ) {
cshape = kk;
distance = cshape->range(x,y);
}
}
return cshape;
}


  3 Responses to “Category : Files from Magazines
Archive   : MICROCAD.ZIP
Filename : SHAPELST.CPP

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/