Skip to content

Commit

Permalink
Fix Ellipse and change header file ext
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangfitus committed Oct 30, 2023
1 parent 07cefa7 commit 5320258
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 41 deletions.
16 changes: 7 additions & 9 deletions src/Circle.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
#include "Circle.h"
#include "Circle.hpp"

#include <cmath>

Circle::Circle(float radius, float center_x, float center_y, sf::Color fill, sf::Color stroke, float stroke_thickness) : radius(radius)
{
Circle::Circle(float radius, float center_x, float center_y, sf::Color fill,
sf::Color stroke, float stroke_thickness)
: radius(radius) {
setPosition(center_x, center_y);
setFillColor(fill);
setOutlineColor(stroke);
setOutlineThickness(stroke_thickness);
update();
}

std::size_t Circle::getPointCount() const
{
return SCALE;
}
std::size_t Circle::getPointCount() const { return SCALE; }

sf::Vector2f Circle::getPoint(std::size_t index) const
{
sf::Vector2f Circle::getPoint(std::size_t index) const {
static const float pi = 3.141592654f;

float angle = index * 2 * pi / getPointCount() - pi / 2;
Expand Down
3 changes: 1 addition & 2 deletions src/Circle.h → src/Circle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#define CIRCLE_H_
#define SCALE 1000000

class Circle : public sf::Shape
{
class Circle : public sf::Shape {
private:
float radius;

Expand Down
21 changes: 7 additions & 14 deletions src/Ellipse.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
#include "Ellipse.h"
#include "Ellipse.hpp"

#include <cmath>

Ellipse::Ellipse(const sf::Vector2f &radius, float center_x, float center_y, sf::Color fill, sf::Color stroke, float stroke_thickness) : radius(radius)
{
setPosition(center_x, center_y);
setFillColor(fill);
setOutlineColor(stroke);
setOutlineThickness(stroke_thickness);
Ellipse::Ellipse(const sf::Vector2f &radius, float center_x, float center_y,
sf::Color fill, sf::Color stroke, float stroke_thickness)
: Circle(1.f, center_x, center_y, fill, stroke, stroke_thickness),
radius(radius) {
update();
}

std::size_t Ellipse::getPointCount() const
{
return SCALE;
}

sf::Vector2f Ellipse::getPoint(std::size_t index) const
{
sf::Vector2f Ellipse::getPoint(std::size_t index) const {
static const float pi = 3.141592654f;

float angle = index * 2 * pi / getPointCount() - pi / 2;
Expand Down
16 changes: 0 additions & 16 deletions src/Ellipse.h

This file was deleted.

15 changes: 15 additions & 0 deletions src/Ellipse.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "Circle.hpp"
#ifndef ELLIPSE_H_
#define ELLIPSE_H_

class Ellipse : public Circle {
private:
sf::Vector2f radius;

public:
Ellipse(const sf::Vector2f &radius, float center_x, float center_y,
sf::Color fill, sf::Color stroke, float stroke_thickness);
virtual sf::Vector2f getPoint(std::size_t index) const override;
};

#endif

0 comments on commit 5320258

Please sign in to comment.