Language: C++

#ifndef ___Geometry_Library
#define ___Geometry_Library

// ------ Includes ------ //
#include <cmath>
#include <vector>
#include <complex>
#include <utility>
#include <algorithm>

// ------ Defines ------ //
typedef long double GType;
typedef std::complex<GType> Point;
typedef std::pair<Point, Point> Segment;

// ------ Constants ------ //
const GType EPS = 1.0e-10L;

// ------ Functions Level 1 ------ //
GType dot(const Point& p1, const Point& p2) {
	return (std::conj(p1) * p2).real();
}
GType cross(const Point& p1, const Point& p2) {
	return (std::conj(p1) * p2).imag();
}
int ccw(const Point& p1, const Point& p2, const Point& p3) {
	Point v1 = p2 - p1, v2 = p3 - p1;
	if (cross(v1, v2) > EPS) return +1;
	if (cross(v1, v2) < -EPS) return -1;
	if (dot(v1, v2) < -EPS) return +2;
	if (std::norm(v1) < std::norm(v2)) return -2;
	return 0;
}

// ------ Functions Level 2 ------ //
bool intersect(const Segment& s1, const Point& p1, bool segflag) {
	if (!segflag) return std::abs(cross(s1.second - p1, s1.first - p1)) < EPS;
	return (std::abs(s1.first - p1) + std::abs(s1.second - p1) - std::abs(s1.second - s1.first)) < EPS;
}
bool intersect(const Segment& s1, const Segment& s2, bool segflag) {
	if (!segflag) return cross(s1.second - s1.first, s2.first - s1.first) * cross(s1.second - s1.first, s2.second - s1.first) < EPS;
	return (ccw(s1.first, s1.second, s2.first) * ccw(s1.first, s1.second, s2.second) <= 0 && ccw(s2.first, s2.second, s1.first) * ccw(s2.first, s2.second, s1.second) <= 0);
}
GType distance(const Segment& s1, const Point& p1, bool segflag) {
	if (!segflag) return std::abs(p1 - projection(s1, p1));
	const Point p2 = projection(s1, p1);
	if (intersect(s1, p2, true)) return std::abs(p2 - p1);
	return std::min(std::abs(s1.first - p1), std::abs(s1.second - p1));
}
GType distance(const Segment& s1, const Segment& s2, bool segflag) {
	if (intersect(s1, s2, segflag)) return 0;
	if (!segflag) return std::min(distance(s1, s2.first, false), distance(s1, s2.second, false));
	return std::min({ distance(s1, s2.first, true), distance(s1, s2.second, true), distance(s2, s1.first, true), distance(s2, s1.second, true) });
}
Point crosspoint(const Segment& s1, const Segment& s2) {
	GType r1 = cross(s1.second - s1.first, s2.second - s2.first);
	GType r2 = cross(s1.second - s1.first, s1.second - s2.first);
	if (std::abs(r1) < EPS && std::abs(r2) < EPS) return s2.first;
	return s2.first + r2 / r1 * (s2.second - s2.first);
}

#endif

struct equal_point {
	bool operator()(const Point& p1, const Point& p2) const {
		return abs(p1 - p2) <= EPS;
	}
};
struct sorter {
	bool operator()(const Point& p1, const Point& p2) const {
		if (abs(p1.real() - p2.real() > EPS)) return p1.real() < p2.real();
		return p1.imag() < p2.imag();
	}
};

#include <vector>
#include <iostream>
using namespace std;
int n; double ax, ay, bx, by;
int main() {
	while (cin >> n, n) {
		vector<Segment> v(n);
		v.push_back(Segment(Point(-100, -100), Point(-100, 100)));
		v.push_back(Segment(Point(-100, 100), Point(100, 100)));
		v.push_back(Segment(Point(100, 100), Point(100, -100)));
		v.push_back(Segment(Point(100, -100), Point(-100, -100)));
		for (int i = 0; i < n; i++) {
			cin >> ax >> ay >> bx >> by;
			v[i] = Segment(Point(ax, ay), Point(bx, by));
		}
		vector<Point> res;
		vector<vector<Point> > part(v.size());
		for (int i = 0; i < v.size(); i++) {
			for (int j = i + 1; j < v.size(); j++) {
				if (distance(v[i], v[j], true) <= EPS) {
					res.push_back(crosspoint(v[i], v[j]));
					part[i].push_back(crosspoint(v[i], v[j]));
					part[j].push_back(crosspoint(v[i], v[j]));
				}
			}
		}
		sort(res.begin(), res.end(), sorter());
		res.erase(unique(res.begin(), res.end(), equal_point()), res.end());
		int ret = -(int)res.size();
		for (int i = 0; i < v.size(); i++) {
			sort(part[i].begin(), part[i].end(), sorter());
			part[i].erase(unique(part[i].begin(), part[i].end(), equal_point()), part[i].end());
			ret += part[i].size() - 1;
		}
		cout << ret + 1 << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'GType distance(const Segment&, const Point&, bool)':
a.cc:45:44: error: 'projection' was not declared in this scope
   45 |         if (!segflag) return std::abs(p1 - projection(s1, p1));
      |                                            ^~~~~~~~~~
a.cc:46:26: error: 'projection' was not declared in this scope
   46 |         const Point p2 = projection(s1, p1);
      |                          ^~~~~~~~~~