% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
\PassOptionsToPackage{dvipsnames,svgnames,x11names}{xcolor}
%
\documentclass[
]{article}
\usepackage{amsmath,amssymb}
\usepackage{iftex}
\ifPDFTeX
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else
% xetex/luatex font selection
\setmainfont[]{Calibri}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
% Make \paragraph and \subparagraph free-standing
\makeatletter
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}{
\@ifstar
\xxxParagraphStar
\xxxParagraphNoStar
}
\newcommand{\xxxParagraphStar}[1]{\oldparagraph*{#1}\mbox{}}
\newcommand{\xxxParagraphNoStar}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}{
\@ifstar
\xxxSubParagraphStar
\xxxSubParagraphNoStar
}
\newcommand{\xxxSubParagraphStar}[1]{\oldsubparagraph*{#1}\mbox{}}
\newcommand{\xxxSubParagraphNoStar}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
\makeatother
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{241,243,245}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.40,0.45,0.13}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\BuiltInTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\ExtensionTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.28,0.35,0.67}{#1}}
\newcommand{\ImportTok}[1]{\textcolor[rgb]{0.00,0.46,0.62}{#1}}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.68,0.00,0.00}{#1}}
\newcommand{\RegionMarkerTok}[1]{\textcolor[rgb]{0.00,0.23,0.31}{#1}}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.07,0.07,0.07}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.13,0.47,0.30}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.37,0.37,0.37}{\textit{#1}}}
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}\usepackage{longtable,booktabs,array}
\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\usepackage{graphicx}
\makeatletter
\newsavebox\pandoc@box
\newcommand*\pandocbounded[1]{% scales image to fit in text height/width
\sbox\pandoc@box{#1}%
\Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}%
\Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}%
\ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both
\ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}%
\else\usebox{\pandoc@box}%
\fi%
}
% Set default figure placement to htbp
\def\fps@figure{htbp}
\makeatother
\makeatletter
\@ifpackageloaded{caption}{}{\usepackage{caption}}
\AtBeginDocument{%
\ifdefined\contentsname
\renewcommand*\contentsname{Table of contents}
\else
\newcommand\contentsname{Table of contents}
\fi
\ifdefined\listfigurename
\renewcommand*\listfigurename{List of Figures}
\else
\newcommand\listfigurename{List of Figures}
\fi
\ifdefined\listtablename
\renewcommand*\listtablename{List of Tables}
\else
\newcommand\listtablename{List of Tables}
\fi
\ifdefined\figurename
\renewcommand*\figurename{Figure}
\else
\newcommand\figurename{Figure}
\fi
\ifdefined\tablename
\renewcommand*\tablename{Table}
\else
\newcommand\tablename{Table}
\fi
}
\@ifpackageloaded{float}{}{\usepackage{float}}
\floatstyle{ruled}
\@ifundefined{c@chapter}{\newfloat{codelisting}{h}{lop}}{\newfloat{codelisting}{h}{lop}[chapter]}
\floatname{codelisting}{Listing}
\newcommand*\listoflistings{\listof{codelisting}{List of Listings}}
\makeatother
\makeatletter
\makeatother
\makeatletter
\@ifpackageloaded{caption}{}{\usepackage{caption}}
\@ifpackageloaded{subcaption}{}{\usepackage{subcaption}}
\makeatother
\usepackage{bookmark}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same} % disable monospaced font for URLs
\hypersetup{
pdftitle={Exercise SW03},
pdfauthor={Matteo Frongillo},
colorlinks=true,
linkcolor={blue},
filecolor={Maroon},
citecolor={Blue},
urlcolor={Blue},
pdfcreator={LaTeX via pandoc}}
\title{Exercise SW03}
\author{Matteo Frongillo}
\date{2025-03-11}
\begin{document}
\maketitle
\subsection{Introduction}\label{introduction}
In this document, we will explore the implementation of two geometric
shapes, Rectangle and Circle, using Python. We will discuss the theory
behind these shapes and how they are implemented in the
\texttt{programm.py} file.
\subsection{Theory}\label{theory}
\subsubsection{Circle}\label{circle}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{import matplotlib.pyplot as plt}
\NormalTok{import math}
\NormalTok{class Circle:}
\NormalTok{ def \_\_init\_\_(self, color, xPos, yPos, radius): \#constructor}
\NormalTok{ self.color = color}
\NormalTok{ self.xPos = xPos}
\NormalTok{ self.yPos = yPos}
\NormalTok{ self.radius = radius}
\NormalTok{ def resize(self, size):}
\NormalTok{ self.radius *= size}
\NormalTok{ return "New radius: ", self.radius}
\NormalTok{ def get\_origin(self):}
\NormalTok{ return (self.xPos, self.yPos)}
\NormalTok{ def set\_origin(self, x, y):}
\NormalTok{ self.xPos = x}
\NormalTok{ self.yPos = y}
\NormalTok{ def draw(self):}
\NormalTok{ print(f"Circle: color=\{self.color\}, center=(\{self.xPos\}, \{self.yPos\}), radius=\{self.radius\}")}
\NormalTok{ fig, ax = plt.subplots()}
\NormalTok{ circle = plt.Circle((self.xPos, self.yPos), self.radius, color=self.color, fill=False)}
\NormalTok{ ax.add\_patch(circle)}
\NormalTok{ ax.set\_aspect(\textquotesingle{}equal\textquotesingle{}, adjustable=\textquotesingle{}box\textquotesingle{})}
\NormalTok{ ax.set\_xlim(self.xPos {-} self.radius {-} 1, self.xPos + self.radius + 1)}
\NormalTok{ ax.set\_ylim(self.yPos {-} self.radius {-} 1, self.yPos + self.radius + 1)}
\NormalTok{ ax.axhline(y=0, color=\textquotesingle{}k\textquotesingle{})}
\NormalTok{ ax.axvline(x=0, color=\textquotesingle{}k\textquotesingle{})}
\NormalTok{ ax.plot(self.xPos, self.yPos, \textquotesingle{}ro\textquotesingle{}) \# red dot at the center}
\NormalTok{ plt.grid(True)}
\NormalTok{ plt.show()}
\NormalTok{ def area(self):}
\NormalTok{ area = round(self.radius**2*math.pi,2)}
\NormalTok{ return area}
\end{Highlighting}
\end{Shaded}
\subsubsection{Rectangle}\label{rectangle}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{import matplotlib.pyplot as plt}
\NormalTok{import math}
\NormalTok{class Rectangle:}
\NormalTok{ def \_\_init\_\_(self, color, xPos, yPos, width, height): \#constructor}
\NormalTok{ self.color = color}
\NormalTok{ self.xPos = xPos}
\NormalTok{ self.yPos = yPos}
\NormalTok{ self.width = width}
\NormalTok{ self.height = height}
\NormalTok{ def resize(self, size):}
\NormalTok{ self.width *= size}
\NormalTok{ self.height *= size}
\NormalTok{ return "New width: ", self.width, "New height: ", self.height}
\NormalTok{ def get\_origin(self):}
\NormalTok{ return (self.xPos, self.yPos)}
\NormalTok{ def set\_origin(self, x, y):}
\NormalTok{ self.xPos = x}
\NormalTok{ self.yPos = y}
\NormalTok{ def draw(self):}
\NormalTok{ print(f"Rectangle: color=\{self.color\}, origin=(\{self.xPos\}, \{self.yPos\}), width=\{self.width\}, height=\{self.height\}")}
\NormalTok{ fig, ax = plt.subplots()}
\NormalTok{ rectangle = plt.Rectangle((self.xPos, self.yPos), self.width, self.height, color=self.color, fill=False)}
\NormalTok{ ax.add\_patch(rectangle)}
\NormalTok{ ax.set\_aspect(\textquotesingle{}equal\textquotesingle{}, adjustable=\textquotesingle{}box\textquotesingle{})}
\NormalTok{ ax.set\_xlim(self.xPos {-} 1, self.xPos + self.width + 1)}
\NormalTok{ ax.set\_ylim(self.yPos {-} 1, self.yPos + self.height + 1)}
\NormalTok{ ax.axhline(y=0, color=\textquotesingle{}k\textquotesingle{})}
\NormalTok{ ax.axvline(x=0, color=\textquotesingle{}k\textquotesingle{})}
\NormalTok{ ax.plot(self.xPos, self.yPos, \textquotesingle{}ro\textquotesingle{}) \# red dot at the origin}
\NormalTok{ plt.grid(True)}
\NormalTok{ plt.show()}
\NormalTok{ def area(self):}
\NormalTok{ area = round(self.width*self.height,2)}
\NormalTok{ return area}
\end{Highlighting}
\end{Shaded}
\section{Implementations}\label{implementations}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{from circle import Circle}
\NormalTok{from rectangle import Rectangle}
\NormalTok{def test\_shapes():}
\NormalTok{ \# Test Rectangle}
\NormalTok{ rect = Rectangle("blue", 0, 0, 10, 5)}
\NormalTok{ print("Rectangle Area:", rect.area())}
\NormalTok{ rect.draw()}
\NormalTok{ rect.resize(2)}
\NormalTok{ print("Resized Rectangle Area:", rect.area())}
\NormalTok{ rect.set\_origin(5, 5)}
\NormalTok{ print("Rectangle New Origin:", rect.get\_origin())}
\NormalTok{ rect.draw()}
\NormalTok{ \# Test Circle}
\NormalTok{ circ = Circle("red", 0, 0, 5)}
\NormalTok{ print("Circle Area:", circ.area())}
\NormalTok{ circ.draw()}
\NormalTok{ circ.resize(2)}
\NormalTok{ print("Resized Circle Area:", circ.area())}
\NormalTok{ circ.set\_origin(5, 5)}
\NormalTok{ print("Circle New Origin:", circ.get\_origin())}
\NormalTok{ circ.draw()}
\NormalTok{test\_shapes()}
\end{Highlighting}
\end{Shaded}
\end{document}