Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "_socha"
version = "5.1.0"
version = "5.1.1"
edition = "2021"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "maturin"

[project]
name = "socha"
version = "5.1.0"
version = "5.1.1"
authors = [
{ name = "yoente", email = "stu250140@mail.uni-kiel.de" },
{ name = "maxblan", email = "stu222782@mail.uni-kiel.de" },
Expand Down
28 changes: 12 additions & 16 deletions python/socha/_socha.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,60 @@ from enum import Enum

class Vector:
"""
Ein 2 dimensionaler Vektor.
Ein 2 dimensionaler Vektor. (unveränderbar)

Attributes:
delta_x (int): Die Entfernung in x-Richtung.
delta_y (int): Die Entfernung in y-Richtung.
"""

delta_x: int
delta_y: int
@property
def delta_x(self) -> int: ...
@property
def delta_y(self) -> int: ...

def __init__(self, delta_x: int, delta_y: int) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
def __hash__(self) -> int: ...

def deepcopy(self) -> Vector:
"""Kopiert das Objekt."""

def add_vector(self, other: Vector) -> Vector:
"""Addiert einen anderen Vector (nicht mutierend)."""

def add_vector_mut(self, other: Vector) -> None:
"""Addiert einen anderen Vector (mutierend)."""

def scale(self, scalar: int) -> Vector:
"""Skaliert diesen Vektor (nicht mutierend)."""

def scale_mut(self, scalar: int) -> None:
"""Skaliert diesen Vektor (mutierend)."""

def get_length(self) -> float | None:
"""Berechnet die Länge dieses Vektors."""


class Coordinate:
"""
Eine 2 dimensionale Koordinate auf einem Spielfeld.
Eine 2 dimensionale Koordinate auf einem Spielfeld. (unveränderbar)

Attributes:
x (int): Der x-Wert.
y (int): Der y-Wert.
"""

x: int
y: int
@property
def x(self) -> int: ...
@property
def y(self) -> int: ...

def __init__(self, x: int, y: int) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
def __hash__(self) -> int: ...

def deepcopy(self) -> Coordinate:
"""Kopiert das Objekt."""

def add_vector(self, vector: Vector) -> Coordinate:
"""Addiert einen Vector auf diese Koordinate (nicht mutierend)."""

def add_vector_mut(self, vector: Vector) -> None:
"""Addiert einen Vector auf diese Koordinate (mutierend)."""

def get_difference(self, other: Coordinate) -> Vector:
"""Berechnet die Differenz zwischen zwei Koordinaten als Vektor."""

Expand Down
10 changes: 5 additions & 5 deletions src/plugin2027/piece.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use crate::plugin2027::{
#[pyclass(from_py_object)]
#[derive(Debug, Clone)]
pub struct Piece {
#[pyo3(get, set)]
#[pyo3(get)]
pub color: Color,
#[pyo3(get, set)]
#[pyo3(get)]
pub kind: PieceShape,
#[pyo3(get, set)]
#[pyo3(get)]
pub rotation: Rotation,
#[pyo3(get, set)]
#[pyo3(get)]
pub is_flipped: bool,
#[pyo3(get, set)]
#[pyo3(get)]
pub position: Coordinate,
}

Expand Down
16 changes: 8 additions & 8 deletions src/plugin2027/utils/coordinate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use pyo3::*;
use std::hash::{DefaultHasher, Hash, Hasher};

use crate::plugin2027::{
utils::vector::Vector, utils::direction::Direction
Expand All @@ -7,9 +8,9 @@ use crate::plugin2027::{
#[pyclass(from_py_object)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Coordinate {
#[pyo3(get, set)]
#[pyo3(get)]
pub x: isize,
#[pyo3(get, set)]
#[pyo3(get)]
pub y: isize,
}

Expand All @@ -26,6 +27,11 @@ impl Coordinate {
fn __repr__(&self) -> String {format!("{:?}", self)}
fn __eq__(&self, other: &Coordinate) -> bool {self == other}
fn __ne__(&self, other: &Coordinate) -> bool {self != other}
fn __hash__(&self) -> u64 {
let mut hasher = DefaultHasher::new();
self.hash(&mut hasher);
hasher.finish()
}
fn deepcopy(&self) -> Coordinate {*self}

pub fn add_vector(&self, vector: &Vector) -> Coordinate {
Expand All @@ -35,12 +41,6 @@ impl Coordinate {
}
}

pub fn add_vector_mut(&mut self, vector: &Vector) {

self.x += vector.delta_x;
self.y += vector.delta_y;
}

pub fn get_difference(&self, other: &Coordinate) -> Vector {
Vector {
delta_x: other.x - self.x,
Expand Down
21 changes: 9 additions & 12 deletions src/plugin2027/utils/vector.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use pyo3::*;
use std::hash::{DefaultHasher, Hash, Hasher};

#[pyclass(from_py_object)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Vector {
#[pyo3(get, set)]
#[pyo3(get)]
pub delta_x: isize,
#[pyo3(get, set)]
#[pyo3(get)]
pub delta_y: isize,
}

Expand All @@ -22,6 +23,12 @@ impl Vector {
fn __repr__(&self) -> String {format!("{:?}", self)}
fn __eq__(&self, other: &Vector) -> bool {self == other}
fn __ne__(&self, other: &Vector) -> bool {self != other}
fn __hash__(&self) -> u64 {
let mut hasher = DefaultHasher::new();
self.hash(&mut hasher);
hasher.finish()
}

fn deepcopy(&self) -> Vector {*self}

pub fn add_vector(&self, other: &Vector) -> Vector {
Expand All @@ -30,11 +37,6 @@ impl Vector {
delta_y: self.delta_y + other.delta_y
}
}

pub fn add_vector_mut(&mut self, other: &Vector) {
self.delta_x += other.delta_x;
self.delta_y += other.delta_y;
}

pub fn scale(&self, scalar: isize) -> Vector {
Vector {
Expand All @@ -43,11 +45,6 @@ impl Vector {
}
}

pub fn scale_mut(&mut self, scalar: isize) {
self.delta_x *= scalar;
self.delta_y *= scalar;
}

pub fn get_length(&self) -> Option<f32> {
let squared_length = self.delta_x * self.delta_x + self.delta_y * self.delta_y;

Expand Down
Loading