Skip to content

Commit

Permalink
Remove display of vector components
Browse files Browse the repository at this point in the history
- Removed 'ScreenFacade.draw_dashed_line()' method
- Removed 'PlottingConfiguration.show_vector_values',
  'PlottingConfiguration.vector_values_line_color' and
  'PlottingConfiguration.vector_values_line_width' attributes.
  • Loading branch information
dylannalex committed Dec 31, 2022
1 parent c74b5fc commit c380c79
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 123 deletions.
19 changes: 2 additions & 17 deletions curvipy/_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(

class PlottingConfiguration:
"""Defines the configuration for plotting curves and vectors.
Parameters
----------
plotting_speed : int
Expand All @@ -57,14 +57,6 @@ class PlottingConfiguration:
Vector width. Defaults to 3.
vector_head_size : int
Size of vectors' head. Defaults to 10.
show_vector_values : bool
When True, vector head and tail values are shown on the axes. Defaults to True.
vector_values_line_color : str
Color of the dashed line drawn from the vector head and tail to the axes when \
`show_vector_values` is set to True. Defaults to "#70CBCE".
vector_values_line_width : int
Width of the dashed line drawn from the vector head and tail to the axes. when \
`show_vector_values` is set to True. Defaults to 3.
"""

def __init__(
Expand All @@ -75,9 +67,6 @@ def __init__(
vector_color: str = "#E63946",
vector_width: int = 3,
vector_head_size: int = 10,
show_vector_values: bool = True,
vector_values_line_color: str = "#70CBCE",
vector_values_line_width: int = 3,
):
# General attributes
self.plotting_speed = plotting_speed
Expand All @@ -90,9 +79,6 @@ def __init__(
self.vector_color = vector_color
self.vector_width = vector_width
self.vector_head_size = vector_head_size
self.show_vector_values = show_vector_values
self.vector_values_line_color = vector_values_line_color
self.vector_values_line_width = vector_values_line_width


class AxesConfiguration:
Expand Down Expand Up @@ -438,8 +424,7 @@ def plot_vector(self, vector: _Vector) -> None:
# reflect the real coordinates on screen of the vector.
#
# TODO:
# - Display vector components when `PlottingConfiguration.show_vector_values`
# equals True.
# - Display vector components

# Check if vector is the cero vector (v = [0, 0])
if not vector.norm:
Expand Down
107 changes: 1 addition & 106 deletions curvipy/_screen.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import turtle as _turtle

from math import sqrt as _sqrt
from math import sin as _sin
from math import cos as _cos
from math import pi as _pi
Expand Down Expand Up @@ -174,112 +175,6 @@ def draw_line(
rend_point = self.get_real_point(end_point)
self.goto_drawing(rend_point, drawing_speed)

def draw_dashed_line(
self,
start_point: _TLogicalPoint,
end_point: _TLogicalPoint,
total_dashes: int,
dash_size: int,
line_width: int,
line_color: str,
drawing_speed: int,
) -> None:
"""Draws a dashed line from start position to end position.
Parameters
----------
start_point : tuple[int or float, int or float]
Logical position at which the dashed line starts. `start_point` \
is translated to a real position.
end_point : tuple[int or float, int or float]
Logical position at which the dashed line ends. `end_point` \
is translated to a real position.
total_dashes: int
Positive integer. Number of dashes on the line.
dash_size : int
Positive integer.
line_width : int
Line width.
line_color : str
Line color.
drawing_speed : int
Drawing speed. Integer from 1 to 10.
"""
# Pen setup
if line_width != self.__pen_width_cache:
self.__pen.width(line_width)
self.__pen_width_cache = line_width

if line_color != self.__pen_color_cache:
self.__pen.color(line_color)
self.__pen_color_cache = line_color
print(
start_point,
end_point,
total_dashes,
dash_size,
line_width,
line_color,
drawing_speed,
)
# Variables
rstart_point = self.get_real_point(start_point)
rend_point = self.get_real_point(end_point)

# Calculate slope
if rstart_point == rend_point:
return
elif rstart_point[0] == rend_point[0]:
slope = "inf" # infinite (vertical line)
elif rstart_point[1] == rend_point[1]:
slope = 0
else:
dx = rend_point[0] - rstart_point[0]
dy = rend_point[1] - rstart_point[1]
slope = dy / dx

# Calculate line
if slope != "inf":
line = lambda t: (
t,
slope * t + (rstart_point[1] - rstart_point[0] * slope),
)
t0 = rstart_point[0]
dt = (rend_point[0] - rstart_point[0]) / total_dashes
else:
line = lambda t: (rstart_point[0], t)
t0 = rstart_point[1]
dt = (rend_point[1] - rstart_point[1]) / total_dashes

# Draw dashed line
for i in range(total_dashes):
x, y = line(t0 + dt * i)
if slope != "inf":
dash_start_point = (
x - dash_size,
y - dash_size * slope,
)
dash_end_point = (
x + dash_size,
y + dash_size * slope,
)
else:
dash_start_point = (
x,
y - dash_size,
)
dash_end_point = (
x,
y + dash_size,
)

self.__pen.up()
self.__pen.speed(__class__.MAX_DRAWING_SPEED)
self.__pen.goto(dash_start_point)
self.__pen.down()
self.__pen.speed(drawing_speed)
self.__pen.goto(dash_end_point)

def draw_polyline(
self,
points: list[_TLogicalPoint],
Expand Down

0 comments on commit c380c79

Please sign in to comment.