Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
0 results Searching
Select Git revision
Loading items
Show changes

Commits on Source 6

35 files
+ 190
2976
Compare changes
  • Side-by-side
  • Inline

Files

GUI/ThreadSafeVector.h

0 → 100644
+45 −0
Original line number Diff line number Diff line
//
// Created by Ari Trachtenberg on 11/8/24.
//

#ifndef HW6_THREADSAFEVECTOR_H
#define HW6_THREADSAFEVECTOR_H
#include <vector>
#include <shared_mutex>
#include <mutex>
#include <stdexcept>

// A thread-safe vector, based on a ChatGPT response
template <typename T>
class ThreadSafeVector {
private:
    std::vector<T> vec;
    mutable std::shared_mutex mtx;  // `mutable` allows locking in const methods.

public:
    // Pushes an element to the back of the vector (exclusive lock for modification).
    void push_back(const T& value) {
        std::unique_lock<std::shared_mutex> lock(mtx);
        vec.push_back(value);
    }

    // Returns the size of the vector (shared lock for read access).
    size_t size() const {
        std::shared_lock<std::shared_mutex> lock(mtx);
        return vec.size();
    }

    // Accesses an element by index with bounds checking (shared lock for read access).
    T operator[](size_t index) const {
        std::shared_lock<std::shared_mutex> lock(mtx);
        return vec[index];
    }

    // Provides a thread-safe way to begin and end iterators (copy for safe iteration).
    std::vector<T> get_copy() const {
        std::shared_lock<std::shared_mutex> lock(mtx);
        return vec;  // Returns a copy of the vector.
    }
};

#endif //HW6_THREADSAFEVECTOR_H
+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ void draw::Window::_drawShapes() {
            }

            // draw shapes
            for (Shape *theShape: shapeList) {
            for (Shape *theShape: shapeList.get_copy()) {
                theShape->onInput(userInput);
                theShape->draw();
            }
+2 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include "../Shapes/Shape.h"
#include "../Shapes/Rect/Rect.h"
#include "../Shapes/AllDoneSensor.h"
#include "ThreadSafeVector.h"

using namespace std;

@@ -146,7 +147,7 @@ namespace draw {
        /**
         * A list of the shapes that are displayed on this Window.
         */
        vector<Shape *> shapeList;
        ThreadSafeVector<Shape *> shapeList;

        /**
         * The Thread used for drawing shapes.
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@
#define HW6_ANIMATED_H

/**
 * Represents an animated figure
 * An abstract class representing an animated figure.
 */
class Animated {
 public:
Original line number Diff line number Diff line
@@ -9,9 +9,13 @@
#include "El.h"

namespace draw {
/**
 * Represents an animated El shape.
 */
class AnimatedEl : public El, public Animated {
 public:
    explicit AnimatedEl(Color theColor, int theX1 = 0, int theY1 = 0, float theLen = 0, float theAngle = 0) : El(theColor, theX1, theY1, theLen, theAngle) {}
  explicit AnimatedEl(Color theColor, int theX1 = 0, int theY1 = 0, float theLen = 0, float theAngle = 0)
      : El(theColor, theX1, theY1, theLen, theAngle) {}

  void draw() override {
    update();
Original line number Diff line number Diff line
@@ -31,8 +31,8 @@ class BoundedMovingRotatingEl : virtual public MovingEl, virtual public Rotating
                          float theYVel = 3)
      :
      MovingEl(theColor, theX1, theY1, theLen, theAngle, theXVel, theYVel),
      RotatingEl(theColor, theX1, theY1, theLen, theAngle, theAngleVel),
      AnimatedEl(theColor, theX1, theY1, theLen, theAngle),
      RotatingEl(theColor, (int) theX1, (int) theY1, theLen, theAngle, theAngleVel),
      AnimatedEl(theColor, (int) theX1, (int) theY1, theLen, theAngle),
      myBounds(theBounds) {}

  void update() override {
Original line number Diff line number Diff line
@@ -19,7 +19,12 @@ class RotatingEl : virtual public AnimatedEl {
   * @param theAngVel angular velocity of the El, in radians / frame.
   * Note:  The variable {@link Window#FRAME_RATE} determines the number of frames per second.
   */
  explicit RotatingEl(Color theColor, int theX1 = 0, int theY1 = 0, float theLen = 0, float theAngle = 0, float theAngVel = 0.01)
  explicit RotatingEl(Color theColor,
                      int theX1 = 0,
                      int theY1 = 0,
                      float theLen = 0,
                      float theAngle = 0,
                      float theAngVel = 0.01)
      : AnimatedEl(theColor, theX1, theY1, theLen, theAngle), myAngVel(theAngVel) {}

  void update() override {
Original line number Diff line number Diff line
@@ -14,10 +14,14 @@ namespace draw {
 */
class RotatingSensingEl : public RotatingEl {
 public:
        RotatingSensingEl(Color theColor, int theX1 = 0, int theY1 = 0, float theLen = 0, float theAngle = 0, float theAngVel = 0.01):
  RotatingSensingEl(Color theColor,
                    int theX1 = 0,
                    int theY1 = 0,
                    float theLen = 0,
                    float theAngle = 0,
                    float theAngVel = 0.01) :
      RotatingEl(theColor, theX1, theY1, theLen, theAngle, theAngVel),
        AnimatedEl(theColor, theX1, theY1, theLen, theAngle)
        {}
      AnimatedEl(theColor, theX1, theY1, theLen, theAngle) {}

  /**
   * If the left mouse button is pressed, change the direction of the El's rotation
Original line number Diff line number Diff line
@@ -10,6 +10,10 @@
#include "../../DataStructures/Point.h"

namespace draw {

/**
 * Represents a rectangle shape.
 */
class Rect : public Line {
 public:
  /**

ci_cd/.gitlab-ci.yml

0 → 100644
+8 −0
Original line number Diff line number Diff line
stages:
  - noop

do_nothing:
  stage: noop
  script:
    - echo "This job does nothing"
  tags: [shell]
 No newline at end of file
Original line number Diff line number Diff line
set(CMAKE_C_COMPILER "/usr/bin/cc")
set(CMAKE_C_COMPILER_ARG1 "")
set(CMAKE_C_COMPILER_ID "GNU")
set(CMAKE_C_COMPILER_VERSION "8.5.0")
set(CMAKE_C_COMPILER_VERSION_INTERNAL "")
set(CMAKE_C_COMPILER_WRAPPER "")
set(CMAKE_C_STANDARD_COMPUTED_DEFAULT "17")
set(CMAKE_C_EXTENSIONS_COMPUTED_DEFAULT "ON")
set(CMAKE_C_COMPILE_FEATURES "c_std_90;c_function_prototypes;c_std_99;c_restrict;c_variadic_macros;c_std_11;c_static_assert;c_std_17")
set(CMAKE_C90_COMPILE_FEATURES "c_std_90;c_function_prototypes")
set(CMAKE_C99_COMPILE_FEATURES "c_std_99;c_restrict;c_variadic_macros")
set(CMAKE_C11_COMPILE_FEATURES "c_std_11;c_static_assert")
set(CMAKE_C17_COMPILE_FEATURES "c_std_17")
set(CMAKE_C23_COMPILE_FEATURES "")

set(CMAKE_C_PLATFORM_ID "Linux")
set(CMAKE_C_SIMULATE_ID "")
set(CMAKE_C_COMPILER_FRONTEND_VARIANT "")
set(CMAKE_C_SIMULATE_VERSION "")




set(CMAKE_AR "/usr/bin/ar")
set(CMAKE_C_COMPILER_AR "/usr/bin/gcc-ar")
set(CMAKE_RANLIB "/usr/bin/ranlib")
set(CMAKE_C_COMPILER_RANLIB "/usr/bin/gcc-ranlib")
set(CMAKE_LINKER "/usr/bin/ld")
set(CMAKE_MT "")
set(CMAKE_COMPILER_IS_GNUCC 1)
set(CMAKE_C_COMPILER_LOADED 1)
set(CMAKE_C_COMPILER_WORKS TRUE)
set(CMAKE_C_ABI_COMPILED TRUE)

set(CMAKE_C_COMPILER_ENV_VAR "CC")

set(CMAKE_C_COMPILER_ID_RUN 1)
set(CMAKE_C_SOURCE_FILE_EXTENSIONS c;m)
set(CMAKE_C_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC)
set(CMAKE_C_LINKER_PREFERENCE 10)

# Save compiler ABI information.
set(CMAKE_C_SIZEOF_DATA_PTR "8")
set(CMAKE_C_COMPILER_ABI "ELF")
set(CMAKE_C_BYTE_ORDER "LITTLE_ENDIAN")
set(CMAKE_C_LIBRARY_ARCHITECTURE "")

if(CMAKE_C_SIZEOF_DATA_PTR)
  set(CMAKE_SIZEOF_VOID_P "${CMAKE_C_SIZEOF_DATA_PTR}")
endif()

if(CMAKE_C_COMPILER_ABI)
  set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_C_COMPILER_ABI}")
endif()

if(CMAKE_C_LIBRARY_ARCHITECTURE)
  set(CMAKE_LIBRARY_ARCHITECTURE "")
endif()

set(CMAKE_C_CL_SHOWINCLUDES_PREFIX "")
if(CMAKE_C_CL_SHOWINCLUDES_PREFIX)
  set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_C_CL_SHOWINCLUDES_PREFIX}")
endif()





set(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES "/usr/lib/gcc/x86_64-redhat-linux/8/include;/usr/local/include;/usr/include")
set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "gcc;gcc_s;c;gcc;gcc_s")
set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "/usr/lib/gcc/x86_64-redhat-linux/8;/usr/lib64;/lib64;/usr/lib")
set(CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "")
Original line number Diff line number Diff line
set(CMAKE_CXX_COMPILER "/usr/bin/c++")
set(CMAKE_CXX_COMPILER_ARG1 "")
set(CMAKE_CXX_COMPILER_ID "GNU")
set(CMAKE_CXX_COMPILER_VERSION "8.5.0")
set(CMAKE_CXX_COMPILER_VERSION_INTERNAL "")
set(CMAKE_CXX_COMPILER_WRAPPER "")
set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT "14")
set(CMAKE_CXX_EXTENSIONS_COMPUTED_DEFAULT "ON")
set(CMAKE_CXX_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters;cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates;cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates;cxx_std_17;cxx_std_20")
set(CMAKE_CXX98_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters")
set(CMAKE_CXX11_COMPILE_FEATURES "cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates")
set(CMAKE_CXX14_COMPILE_FEATURES "cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates")
set(CMAKE_CXX17_COMPILE_FEATURES "cxx_std_17")
set(CMAKE_CXX20_COMPILE_FEATURES "cxx_std_20")
set(CMAKE_CXX23_COMPILE_FEATURES "")

set(CMAKE_CXX_PLATFORM_ID "Linux")
set(CMAKE_CXX_SIMULATE_ID "")
set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "")
set(CMAKE_CXX_SIMULATE_VERSION "")




set(CMAKE_AR "/usr/bin/ar")
set(CMAKE_CXX_COMPILER_AR "/usr/bin/gcc-ar")
set(CMAKE_RANLIB "/usr/bin/ranlib")
set(CMAKE_CXX_COMPILER_RANLIB "/usr/bin/gcc-ranlib")
set(CMAKE_LINKER "/usr/bin/ld")
set(CMAKE_MT "")
set(CMAKE_COMPILER_IS_GNUCXX 1)
set(CMAKE_CXX_COMPILER_LOADED 1)
set(CMAKE_CXX_COMPILER_WORKS TRUE)
set(CMAKE_CXX_ABI_COMPILED TRUE)

set(CMAKE_CXX_COMPILER_ENV_VAR "CXX")

set(CMAKE_CXX_COMPILER_ID_RUN 1)
set(CMAKE_CXX_SOURCE_FILE_EXTENSIONS C;M;c++;cc;cpp;cxx;m;mm;mpp;CPP;ixx;cppm)
set(CMAKE_CXX_IGNORE_EXTENSIONS inl;h;hpp;HPP;H;o;O;obj;OBJ;def;DEF;rc;RC)

foreach (lang C OBJC OBJCXX)
  if (CMAKE_${lang}_COMPILER_ID_RUN)
    foreach(extension IN LISTS CMAKE_${lang}_SOURCE_FILE_EXTENSIONS)
      list(REMOVE_ITEM CMAKE_CXX_SOURCE_FILE_EXTENSIONS ${extension})
    endforeach()
  endif()
endforeach()

set(CMAKE_CXX_LINKER_PREFERENCE 30)
set(CMAKE_CXX_LINKER_PREFERENCE_PROPAGATES 1)

# Save compiler ABI information.
set(CMAKE_CXX_SIZEOF_DATA_PTR "8")
set(CMAKE_CXX_COMPILER_ABI "ELF")
set(CMAKE_CXX_BYTE_ORDER "LITTLE_ENDIAN")
set(CMAKE_CXX_LIBRARY_ARCHITECTURE "")

if(CMAKE_CXX_SIZEOF_DATA_PTR)
  set(CMAKE_SIZEOF_VOID_P "${CMAKE_CXX_SIZEOF_DATA_PTR}")
endif()

if(CMAKE_CXX_COMPILER_ABI)
  set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_CXX_COMPILER_ABI}")
endif()

if(CMAKE_CXX_LIBRARY_ARCHITECTURE)
  set(CMAKE_LIBRARY_ARCHITECTURE "")
endif()

set(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX "")
if(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX)
  set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_CXX_CL_SHOWINCLUDES_PREFIX}")
endif()





set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "/usr/include/c++/8;/usr/include/c++/8/x86_64-redhat-linux;/usr/include/c++/8/backward;/usr/lib/gcc/x86_64-redhat-linux/8/include;/usr/local/include;/usr/include")
set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "stdc++;m;gcc_s;gcc;c;gcc_s;gcc")
set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "/usr/lib/gcc/x86_64-redhat-linux/8;/usr/lib64;/lib64;/usr/lib")
set(CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "")
Original line number Diff line number Diff line
set(CMAKE_HOST_SYSTEM "Linux-4.18.0-553.8.1.el8_10.x86_64")
set(CMAKE_HOST_SYSTEM_NAME "Linux")
set(CMAKE_HOST_SYSTEM_VERSION "4.18.0-553.8.1.el8_10.x86_64")
set(CMAKE_HOST_SYSTEM_PROCESSOR "x86_64")



set(CMAKE_SYSTEM "Linux-4.18.0-553.8.1.el8_10.x86_64")
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_VERSION "4.18.0-553.8.1.el8_10.x86_64")
set(CMAKE_SYSTEM_PROCESSOR "x86_64")

set(CMAKE_CROSSCOMPILING "FALSE")

set(CMAKE_SYSTEM_LOADED 1)
+0 −11
Original line number Diff line number Diff line
/ad/eng/linux/opt/JetBrain/2022.3/clion-2022.3.1/bin/cmake/linux/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" -S /home/trachten/CLionProjects/homework-six -B /home/trachten/CLionProjects/homework-six/cmake-build-debug
CMake Error at /ad/eng/linux/opt/JetBrain/2022.3/clion-2022.3.1/bin/cmake/linux/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find X11 (missing: X11_X11_INCLUDE_PATH X11_X11_LIB)
Call Stack (most recent call first):
  /ad/eng/linux/opt/JetBrain/2022.3/clion-2022.3.1/bin/cmake/linux/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  /ad/eng/linux/opt/JetBrain/2022.3/clion-2022.3.1/bin/cmake/linux/share/cmake-3.24/Modules/FindX11.cmake:481 (find_package_handle_standard_args)
  CMakeLists.txt:7 (find_package)


-- Configuring incomplete, errors occurred!
See also "/home/trachten/CLionProjects/homework-six/cmake-build-debug/CMakeFiles/CMakeOutput.log".
+0 −3
Original line number Diff line number Diff line
Start testing: Oct 30 22:21 EDT
----------------------------------------------------------
End testing: Oct 30 22:21 EDT

main.cpp

0 → 100644
+52 −0
Original line number Diff line number Diff line
//
// Created by Ari on 3/28/23.
//

#include <X11/X.h>
#include "GUI/Window.h"
#include "Shapes/Line.h"
#include "Shapes/Rect/Rect.h"
#include "Shapes/El/El.h"
#include "Shapes/El/RotatingEl.h"
#include "Shapes/El/MovingEl.h"
#include "Shapes/El/BoundedMovingRotatingEl.h"
#include "Shapes/El/RotatingSensingEl.h"
#include "Shapes/El/BlinkingMovingEl.h"

void example() {
    // Get an instance of the Window
    draw::Window& theWindow = draw::Window::getInstance();

    // Add your shapes

    /**
     * Add a red line from coordinate (10,10) to (200,200).
     */
    theWindow.addShape(new draw::Line(Color::Red, 10, 10, 200, 200));

    /**
     * Add a yellow rectangle denoted by the corner points at (20,30) and (40,50).
     */
    theWindow.addShape(new draw::Rect(Color::Yellow, 20,30,40,50));

    /**
     * Add a green L at the point (100,100), whose side has length 100 pixels.
     */
    theWindow.addShape(new draw::El(Color::Green, 100, 100, 100));

    theWindow.addShape( new draw::RotatingEl(Color::Purple, 200, 200, 50, 0, 0.03));
    theWindow.addShape( new draw::MovingEl(Color::Brown,0,75,30,5,1,1));
    theWindow.addShape( new draw::BoundedMovingRotatingEl( Color::Blue, theWindow.bounds, 150,150,100,0,0.01, 3,3));
    theWindow.addShape( new draw::RotatingSensingEl(Color::Orange, 300, 200, 70, 0, 0.1));
    theWindow.addShape( new draw::BlinkingMovingEl());
    // Wait for the user to exit
    draw::Window::WaitForAllDone();
}

void AddShapes() {
  // your code here
}

int main() {
    example();
}
 No newline at end of file