From 60a9254583fbe51d4fcf455ae7d497adf3316835 Mon Sep 17 00:00:00 2001 From: Alex Clink Date: Tue, 25 Jan 2022 00:14:53 -0500 Subject: [PATCH] Prefer bracket notation for vector --- examples/balls.cr | 4 ++-- examples/snow.cr | 4 ++-- spec/vector_spec.cr | 2 +- src/3d/mesh.cr | 6 +++--- src/3d/tri.cr | 10 +++++----- src/entity/circle_collision.cr | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/balls.cr b/examples/balls.cr index 361aebf..2474765 100644 --- a/examples/balls.cr +++ b/examples/balls.cr @@ -31,10 +31,10 @@ module PF end def add_ball - position = Vector2(Float64).new(rand(0.0_f64..@width.to_f64), rand(0.0_f64..@height.to_f64)) + position = Vector[rand(0.0_f64..@width.to_f64), rand(0.0_f64..@height.to_f64)] ball = Ball.new(rand(10.0..30.0)) ball.position = position - ball.velocity = Vector2(Float64).new(rand(-50.0..50.0), rand(-50.0..50.0)) + ball.velocity = Vector[rand(-50.0..50.0), rand(-50.0..50.0)] @balls << ball end diff --git a/examples/snow.cr b/examples/snow.cr index 99dae8b..09cf2f6 100644 --- a/examples/snow.cr +++ b/examples/snow.cr @@ -34,7 +34,7 @@ class Wind while y < @height x = step / 2 while x < @width - @gusts << Gust.new(PF::Vector2(Float64).new(x, y), PF::Vector2(Float64).new(rand(-1.0..1.0), rand(-1.0..1.0))) + @gusts << Gust.new(PF::Vector[x, y], PF::Vector[rand(-1.0..1.0), rand(-1.0..1.0)]) x += step end y += step @@ -49,7 +49,7 @@ class Flake property velocity : PF::Vector2(Float64) def initialize(@position, @shape = rand(0_u8..2_u8), @z_pos = rand(0.0..1.0), velocity : PF::Vector2(Float64)? = nil) - @velocity = velocity || PF::Vector2(Float64).new(rand(-2.0..2.0), rand(0.0..20.0)) + @velocity = velocity || PF::Vector[rand(-2.0..2.0), rand(0.0..20.0)] end def update(dt) diff --git a/spec/vector_spec.cr b/spec/vector_spec.cr index b17ecf3..d5660c1 100644 --- a/spec/vector_spec.cr +++ b/spec/vector_spec.cr @@ -8,7 +8,7 @@ describe Vector do it "multiplies 2 vectors" do v1 = Vector[1, 2] v2 = Vector[2, 2] - (v1 * v2).should eq(Vector2(Int32).new(2, 4)) + (v1 * v2).should eq(Vector[2, 4]) end end diff --git a/src/3d/mesh.cr b/src/3d/mesh.cr index 05e8f02..263d32a 100644 --- a/src/3d/mesh.cr +++ b/src/3d/mesh.cr @@ -1,9 +1,9 @@ module PF class Mesh setter tris = [] of Tri - property origin = Vector3(Float64).new(0.0, 0.0, 0.0) - property rotation = Vector3(Float64).new(0.0, 0.0, 0.0) - property position = Vector3(Float64).new(0.0, 0.0, 0.0) + property origin : Vector3(Float64) = Vector[0.0, 0.0, 0.0] + property rotation : Vector3(Float64) = Vector[0.0, 0.0, 0.0] + property position : Vector3(Float64) = Vector[0.0, 0.0, 0.0] # Load an obj file def self.load_obj(path, use_normals : Bool = false) diff --git a/src/3d/tri.cr b/src/3d/tri.cr index 7365327..c81426c 100644 --- a/src/3d/tri.cr +++ b/src/3d/tri.cr @@ -15,9 +15,9 @@ module PF end def initialize(p1x : Float64, p1y : Float64, p1z : Float64, p2x : Float64, p2y : Float64, p2z : Float64, p3x : Float64, p3y : Float64, p3z : Float64, @color = PF::Pixel.white) - @p1 = Vector3(Float64).new(p1x, p1y, p1z) - @p2 = Vector3(Float64).new(p2x, p2y, p2z) - @p3 = Vector3(Float64).new(p3x, p3y, p3z) + @p1 = Vector[p1x, p1y, p1z] + @p2 = Vector[p2x, p2y, p2z] + @p3 = Vector[p3x, p3y, p3z] end # Return the normal assuming clockwise pointing winding @@ -61,9 +61,9 @@ module PF plane_normal = plane_normal.normalized # Create two temporary storage arrays to classify points either side of plane - inside_points = StaticArray(Vector3(Float64), 3).new(Vector3(Float64).new(0.0, 0.0, 0.0)) + inside_points = StaticArray(Vector3(Float64), 3).new(Vector[0.0, 0.0, 0.0]) inside_count = 0 - outside_points = StaticArray(Vector3(Float64), 3).new(Vector3(Float64).new(0.0, 0.0, 0.0)) + outside_points = StaticArray(Vector3(Float64), 3).new(Vector[0.0, 0.0, 0.0]) outside_count = 0 # Classify each point as inside or outside of the plane diff --git a/src/entity/circle_collision.cr b/src/entity/circle_collision.cr index 69b4a20..8a56185 100644 --- a/src/entity/circle_collision.cr +++ b/src/entity/circle_collision.cr @@ -28,7 +28,7 @@ module PF # Calculate the new velocities normal_vec = (position - other.position) / d - tangental_vec = Vector2(Float64).new(-normal_vec.y, normal_vec.x) + tangental_vec = Vector[-normal_vec.y, normal_vec.x] # Dot product of velocity with the tangent # (the direction in which to bounce towards)