luckYrat's library.

This documentation is automatically generated by competitive-verifier/competitive-verifier


:heavy_check_mark: cpp/geometry/line-segment.hpp

Depends on

Required by

Verified with

Code

#pragma once

#include "point.hpp"

struct LineSegment{
  Point first, second;
  LineSegment(Point a, Point b):first(a),second(b){}
};


#line 2 "cpp/geometry/line-segment.hpp"

#line 2 "cpp/geometry/vec.hpp"

struct Vec{
  long double x,y;
  Vec operator*(long double a){
    return {x*a, y*a};
  }
  Vec operator/(long double a){
    return {x/a, y/a};
  }

  friend ostream &operator<<(ostream &os, const Vec &p){
    return os << p.x << " " << p.y;
  }
};

long double magnitude(Vec v){
  return sqrt(v.x*v.x+v.y*v.y);
}

Vec standardize(Vec v){
  return v/magnitude(v);
}
#line 3 "cpp/geometry/point.hpp"

struct Point{
  long double x,y;

  Vec operator-(Point b){
    return {x-b.x, y-b.y};
  }
  Point operator+(long double a){
    return {x+a, y+a};
  }
  Point operator+(Vec v){
    return {x+v.x, y+v.y};
  }

  friend istream &operator>>(istream &is, Point &p){
    long double a,b;
    cin>>a>>b;
    p = Point({a,b});
    return (is);
  }

  friend ostream &operator<<(ostream &os, const Point &p){
    return os << p.x << " " << p.y;
  }

};
#line 4 "cpp/geometry/line-segment.hpp"

struct LineSegment{
  Point first, second;
  LineSegment(Point a, Point b):first(a),second(b){}
};


Back to top page