Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "segment.h"
- class Ray : public Segment {
- public:
- Ray(Point first, Point second)
- : Segment(
- std::move(first),
- std::move(second)
- ) {}
- virtual const Point getFirstPoint(const Painter& p) const override {
- return TwoPointFigure::getFirstPoint(p);
- }
- virtual const Point getSecondPoint(const Painter& painter) const override {
- const Point first = getFirstPoint(painter);
- int multiplier = std::numeric_limits<int>::max();
- if (delta.x < 0) {
- multiplier = std::min(
- multiplier,
- utils::ceiling(the_center.x, -delta.x)
- );
- }
- if (delta.x > 0) {
- multiplier = std::min(
- multiplier,
- utils::ceiling(painter.getWidth() - the_center.x, delta.x)
- );
- }
- if (delta.y < 0) {
- multiplier = std::min(
- multiplier,
- utils::ceiling(the_center.y, -delta.y)
- );
- }
- if (delta.y > 0) {
- multiplier = std::min(
- multiplier,
- utils::ceiling(painter.getHeight() - the_center.y, delta.y)
- );
- }
- return first + delta * multiplier;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement