Vikassy has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/141295

Change subject: Finding minimum bounding rectangle for language screenshot
......................................................................

Finding minimum bounding rectangle for language screenshot

Change-Id: I19b98c79b837896e348433dd77969d07f9e5a366
---
A modules/ve-mw/test/browser/features/support/rectangle.rb
A modules/ve-mw/test/browser/features/support/rectangle_spec.rb
2 files changed, 44 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/95/141295/1

diff --git a/modules/ve-mw/test/browser/features/support/rectangle.rb 
b/modules/ve-mw/test/browser/features/support/rectangle.rb
new file mode 100644
index 0000000..c7f76aa
--- /dev/null
+++ b/modules/ve-mw/test/browser/features/support/rectangle.rb
@@ -0,0 +1,14 @@
+def rectangle input_rectangle_1, input_rectangle_2=nil
+  return input_rectangle_1 unless input_rectangle_2
+
+  # Finding minimum from the top left
+  top_left_x = [input_rectangle_1[0][0],input_rectangle_2[0][0]].min
+  top_left_y = [input_rectangle_1[0][1],input_rectangle_2[0][1]].min
+
+  # Finding maximum from the bottom right
+  bottom_right_x = [input_rectangle_1[3][0],input_rectangle_2[3][0]].max
+  bottom_right_y = [input_rectangle_1[3][1],input_rectangle_2[3][1]].max
+
+  # The new rectangle is constructed with its minimum and maximum 
co-ordinates. 
+  [[top_left_x, top_left_y], [bottom_right_x, top_left_y], [top_left_x, 
bottom_right_y], [bottom_right_x, bottom_right_y]]
+end
\ No newline at end of file
diff --git a/modules/ve-mw/test/browser/features/support/rectangle_spec.rb 
b/modules/ve-mw/test/browser/features/support/rectangle_spec.rb
new file mode 100644
index 0000000..06df0af
--- /dev/null
+++ b/modules/ve-mw/test/browser/features/support/rectangle_spec.rb
@@ -0,0 +1,30 @@
+require_relative 'rectangle'
+
+# Rectangle is defined as set of co-ordinates represnted in (x,y).
+# Positions are Top left, Top Right, Bottom left and Bottom right
+describe "Rectangle" do
+  it "should return the co-ordinates of provided 1 rectangle" do
+       input_rectangle = [[0,0],[1,0],[0,1],[1,1]]
+       expect(rectangle(input_rectangle)).to eq(input_rectangle)
+  end
+
+  it "if we provide 2 rectangles and if one contains the other then it should 
return co-ordinates of bigger rectangle" do
+    input_rectangle_1 = [[0,0],[1,0],[0,1],[1,1]]
+    input_rectangle_2 = [[0,0],[2,0],[0,2],[2,2]]
+    output_rectangle  = input_rectangle_2
+       expect(rectangle(input_rectangle_1, input_rectangle_2)).to 
eq(output_rectangle)
+  end
+
+  it "if we provide 2 rectangles it should return co-ordinates of third 
rectanlge which contains both" do
+    input_rectangle_1  = [[0,0],[1,0],[0,1],[1,1]]
+    input_rectangle_2  = [[1,0],[2,0],[1,1],[2,1]]
+    output_rectangle_1 = [[0,0],[2,0],[0,1],[2,1]]
+       expect(rectangle(input_rectangle_1, input_rectangle_2)).to 
eq(output_rectangle_1)
+
+       input_rectangle_3  = [[1,1],[2,1],[1,2],[2,2]]
+    input_rectangle_4  = [[3,3],[4,3],[3,4],[4,4]]
+    output_rectangle_2 = [[1,1],[4,1],[1,4],[4,4]]
+       expect(rectangle(input_rectangle_3, input_rectangle_4)).to 
eq(output_rectangle_2)
+       
+  end
+end
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/141295
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I19b98c79b837896e348433dd77969d07f9e5a366
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Vikassy <vikasyaligar...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to